@rjsf/core 5.0.0-beta.11 → 5.0.0-beta.12
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 +241 -534
- 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 +240 -533
- package/dist/core.esm.js.map +1 -1
- package/dist/core.umd.development.js +244 -537
- 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 +32 -33
- package/package.json +15 -14
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var utils = require('@rjsf/utils');
|
|
7
|
-
var _pick = require('lodash/pick');
|
|
8
7
|
var get = require('lodash/get');
|
|
9
8
|
var _isEmpty = require('lodash/isEmpty');
|
|
9
|
+
var _pick = require('lodash/pick');
|
|
10
10
|
var isObject = require('lodash/isObject');
|
|
11
11
|
var set = require('lodash/set');
|
|
12
12
|
var nanoid = require('nanoid');
|
|
@@ -17,9 +17,9 @@ var omit = require('lodash/omit');
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
18
|
|
|
19
19
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
20
|
-
var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
|
|
21
20
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
22
21
|
var _isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(_isEmpty);
|
|
22
|
+
var _pick__default = /*#__PURE__*/_interopDefaultLegacy(_pick);
|
|
23
23
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
24
24
|
var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
|
|
25
25
|
var unset__default = /*#__PURE__*/_interopDefaultLegacy(unset);
|
|
@@ -27,7 +27,6 @@ var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
|
|
|
27
27
|
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
28
28
|
|
|
29
29
|
/** Used to generate a unique ID for an element in a row */
|
|
30
|
-
|
|
31
30
|
function generateRowId() {
|
|
32
31
|
return nanoid.nanoid();
|
|
33
32
|
}
|
|
@@ -36,8 +35,6 @@ function generateRowId() {
|
|
|
36
35
|
* @param formData - The data for the form
|
|
37
36
|
* @returns - The `formData` converted into a `KeyedFormDataType` element
|
|
38
37
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
38
|
function generateKeyedFormData(formData) {
|
|
42
39
|
return !Array.isArray(formData) ? [] : formData.map(item => {
|
|
43
40
|
return {
|
|
@@ -51,20 +48,15 @@ function generateKeyedFormData(formData) {
|
|
|
51
48
|
* @param keyedFormData - The `KeyedFormDataType` to be converted
|
|
52
49
|
* @returns - The inner `formData` item(s) in the `keyedFormData`
|
|
53
50
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
51
|
function keyedToPlainFormData(keyedFormData) {
|
|
57
52
|
if (Array.isArray(keyedFormData)) {
|
|
58
53
|
return keyedFormData.map(keyedItem => keyedItem.item);
|
|
59
54
|
}
|
|
60
|
-
|
|
61
55
|
return [];
|
|
62
56
|
}
|
|
63
57
|
/** The `ArrayField` component is used to render a field in the schema that is of type `array`. It supports both normal
|
|
64
58
|
* and fixed array, allowing user to add and remove elements from the array data.
|
|
65
59
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
class ArrayField extends React.Component {
|
|
69
61
|
/** Constructs an `ArrayField` from the `props`, generating the initial keyed data from the `formData`
|
|
70
62
|
*
|
|
@@ -72,7 +64,6 @@ class ArrayField extends React.Component {
|
|
|
72
64
|
*/
|
|
73
65
|
constructor(props) {
|
|
74
66
|
super(props);
|
|
75
|
-
|
|
76
67
|
this._getNewFormDataRow = () => {
|
|
77
68
|
const {
|
|
78
69
|
schema,
|
|
@@ -82,20 +73,16 @@ class ArrayField extends React.Component {
|
|
|
82
73
|
schemaUtils
|
|
83
74
|
} = registry;
|
|
84
75
|
let itemSchema = schema.items;
|
|
85
|
-
|
|
86
76
|
if (utils.isFixedItems(schema) && utils.allowAdditionalItems(schema)) {
|
|
87
77
|
itemSchema = schema.additionalItems;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
}
|
|
79
|
+
// Cast this as a T to work around schema utils being for T[] caused by the FieldProps<T[], S, F> call on the class
|
|
91
80
|
return schemaUtils.getDefaultFormState(itemSchema);
|
|
92
81
|
};
|
|
93
|
-
|
|
94
82
|
this.onAddClick = event => {
|
|
95
83
|
if (event) {
|
|
96
84
|
event.preventDefault();
|
|
97
85
|
}
|
|
98
|
-
|
|
99
86
|
const {
|
|
100
87
|
onChange
|
|
101
88
|
} = this.props;
|
|
@@ -112,13 +99,11 @@ class ArrayField extends React.Component {
|
|
|
112
99
|
updatedKeyedFormData: true
|
|
113
100
|
}, () => onChange(keyedToPlainFormData(newKeyedFormData)));
|
|
114
101
|
};
|
|
115
|
-
|
|
116
102
|
this.onAddIndexClick = index => {
|
|
117
103
|
return event => {
|
|
118
104
|
if (event) {
|
|
119
105
|
event.preventDefault();
|
|
120
106
|
}
|
|
121
|
-
|
|
122
107
|
const {
|
|
123
108
|
onChange
|
|
124
109
|
} = this.props;
|
|
@@ -137,29 +122,24 @@ class ArrayField extends React.Component {
|
|
|
137
122
|
}, () => onChange(keyedToPlainFormData(newKeyedFormData)));
|
|
138
123
|
};
|
|
139
124
|
};
|
|
140
|
-
|
|
141
125
|
this.onDropIndexClick = index => {
|
|
142
126
|
return event => {
|
|
143
127
|
if (event) {
|
|
144
128
|
event.preventDefault();
|
|
145
129
|
}
|
|
146
|
-
|
|
147
130
|
const {
|
|
148
131
|
onChange,
|
|
149
132
|
errorSchema
|
|
150
133
|
} = this.props;
|
|
151
134
|
const {
|
|
152
135
|
keyedFormData
|
|
153
|
-
} = this.state;
|
|
154
|
-
|
|
136
|
+
} = this.state;
|
|
137
|
+
// refs #195: revalidate to ensure properly reindexing errors
|
|
155
138
|
let newErrorSchema;
|
|
156
|
-
|
|
157
139
|
if (errorSchema) {
|
|
158
140
|
newErrorSchema = {};
|
|
159
|
-
|
|
160
141
|
for (const idx in errorSchema) {
|
|
161
142
|
const i = parseInt(idx);
|
|
162
|
-
|
|
163
143
|
if (i < index) {
|
|
164
144
|
set__default["default"](newErrorSchema, [i], errorSchema[idx]);
|
|
165
145
|
} else if (i > index) {
|
|
@@ -167,7 +147,6 @@ class ArrayField extends React.Component {
|
|
|
167
147
|
}
|
|
168
148
|
}
|
|
169
149
|
}
|
|
170
|
-
|
|
171
150
|
const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
|
|
172
151
|
this.setState({
|
|
173
152
|
keyedFormData: newKeyedFormData,
|
|
@@ -175,26 +154,21 @@ class ArrayField extends React.Component {
|
|
|
175
154
|
}, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
|
|
176
155
|
};
|
|
177
156
|
};
|
|
178
|
-
|
|
179
157
|
this.onReorderClick = (index, newIndex) => {
|
|
180
158
|
return event => {
|
|
181
159
|
if (event) {
|
|
182
160
|
event.preventDefault();
|
|
183
161
|
event.currentTarget.blur();
|
|
184
162
|
}
|
|
185
|
-
|
|
186
163
|
const {
|
|
187
164
|
onChange,
|
|
188
165
|
errorSchema
|
|
189
166
|
} = this.props;
|
|
190
167
|
let newErrorSchema;
|
|
191
|
-
|
|
192
168
|
if (this.props.errorSchema) {
|
|
193
169
|
newErrorSchema = {};
|
|
194
|
-
|
|
195
170
|
for (const idx in errorSchema) {
|
|
196
171
|
const i = parseInt(idx);
|
|
197
|
-
|
|
198
172
|
if (i == index) {
|
|
199
173
|
set__default["default"](newErrorSchema, [newIndex], errorSchema[index]);
|
|
200
174
|
} else if (i == newIndex) {
|
|
@@ -204,30 +178,23 @@ class ArrayField extends React.Component {
|
|
|
204
178
|
}
|
|
205
179
|
}
|
|
206
180
|
}
|
|
207
|
-
|
|
208
181
|
const {
|
|
209
182
|
keyedFormData
|
|
210
183
|
} = this.state;
|
|
211
|
-
|
|
212
184
|
function reOrderArray() {
|
|
213
185
|
// Copy item
|
|
214
|
-
const _newKeyedFormData = keyedFormData.slice();
|
|
215
|
-
|
|
216
|
-
|
|
186
|
+
const _newKeyedFormData = keyedFormData.slice();
|
|
187
|
+
// Moves item from index to newIndex
|
|
217
188
|
_newKeyedFormData.splice(index, 1);
|
|
218
|
-
|
|
219
189
|
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
220
|
-
|
|
221
190
|
return _newKeyedFormData;
|
|
222
191
|
}
|
|
223
|
-
|
|
224
192
|
const newKeyedFormData = reOrderArray();
|
|
225
193
|
this.setState({
|
|
226
194
|
keyedFormData: newKeyedFormData
|
|
227
195
|
}, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
|
|
228
196
|
};
|
|
229
197
|
};
|
|
230
|
-
|
|
231
198
|
this.onChangeForIndex = index => {
|
|
232
199
|
return (value, newErrorSchema, id) => {
|
|
233
200
|
const {
|
|
@@ -242,12 +209,12 @@ class ArrayField extends React.Component {
|
|
|
242
209
|
const jsonValue = typeof value === "undefined" ? null : value;
|
|
243
210
|
return index === i ? jsonValue : item;
|
|
244
211
|
});
|
|
245
|
-
onChange(newFormData, errorSchema && errorSchema && {
|
|
212
|
+
onChange(newFormData, errorSchema && errorSchema && {
|
|
213
|
+
...errorSchema,
|
|
246
214
|
[index]: newErrorSchema
|
|
247
215
|
}, id);
|
|
248
216
|
};
|
|
249
217
|
};
|
|
250
|
-
|
|
251
218
|
this.onSelectChange = value => {
|
|
252
219
|
const {
|
|
253
220
|
onChange,
|
|
@@ -255,13 +222,10 @@ class ArrayField extends React.Component {
|
|
|
255
222
|
} = this.props;
|
|
256
223
|
onChange(value, undefined, idSchema && idSchema.$id);
|
|
257
224
|
};
|
|
258
|
-
|
|
259
225
|
const {
|
|
260
226
|
formData: _formData = []
|
|
261
227
|
} = props;
|
|
262
|
-
|
|
263
228
|
const _keyedFormData = generateKeyedFormData(_formData);
|
|
264
|
-
|
|
265
229
|
this.state = {
|
|
266
230
|
keyedFormData: _keyedFormData,
|
|
267
231
|
updatedKeyedFormData: false
|
|
@@ -273,8 +237,6 @@ class ArrayField extends React.Component {
|
|
|
273
237
|
* @param nextProps - The next set of props data
|
|
274
238
|
* @param prevState - The previous set of state data
|
|
275
239
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
240
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
279
241
|
// Don't call getDerivedStateFromProps if keyed formdata was just updated.
|
|
280
242
|
if (prevState.updatedKeyedFormData) {
|
|
@@ -282,7 +244,6 @@ class ArrayField extends React.Component {
|
|
|
282
244
|
updatedKeyedFormData: false
|
|
283
245
|
};
|
|
284
246
|
}
|
|
285
|
-
|
|
286
247
|
const nextFormData = Array.isArray(nextProps.formData) ? nextProps.formData : [];
|
|
287
248
|
const previousKeyedFormData = prevState.keyedFormData || [];
|
|
288
249
|
const newKeyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => {
|
|
@@ -298,8 +259,6 @@ class ArrayField extends React.Component {
|
|
|
298
259
|
/** Returns the appropriate title for an item by getting first the title from the schema.items, then falling back to
|
|
299
260
|
* the description from the schema.items, and finally the string "Item"
|
|
300
261
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
262
|
get itemTitle() {
|
|
304
263
|
const {
|
|
305
264
|
schema
|
|
@@ -312,16 +271,13 @@ class ArrayField extends React.Component {
|
|
|
312
271
|
* @param itemSchema - The schema for the item
|
|
313
272
|
* @return - True if the item schema type does not contain the "null" type
|
|
314
273
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
274
|
isItemRequired(itemSchema) {
|
|
318
275
|
if (Array.isArray(itemSchema.type)) {
|
|
319
276
|
// While we don't yet support composite/nullable jsonschema types, it's
|
|
320
277
|
// future-proof to check for requirement against these.
|
|
321
278
|
return !itemSchema.type.includes("null");
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
279
|
+
}
|
|
280
|
+
// All non-null array item types are inherently required by design
|
|
325
281
|
return itemSchema.type !== "null";
|
|
326
282
|
}
|
|
327
283
|
/** Determines whether more items can be added to the array. If the uiSchema indicates the array doesn't allow adding
|
|
@@ -331,8 +287,6 @@ class ArrayField extends React.Component {
|
|
|
331
287
|
* @param formItems - The list of items in the form
|
|
332
288
|
* @returns - True if the item is addable otherwise false
|
|
333
289
|
*/
|
|
334
|
-
|
|
335
|
-
|
|
336
290
|
canAddItem(formItems) {
|
|
337
291
|
const {
|
|
338
292
|
schema,
|
|
@@ -341,7 +295,6 @@ class ArrayField extends React.Component {
|
|
|
341
295
|
let {
|
|
342
296
|
addable
|
|
343
297
|
} = utils.getUiOptions(uiSchema);
|
|
344
|
-
|
|
345
298
|
if (addable !== false) {
|
|
346
299
|
// if ui:options.addable was not explicitly set to false, we can add
|
|
347
300
|
// another item if we have not exceeded maxItems yet
|
|
@@ -351,14 +304,12 @@ class ArrayField extends React.Component {
|
|
|
351
304
|
addable = true;
|
|
352
305
|
}
|
|
353
306
|
}
|
|
354
|
-
|
|
355
307
|
return addable;
|
|
356
308
|
}
|
|
357
309
|
/** Returns the default form information for an item based on the schema for that item. Deals with the possibility
|
|
358
310
|
* that the schema is fixed and allows additional items.
|
|
359
311
|
*/
|
|
360
312
|
|
|
361
|
-
|
|
362
313
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
363
314
|
*/
|
|
364
315
|
render() {
|
|
@@ -371,7 +322,6 @@ class ArrayField extends React.Component {
|
|
|
371
322
|
const {
|
|
372
323
|
schemaUtils
|
|
373
324
|
} = registry;
|
|
374
|
-
|
|
375
325
|
if (!(utils.ITEMS_KEY in schema)) {
|
|
376
326
|
const uiOptions = utils.getUiOptions(uiSchema);
|
|
377
327
|
const UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
|
|
@@ -382,30 +332,23 @@ class ArrayField extends React.Component {
|
|
|
382
332
|
registry: registry
|
|
383
333
|
});
|
|
384
334
|
}
|
|
385
|
-
|
|
386
335
|
if (schemaUtils.isMultiSelect(schema)) {
|
|
387
336
|
// If array has enum or uniqueItems set to true, call renderMultiSelect() to render the default multiselect widget or a custom widget, if specified.
|
|
388
337
|
return this.renderMultiSelect();
|
|
389
338
|
}
|
|
390
|
-
|
|
391
339
|
if (utils.isCustomWidget(uiSchema)) {
|
|
392
340
|
return this.renderCustomWidget();
|
|
393
341
|
}
|
|
394
|
-
|
|
395
342
|
if (utils.isFixedItems(schema)) {
|
|
396
343
|
return this.renderFixedArray();
|
|
397
344
|
}
|
|
398
|
-
|
|
399
345
|
if (schemaUtils.isFilesArray(schema, uiSchema)) {
|
|
400
346
|
return this.renderFiles();
|
|
401
347
|
}
|
|
402
|
-
|
|
403
348
|
return this.renderNormalArray();
|
|
404
349
|
}
|
|
405
350
|
/** Renders a normal array without any limitations of length
|
|
406
351
|
*/
|
|
407
|
-
|
|
408
|
-
|
|
409
352
|
renderNormalArray() {
|
|
410
353
|
const {
|
|
411
354
|
schema,
|
|
@@ -433,9 +376,7 @@ class ArrayField extends React.Component {
|
|
|
433
376
|
formContext
|
|
434
377
|
} = registry;
|
|
435
378
|
const uiOptions = utils.getUiOptions(uiSchema);
|
|
436
|
-
|
|
437
379
|
const _schemaItems = isObject__default["default"](schema.items) ? schema.items : {};
|
|
438
|
-
|
|
439
380
|
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
440
381
|
const formData = keyedToPlainFormData(this.state.keyedFormData);
|
|
441
382
|
const arrayProps = {
|
|
@@ -444,8 +385,8 @@ class ArrayField extends React.Component {
|
|
|
444
385
|
const {
|
|
445
386
|
key,
|
|
446
387
|
item
|
|
447
|
-
} = keyedItem;
|
|
448
|
-
|
|
388
|
+
} = keyedItem;
|
|
389
|
+
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
449
390
|
const itemCast = item;
|
|
450
391
|
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
451
392
|
const itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
|
|
@@ -454,10 +395,10 @@ class ArrayField extends React.Component {
|
|
|
454
395
|
return this.renderArrayFieldItem({
|
|
455
396
|
key,
|
|
456
397
|
index,
|
|
457
|
-
name: name && name
|
|
398
|
+
name: name && `${name}-${index}`,
|
|
458
399
|
canMoveUp: index > 0,
|
|
459
400
|
canMoveDown: index < formData.length - 1,
|
|
460
|
-
itemSchema
|
|
401
|
+
itemSchema,
|
|
461
402
|
itemIdSchema,
|
|
462
403
|
itemErrorSchema,
|
|
463
404
|
itemData: itemCast,
|
|
@@ -468,7 +409,7 @@ class ArrayField extends React.Component {
|
|
|
468
409
|
rawErrors
|
|
469
410
|
});
|
|
470
411
|
}),
|
|
471
|
-
className:
|
|
412
|
+
className: `field field-array field-array-of-${itemsSchema.type}`,
|
|
472
413
|
disabled,
|
|
473
414
|
idSchema,
|
|
474
415
|
uiSchema,
|
|
@@ -483,13 +424,12 @@ class ArrayField extends React.Component {
|
|
|
483
424
|
registry
|
|
484
425
|
};
|
|
485
426
|
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
486
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
427
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
428
|
+
...arrayProps
|
|
487
429
|
});
|
|
488
430
|
}
|
|
489
431
|
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
490
432
|
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
433
|
renderCustomWidget() {
|
|
494
434
|
const {
|
|
495
435
|
schema,
|
|
@@ -542,8 +482,6 @@ class ArrayField extends React.Component {
|
|
|
542
482
|
}
|
|
543
483
|
/** Renders an array as a set of checkboxes
|
|
544
484
|
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
485
|
renderMultiSelect() {
|
|
548
486
|
const {
|
|
549
487
|
schema,
|
|
@@ -580,7 +518,8 @@ class ArrayField extends React.Component {
|
|
|
580
518
|
onChange: this.onSelectChange,
|
|
581
519
|
onBlur: onBlur,
|
|
582
520
|
onFocus: onFocus,
|
|
583
|
-
options: {
|
|
521
|
+
options: {
|
|
522
|
+
...options,
|
|
584
523
|
enumOptions
|
|
585
524
|
},
|
|
586
525
|
schema: schema,
|
|
@@ -599,8 +538,6 @@ class ArrayField extends React.Component {
|
|
|
599
538
|
}
|
|
600
539
|
/** Renders an array of files using the `FileWidget`
|
|
601
540
|
*/
|
|
602
|
-
|
|
603
|
-
|
|
604
541
|
renderFiles() {
|
|
605
542
|
const {
|
|
606
543
|
schema,
|
|
@@ -650,8 +587,6 @@ class ArrayField extends React.Component {
|
|
|
650
587
|
}
|
|
651
588
|
/** Renders an array that has a maximum limit of items
|
|
652
589
|
*/
|
|
653
|
-
|
|
654
|
-
|
|
655
590
|
renderFixedArray() {
|
|
656
591
|
const {
|
|
657
592
|
schema,
|
|
@@ -683,20 +618,15 @@ class ArrayField extends React.Component {
|
|
|
683
618
|
schemaUtils,
|
|
684
619
|
formContext
|
|
685
620
|
} = registry;
|
|
686
|
-
|
|
687
621
|
const _schemaItems = isObject__default["default"](schema.items) ? schema.items : [];
|
|
688
|
-
|
|
689
622
|
const itemSchemas = _schemaItems.map((item, index) => schemaUtils.retrieveSchema(item, formData[index]));
|
|
690
|
-
|
|
691
623
|
const additionalSchema = isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
|
|
692
|
-
|
|
693
624
|
if (!items || items.length < itemSchemas.length) {
|
|
694
625
|
// to make sure at least all fixed items are generated
|
|
695
626
|
items = items || [];
|
|
696
627
|
items = items.concat(new Array(itemSchemas.length - items.length));
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
|
|
628
|
+
}
|
|
629
|
+
// These are the props passed into the render function
|
|
700
630
|
const arrayProps = {
|
|
701
631
|
canAdd: this.canAddItem(items) && !!additionalSchema,
|
|
702
632
|
className: "field field-array field-array-fixed-items",
|
|
@@ -707,8 +637,8 @@ class ArrayField extends React.Component {
|
|
|
707
637
|
const {
|
|
708
638
|
key,
|
|
709
639
|
item
|
|
710
|
-
} = keyedItem;
|
|
711
|
-
|
|
640
|
+
} = keyedItem;
|
|
641
|
+
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
712
642
|
const itemCast = item;
|
|
713
643
|
const additional = index >= itemSchemas.length;
|
|
714
644
|
const itemSchema = additional && isObject__default["default"](schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
|
|
@@ -719,7 +649,7 @@ class ArrayField extends React.Component {
|
|
|
719
649
|
return this.renderArrayFieldItem({
|
|
720
650
|
key,
|
|
721
651
|
index,
|
|
722
|
-
name: name && name
|
|
652
|
+
name: name && `${name}-${index}`,
|
|
723
653
|
canRemove: additional,
|
|
724
654
|
canMoveUp: index >= itemSchemas.length + 1,
|
|
725
655
|
canMoveDown: additional && index < items.length - 1,
|
|
@@ -745,7 +675,8 @@ class ArrayField extends React.Component {
|
|
|
745
675
|
rawErrors
|
|
746
676
|
};
|
|
747
677
|
const Template = utils.getTemplate("ArrayFieldTemplate", registry, uiOptions);
|
|
748
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
678
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
679
|
+
...arrayProps
|
|
749
680
|
});
|
|
750
681
|
}
|
|
751
682
|
/** Renders the individual array item using a `SchemaField` along with the additional properties required to be send
|
|
@@ -753,8 +684,6 @@ class ArrayField extends React.Component {
|
|
|
753
684
|
*
|
|
754
685
|
* @param props - The props for the individual array item to be rendered
|
|
755
686
|
*/
|
|
756
|
-
|
|
757
|
-
|
|
758
687
|
renderArrayFieldItem(props) {
|
|
759
688
|
const {
|
|
760
689
|
key,
|
|
@@ -840,7 +769,6 @@ class ArrayField extends React.Component {
|
|
|
840
769
|
uiSchema: itemUiSchema
|
|
841
770
|
};
|
|
842
771
|
}
|
|
843
|
-
|
|
844
772
|
}
|
|
845
773
|
|
|
846
774
|
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
@@ -848,7 +776,6 @@ class ArrayField extends React.Component {
|
|
|
848
776
|
*
|
|
849
777
|
* @param props - The `FieldProps` for this template
|
|
850
778
|
*/
|
|
851
|
-
|
|
852
779
|
function BooleanField(props) {
|
|
853
780
|
const {
|
|
854
781
|
schema,
|
|
@@ -879,27 +806,22 @@ function BooleanField(props) {
|
|
|
879
806
|
} = utils.getUiOptions(uiSchema);
|
|
880
807
|
const Widget = utils.getWidget(schema, widget, widgets);
|
|
881
808
|
let enumOptions;
|
|
882
|
-
|
|
883
809
|
if (Array.isArray(schema.oneOf)) {
|
|
884
810
|
enumOptions = utils.optionsList({
|
|
885
811
|
oneOf: schema.oneOf.map(option => {
|
|
886
812
|
if (isObject__default["default"](option)) {
|
|
887
|
-
return {
|
|
813
|
+
return {
|
|
814
|
+
...option,
|
|
888
815
|
title: option.title || (option.const === true ? "Yes" : "No")
|
|
889
816
|
};
|
|
890
817
|
}
|
|
891
|
-
|
|
892
818
|
return undefined;
|
|
893
819
|
}).filter(o => o) // cast away the error that typescript can't grok is fixed
|
|
894
|
-
|
|
895
820
|
});
|
|
896
821
|
} else {
|
|
897
|
-
var _schema$enum;
|
|
898
|
-
|
|
899
822
|
// We deprecated enumNames in v5. It's intentionally omitted from RSJFSchema type, so we need to cast here.
|
|
900
823
|
const schemaWithEnumNames = schema;
|
|
901
|
-
const enums =
|
|
902
|
-
|
|
824
|
+
const enums = schema.enum ?? [true, false];
|
|
903
825
|
if (!schemaWithEnumNames.enumNames && enums.length === 2 && enums.every(v => typeof v === "boolean")) {
|
|
904
826
|
enumOptions = [{
|
|
905
827
|
value: enums[0],
|
|
@@ -916,9 +838,9 @@ function BooleanField(props) {
|
|
|
916
838
|
});
|
|
917
839
|
}
|
|
918
840
|
}
|
|
919
|
-
|
|
920
841
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
921
|
-
options: {
|
|
842
|
+
options: {
|
|
843
|
+
...options,
|
|
922
844
|
enumOptions
|
|
923
845
|
},
|
|
924
846
|
schema: schema,
|
|
@@ -944,7 +866,6 @@ function BooleanField(props) {
|
|
|
944
866
|
*
|
|
945
867
|
* @param props - The `FieldProps` for this template
|
|
946
868
|
*/
|
|
947
|
-
|
|
948
869
|
class AnyOfField extends React.Component {
|
|
949
870
|
/** Constructs an `AnyOfField` with the given `props` to initialize the initially selected option in state
|
|
950
871
|
*
|
|
@@ -952,7 +873,6 @@ class AnyOfField extends React.Component {
|
|
|
952
873
|
*/
|
|
953
874
|
constructor(props) {
|
|
954
875
|
super(props);
|
|
955
|
-
|
|
956
876
|
this.onOptionChange = option => {
|
|
957
877
|
const selectedOption = parseInt(option, 10);
|
|
958
878
|
const {
|
|
@@ -964,16 +884,15 @@ class AnyOfField extends React.Component {
|
|
|
964
884
|
const {
|
|
965
885
|
schemaUtils
|
|
966
886
|
} = registry;
|
|
967
|
-
const newOption = schemaUtils.retrieveSchema(options[selectedOption], formData);
|
|
887
|
+
const newOption = schemaUtils.retrieveSchema(options[selectedOption], formData);
|
|
888
|
+
// If the new option is of type object and the current data is an object,
|
|
968
889
|
// discard properties added using the old option.
|
|
969
|
-
|
|
970
890
|
let newFormData = undefined;
|
|
971
|
-
|
|
972
891
|
if (utils.guessType(formData) === "object" && (newOption.type === "object" || newOption.properties)) {
|
|
973
892
|
newFormData = Object.assign({}, formData);
|
|
974
893
|
const optionsToDiscard = options.slice();
|
|
975
|
-
optionsToDiscard.splice(selectedOption, 1);
|
|
976
|
-
|
|
894
|
+
optionsToDiscard.splice(selectedOption, 1);
|
|
895
|
+
// Discard any data added using other options
|
|
977
896
|
for (const option of optionsToDiscard) {
|
|
978
897
|
if (option.properties) {
|
|
979
898
|
for (const key in option.properties) {
|
|
@@ -983,15 +902,13 @@ class AnyOfField extends React.Component {
|
|
|
983
902
|
}
|
|
984
903
|
}
|
|
985
904
|
}
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
|
|
905
|
+
}
|
|
906
|
+
// Call getDefaultFormState to make sure defaults are populated on change.
|
|
989
907
|
onChange(schemaUtils.getDefaultFormState(options[selectedOption], newFormData), undefined, this.getFieldId());
|
|
990
908
|
this.setState({
|
|
991
909
|
selectedOption: parseInt(option, 10)
|
|
992
910
|
});
|
|
993
911
|
};
|
|
994
|
-
|
|
995
912
|
const {
|
|
996
913
|
formData: _formData,
|
|
997
914
|
options: _options
|
|
@@ -1006,8 +923,6 @@ class AnyOfField extends React.Component {
|
|
|
1006
923
|
* @param prevProps - The previous `FieldProps` for this template
|
|
1007
924
|
* @param prevState - The previous `AnyOfFieldState` for this template
|
|
1008
925
|
*/
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
926
|
componentDidUpdate(prevProps, prevState) {
|
|
1012
927
|
const {
|
|
1013
928
|
formData,
|
|
@@ -1017,14 +932,11 @@ class AnyOfField extends React.Component {
|
|
|
1017
932
|
const {
|
|
1018
933
|
selectedOption
|
|
1019
934
|
} = this.state;
|
|
1020
|
-
|
|
1021
935
|
if (!utils.deepEquals(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
|
|
1022
936
|
const matchingOption = this.getMatchingOption(selectedOption, formData, options);
|
|
1023
|
-
|
|
1024
937
|
if (!prevState || matchingOption === selectedOption) {
|
|
1025
938
|
return;
|
|
1026
939
|
}
|
|
1027
|
-
|
|
1028
940
|
this.setState({
|
|
1029
941
|
selectedOption: matchingOption
|
|
1030
942
|
});
|
|
@@ -1036,20 +948,16 @@ class AnyOfField extends React.Component {
|
|
|
1036
948
|
* @param options - The list of options to choose from
|
|
1037
949
|
* @return - The index of the `option` that best matches the `formData`
|
|
1038
950
|
*/
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
951
|
getMatchingOption(selectedOption, formData, options) {
|
|
1042
952
|
const {
|
|
1043
953
|
schemaUtils
|
|
1044
954
|
} = this.props.registry;
|
|
1045
955
|
const option = schemaUtils.getMatchingOption(formData, options);
|
|
1046
|
-
|
|
1047
956
|
if (option !== 0) {
|
|
1048
957
|
return option;
|
|
1049
|
-
}
|
|
958
|
+
}
|
|
959
|
+
// If the form data matches none of the options, use the currently selected
|
|
1050
960
|
// option, assuming it's available; otherwise use the first option
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
961
|
return selectedOption || 0;
|
|
1054
962
|
}
|
|
1055
963
|
/** Callback handler to remember what the currently selected option is. In addition to that the `formData` is updated
|
|
@@ -1059,18 +967,15 @@ class AnyOfField extends React.Component {
|
|
|
1059
967
|
* @param option -
|
|
1060
968
|
*/
|
|
1061
969
|
|
|
1062
|
-
|
|
1063
970
|
getFieldId() {
|
|
1064
971
|
const {
|
|
1065
972
|
idSchema,
|
|
1066
973
|
schema
|
|
1067
974
|
} = this.props;
|
|
1068
|
-
return
|
|
975
|
+
return `${idSchema.$id}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`;
|
|
1069
976
|
}
|
|
1070
977
|
/** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
|
|
1071
978
|
*/
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
979
|
render() {
|
|
1075
980
|
const {
|
|
1076
981
|
name,
|
|
@@ -1110,7 +1015,6 @@ class AnyOfField extends React.Component {
|
|
|
1110
1015
|
}, widget, widgets);
|
|
1111
1016
|
const option = options[selectedOption] || null;
|
|
1112
1017
|
let optionSchema;
|
|
1113
|
-
|
|
1114
1018
|
if (option) {
|
|
1115
1019
|
// If the subschema doesn't declare a type, infer the type from the
|
|
1116
1020
|
// parent schema
|
|
@@ -1118,9 +1022,8 @@ class AnyOfField extends React.Component {
|
|
|
1118
1022
|
type: baseType
|
|
1119
1023
|
});
|
|
1120
1024
|
}
|
|
1121
|
-
|
|
1122
1025
|
const enumOptions = options.map((option, index) => ({
|
|
1123
|
-
label: option.title ||
|
|
1026
|
+
label: option.title || `Option ${index + 1}`,
|
|
1124
1027
|
value: index
|
|
1125
1028
|
}));
|
|
1126
1029
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -1163,18 +1066,17 @@ class AnyOfField extends React.Component {
|
|
|
1163
1066
|
hideError: hideError
|
|
1164
1067
|
}));
|
|
1165
1068
|
}
|
|
1166
|
-
|
|
1167
1069
|
}
|
|
1168
1070
|
|
|
1071
|
+
// Matches a string that ends in a . character, optionally followed by a sequence of
|
|
1169
1072
|
// digits followed by any number of 0 characters up until the end of the line.
|
|
1170
1073
|
// Ensuring that there is at least one prefixed character is important so that
|
|
1171
1074
|
// you don't incorrectly match against "0".
|
|
1172
|
-
|
|
1173
|
-
|
|
1075
|
+
const trailingCharMatcherWithPrefix = /\.([0-9]*0)*$/;
|
|
1076
|
+
// This is used for trimming the trailing 0 and . characters without affecting
|
|
1174
1077
|
// the rest of the string. Its possible to use one RegEx with groups for this
|
|
1175
1078
|
// functionality, but it is fairly complex compared to simply defining two
|
|
1176
1079
|
// different matchers.
|
|
1177
|
-
|
|
1178
1080
|
const trailingCharMatcher = /[0.]0*$/;
|
|
1179
1081
|
/**
|
|
1180
1082
|
* The NumberField class has some special handling for dealing with trailing
|
|
@@ -1193,7 +1095,6 @@ const trailingCharMatcher = /[0.]0*$/;
|
|
|
1193
1095
|
* value cached in the state. If it matches the cached value, the cached
|
|
1194
1096
|
* value is passed to the input instead of the formData value
|
|
1195
1097
|
*/
|
|
1196
|
-
|
|
1197
1098
|
function NumberField(props) {
|
|
1198
1099
|
const {
|
|
1199
1100
|
registry,
|
|
@@ -1210,36 +1111,33 @@ function NumberField(props) {
|
|
|
1210
1111
|
*
|
|
1211
1112
|
* @param value - The current value for the change occurring
|
|
1212
1113
|
*/
|
|
1213
|
-
|
|
1214
1114
|
const handleChange = React.useCallback(value => {
|
|
1215
1115
|
// Cache the original value in component state
|
|
1216
|
-
setLastValue(value);
|
|
1116
|
+
setLastValue(value);
|
|
1117
|
+
// Normalize decimals that don't start with a zero character in advance so
|
|
1217
1118
|
// that the rest of the normalization logic is simpler
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1119
|
+
if (`${value}`.charAt(0) === ".") {
|
|
1120
|
+
value = `0${value}`;
|
|
1121
|
+
}
|
|
1122
|
+
// Check that the value is a string (this can happen if the widget used is a
|
|
1222
1123
|
// <select>, due to an enum declaration etc) then, if the value ends in a
|
|
1223
1124
|
// trailing decimal point or multiple zeroes, strip the trailing values
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
1125
|
const processed = typeof value === "string" && value.match(trailingCharMatcherWithPrefix) ? utils.asNumber(value.replace(trailingCharMatcher, "")) : utils.asNumber(value);
|
|
1227
1126
|
onChange(processed);
|
|
1228
1127
|
}, [onChange]);
|
|
1229
|
-
|
|
1230
1128
|
if (typeof lastValue === "string" && typeof value === "number") {
|
|
1231
1129
|
// Construct a regular expression that checks for a string that consists
|
|
1232
1130
|
// of the formData value suffixed with zero or one '.' characters and zero
|
|
1233
1131
|
// or more '0' characters
|
|
1234
|
-
const re = new RegExp(
|
|
1132
|
+
const re = new RegExp(`${value}`.replace(".", "\\.") + "\\.?0*$");
|
|
1133
|
+
// If the cached "lastValue" is a match, use that instead of the formData
|
|
1235
1134
|
// value to prevent the input value from changing in the UI
|
|
1236
|
-
|
|
1237
1135
|
if (lastValue.match(re)) {
|
|
1238
1136
|
value = lastValue;
|
|
1239
1137
|
}
|
|
1240
1138
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1139
|
+
return /*#__PURE__*/React__default["default"].createElement(StringField, {
|
|
1140
|
+
...props,
|
|
1243
1141
|
formData: value,
|
|
1244
1142
|
onChange: handleChange
|
|
1245
1143
|
});
|
|
@@ -1250,30 +1148,25 @@ function NumberField(props) {
|
|
|
1250
1148
|
*
|
|
1251
1149
|
* @param props - The `FieldProps` for this template
|
|
1252
1150
|
*/
|
|
1253
|
-
|
|
1254
1151
|
class ObjectField extends React.Component {
|
|
1255
1152
|
constructor() {
|
|
1256
1153
|
var _this;
|
|
1257
|
-
|
|
1258
1154
|
super(...arguments);
|
|
1259
1155
|
_this = this;
|
|
1260
1156
|
this.state = {
|
|
1261
1157
|
wasPropertyKeyModified: false,
|
|
1262
1158
|
additionalProperties: {}
|
|
1263
1159
|
};
|
|
1264
|
-
|
|
1265
1160
|
this.onPropertyChange = function (name, addedByAdditionalProperties) {
|
|
1266
1161
|
if (addedByAdditionalProperties === void 0) {
|
|
1267
1162
|
addedByAdditionalProperties = false;
|
|
1268
1163
|
}
|
|
1269
|
-
|
|
1270
1164
|
return (value, newErrorSchema, id) => {
|
|
1271
1165
|
const {
|
|
1272
1166
|
formData,
|
|
1273
1167
|
onChange,
|
|
1274
1168
|
errorSchema
|
|
1275
1169
|
} = _this.props;
|
|
1276
|
-
|
|
1277
1170
|
if (value === undefined && addedByAdditionalProperties) {
|
|
1278
1171
|
// Don't set value = undefined for fields added by
|
|
1279
1172
|
// additionalProperties. Doing so removes them from the
|
|
@@ -1284,16 +1177,16 @@ class ObjectField extends React.Component {
|
|
|
1284
1177
|
// set empty values to the empty string.
|
|
1285
1178
|
value = "";
|
|
1286
1179
|
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1180
|
+
const newFormData = {
|
|
1181
|
+
...formData,
|
|
1289
1182
|
[name]: value
|
|
1290
1183
|
};
|
|
1291
|
-
onChange(newFormData, errorSchema && errorSchema && {
|
|
1184
|
+
onChange(newFormData, errorSchema && errorSchema && {
|
|
1185
|
+
...errorSchema,
|
|
1292
1186
|
[name]: newErrorSchema
|
|
1293
1187
|
}, id);
|
|
1294
1188
|
};
|
|
1295
1189
|
};
|
|
1296
|
-
|
|
1297
1190
|
this.onDropPropertyClick = key => {
|
|
1298
1191
|
return event => {
|
|
1299
1192
|
event.preventDefault();
|
|
@@ -1301,13 +1194,13 @@ class ObjectField extends React.Component {
|
|
|
1301
1194
|
onChange,
|
|
1302
1195
|
formData
|
|
1303
1196
|
} = this.props;
|
|
1304
|
-
const copiedFormData = {
|
|
1197
|
+
const copiedFormData = {
|
|
1198
|
+
...formData
|
|
1305
1199
|
};
|
|
1306
1200
|
unset__default["default"](copiedFormData, key);
|
|
1307
1201
|
onChange(copiedFormData);
|
|
1308
1202
|
};
|
|
1309
1203
|
};
|
|
1310
|
-
|
|
1311
1204
|
this.getAvailableKey = (preferredKey, formData) => {
|
|
1312
1205
|
const {
|
|
1313
1206
|
uiSchema
|
|
@@ -1317,27 +1210,24 @@ class ObjectField extends React.Component {
|
|
|
1317
1210
|
} = utils.getUiOptions(uiSchema);
|
|
1318
1211
|
let index = 0;
|
|
1319
1212
|
let newKey = preferredKey;
|
|
1320
|
-
|
|
1321
1213
|
while (newKey in formData) {
|
|
1322
|
-
newKey =
|
|
1214
|
+
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
|
|
1323
1215
|
}
|
|
1324
|
-
|
|
1325
1216
|
return newKey;
|
|
1326
1217
|
};
|
|
1327
|
-
|
|
1328
1218
|
this.onKeyChange = oldValue => {
|
|
1329
1219
|
return (value, newErrorSchema) => {
|
|
1330
1220
|
if (oldValue === value) {
|
|
1331
1221
|
return;
|
|
1332
1222
|
}
|
|
1333
|
-
|
|
1334
1223
|
const {
|
|
1335
1224
|
formData,
|
|
1336
1225
|
onChange,
|
|
1337
1226
|
errorSchema
|
|
1338
1227
|
} = this.props;
|
|
1339
1228
|
value = this.getAvailableKey(value, formData);
|
|
1340
|
-
const newFormData = {
|
|
1229
|
+
const newFormData = {
|
|
1230
|
+
...formData
|
|
1341
1231
|
};
|
|
1342
1232
|
const newKeys = {
|
|
1343
1233
|
[oldValue]: value
|
|
@@ -1352,29 +1242,27 @@ class ObjectField extends React.Component {
|
|
|
1352
1242
|
this.setState({
|
|
1353
1243
|
wasPropertyKeyModified: true
|
|
1354
1244
|
});
|
|
1355
|
-
onChange(renamedObj, errorSchema && errorSchema && {
|
|
1245
|
+
onChange(renamedObj, errorSchema && errorSchema && {
|
|
1246
|
+
...errorSchema,
|
|
1356
1247
|
[value]: newErrorSchema
|
|
1357
1248
|
});
|
|
1358
1249
|
};
|
|
1359
1250
|
};
|
|
1360
|
-
|
|
1361
1251
|
this.handleAddClick = schema => () => {
|
|
1362
1252
|
if (!schema.additionalProperties) {
|
|
1363
1253
|
return;
|
|
1364
1254
|
}
|
|
1365
|
-
|
|
1366
1255
|
const {
|
|
1367
1256
|
formData,
|
|
1368
1257
|
onChange,
|
|
1369
1258
|
registry
|
|
1370
1259
|
} = this.props;
|
|
1371
|
-
const newFormData = {
|
|
1260
|
+
const newFormData = {
|
|
1261
|
+
...formData
|
|
1372
1262
|
};
|
|
1373
1263
|
let type = undefined;
|
|
1374
|
-
|
|
1375
1264
|
if (isObject__default["default"](schema.additionalProperties)) {
|
|
1376
1265
|
type = schema.additionalProperties.type;
|
|
1377
|
-
|
|
1378
1266
|
if (utils.REF_KEY in schema.additionalProperties) {
|
|
1379
1267
|
const {
|
|
1380
1268
|
schemaUtils
|
|
@@ -1385,14 +1273,12 @@ class ObjectField extends React.Component {
|
|
|
1385
1273
|
type = refSchema.type;
|
|
1386
1274
|
}
|
|
1387
1275
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1276
|
+
const newKey = this.getAvailableKey("newKey", newFormData);
|
|
1277
|
+
// Cast this to make the `set` work properly
|
|
1391
1278
|
set__default["default"](newFormData, newKey, this.getDefaultValue(type));
|
|
1392
1279
|
onChange(newFormData);
|
|
1393
1280
|
};
|
|
1394
1281
|
}
|
|
1395
|
-
|
|
1396
1282
|
/** Returns a flag indicating whether the `name` field is required in the object schema
|
|
1397
1283
|
*
|
|
1398
1284
|
* @param name - The name of the field to check for required-ness
|
|
@@ -1413,7 +1299,6 @@ class ObjectField extends React.Component {
|
|
|
1413
1299
|
* @returns - The onPropertyChange callback for the `name` property
|
|
1414
1300
|
*/
|
|
1415
1301
|
|
|
1416
|
-
|
|
1417
1302
|
/** Returns a default value to be used for a new additional schema property of the given `type`
|
|
1418
1303
|
*
|
|
1419
1304
|
* @param type - The type of the new additional schema property
|
|
@@ -1422,22 +1307,16 @@ class ObjectField extends React.Component {
|
|
|
1422
1307
|
switch (type) {
|
|
1423
1308
|
case "string":
|
|
1424
1309
|
return "New Value";
|
|
1425
|
-
|
|
1426
1310
|
case "array":
|
|
1427
1311
|
return [];
|
|
1428
|
-
|
|
1429
1312
|
case "boolean":
|
|
1430
1313
|
return false;
|
|
1431
|
-
|
|
1432
1314
|
case "null":
|
|
1433
1315
|
return null;
|
|
1434
|
-
|
|
1435
1316
|
case "number":
|
|
1436
1317
|
return 0;
|
|
1437
|
-
|
|
1438
1318
|
case "object":
|
|
1439
1319
|
return {};
|
|
1440
|
-
|
|
1441
1320
|
default:
|
|
1442
1321
|
// We don't have a datatype for some reason (perhaps additionalProperties was true)
|
|
1443
1322
|
return "New Value";
|
|
@@ -1449,7 +1328,6 @@ class ObjectField extends React.Component {
|
|
|
1449
1328
|
* @param schema - The schema element to which the new property is being added
|
|
1450
1329
|
*/
|
|
1451
1330
|
|
|
1452
|
-
|
|
1453
1331
|
/** Renders the `ObjectField` from the given props
|
|
1454
1332
|
*/
|
|
1455
1333
|
render() {
|
|
@@ -1486,7 +1364,6 @@ class ObjectField extends React.Component {
|
|
|
1486
1364
|
const title = schema.title === undefined ? name : schema.title;
|
|
1487
1365
|
const description = uiOptions.description || schema.description;
|
|
1488
1366
|
let orderedProperties;
|
|
1489
|
-
|
|
1490
1367
|
try {
|
|
1491
1368
|
const properties = Object.keys(schemaProperties);
|
|
1492
1369
|
orderedProperties = utils.orderProperties(properties, uiOptions.order);
|
|
@@ -1498,7 +1375,6 @@ class ObjectField extends React.Component {
|
|
|
1498
1375
|
}
|
|
1499
1376
|
}, "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)));
|
|
1500
1377
|
}
|
|
1501
|
-
|
|
1502
1378
|
const Template = utils.getTemplate("ObjectFieldTemplate", registry, uiOptions);
|
|
1503
1379
|
const templateProps = {
|
|
1504
1380
|
title: uiOptions.title || title,
|
|
@@ -1549,15 +1425,14 @@ class ObjectField extends React.Component {
|
|
|
1549
1425
|
formContext,
|
|
1550
1426
|
registry
|
|
1551
1427
|
};
|
|
1552
|
-
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
1428
|
+
return /*#__PURE__*/React__default["default"].createElement(Template, {
|
|
1429
|
+
...templateProps,
|
|
1553
1430
|
onAddClick: this.handleAddClick
|
|
1554
1431
|
});
|
|
1555
1432
|
}
|
|
1556
|
-
|
|
1557
1433
|
}
|
|
1558
1434
|
|
|
1559
1435
|
/** The map of component type to FieldName */
|
|
1560
|
-
|
|
1561
1436
|
const COMPONENT_TYPES = {
|
|
1562
1437
|
array: "ArrayField",
|
|
1563
1438
|
boolean: "BooleanField",
|
|
@@ -1577,36 +1452,31 @@ const COMPONENT_TYPES = {
|
|
|
1577
1452
|
* @param registry - The registry from which fields and templates are obtained
|
|
1578
1453
|
* @returns - The `Field` component that is used to render the actual field data
|
|
1579
1454
|
*/
|
|
1580
|
-
|
|
1581
1455
|
function getFieldComponent(schema, uiOptions, idSchema, registry) {
|
|
1582
1456
|
const field = uiOptions.field;
|
|
1583
1457
|
const {
|
|
1584
1458
|
fields
|
|
1585
1459
|
} = registry;
|
|
1586
|
-
|
|
1587
1460
|
if (typeof field === "function") {
|
|
1588
1461
|
return field;
|
|
1589
1462
|
}
|
|
1590
|
-
|
|
1591
1463
|
if (typeof field === "string" && field in fields) {
|
|
1592
1464
|
return fields[field];
|
|
1593
1465
|
}
|
|
1594
|
-
|
|
1595
1466
|
const schemaType = utils.getSchemaType(schema);
|
|
1596
1467
|
const type = Array.isArray(schemaType) ? schemaType[0] : schemaType || "";
|
|
1597
|
-
const componentName = COMPONENT_TYPES[type];
|
|
1468
|
+
const componentName = COMPONENT_TYPES[type];
|
|
1469
|
+
// If the type is not defined and the schema uses 'anyOf' or 'oneOf', don't
|
|
1598
1470
|
// render a field and let the MultiSchemaField component handle the form display
|
|
1599
|
-
|
|
1600
1471
|
if (!componentName && (schema.anyOf || schema.oneOf)) {
|
|
1601
1472
|
return () => null;
|
|
1602
1473
|
}
|
|
1603
|
-
|
|
1604
1474
|
return componentName in fields ? fields[componentName] : () => {
|
|
1605
1475
|
const UnsupportedFieldTemplate = utils.getTemplate("UnsupportedFieldTemplate", registry, uiOptions);
|
|
1606
1476
|
return /*#__PURE__*/React__default["default"].createElement(UnsupportedFieldTemplate, {
|
|
1607
1477
|
schema: schema,
|
|
1608
1478
|
idSchema: idSchema,
|
|
1609
|
-
reason:
|
|
1479
|
+
reason: `Unknown field type ${schema.type}`,
|
|
1610
1480
|
registry: registry
|
|
1611
1481
|
});
|
|
1612
1482
|
};
|
|
@@ -1617,8 +1487,6 @@ function getFieldComponent(schema, uiOptions, idSchema, registry) {
|
|
|
1617
1487
|
*
|
|
1618
1488
|
* @param props - The `FieldProps` for this component
|
|
1619
1489
|
*/
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
1490
|
function SchemaFieldRender(props) {
|
|
1623
1491
|
const {
|
|
1624
1492
|
schema: _schema,
|
|
@@ -1651,7 +1519,6 @@ function SchemaFieldRender(props) {
|
|
|
1651
1519
|
/** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
|
|
1652
1520
|
* `onChange` chain if it is not already being provided from a deeper level in the hierarchy
|
|
1653
1521
|
*/
|
|
1654
|
-
|
|
1655
1522
|
const handleFieldComponentChange = React__default["default"].useCallback((formData, newErrorSchema, id) => {
|
|
1656
1523
|
const theId = id || fieldId;
|
|
1657
1524
|
return onChange(formData, newErrorSchema, theId);
|
|
@@ -1659,28 +1526,25 @@ function SchemaFieldRender(props) {
|
|
|
1659
1526
|
const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
|
|
1660
1527
|
const disabled = Boolean(props.disabled || uiOptions.disabled);
|
|
1661
1528
|
const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
|
|
1662
|
-
const uiSchemaHideError = uiOptions.hideError;
|
|
1663
|
-
|
|
1529
|
+
const uiSchemaHideError = uiOptions.hideError;
|
|
1530
|
+
// Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
|
|
1664
1531
|
const hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
|
|
1665
1532
|
const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
|
|
1666
|
-
|
|
1667
1533
|
if (Object.keys(schema).length === 0) {
|
|
1668
1534
|
return null;
|
|
1669
1535
|
}
|
|
1670
|
-
|
|
1671
1536
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema);
|
|
1672
1537
|
const {
|
|
1673
1538
|
__errors,
|
|
1674
1539
|
...fieldErrorSchema
|
|
1675
|
-
} = errorSchema || {};
|
|
1676
|
-
|
|
1540
|
+
} = errorSchema || {};
|
|
1541
|
+
// See #439: uiSchema: Don't pass consumed class names to child components
|
|
1677
1542
|
const fieldUiSchema = omit__default["default"](uiSchema, ["ui:classNames", "classNames"]);
|
|
1678
|
-
|
|
1679
1543
|
if ("ui:options" in fieldUiSchema) {
|
|
1680
1544
|
fieldUiSchema["ui:options"] = omit__default["default"](fieldUiSchema["ui:options"], ["classNames"]);
|
|
1681
1545
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1546
|
+
const field = /*#__PURE__*/React__default["default"].createElement(FieldComponent, {
|
|
1547
|
+
...props,
|
|
1684
1548
|
onChange: handleFieldComponentChange,
|
|
1685
1549
|
idSchema: idSchema,
|
|
1686
1550
|
schema: schema,
|
|
@@ -1693,37 +1557,30 @@ function SchemaFieldRender(props) {
|
|
|
1693
1557
|
formContext: formContext,
|
|
1694
1558
|
rawErrors: __errors
|
|
1695
1559
|
});
|
|
1696
|
-
const id = idSchema[utils.ID_KEY];
|
|
1697
|
-
|
|
1560
|
+
const id = idSchema[utils.ID_KEY];
|
|
1561
|
+
// If this schema has a title defined, but the user has set a new key/label, retain their input.
|
|
1698
1562
|
let label;
|
|
1699
|
-
|
|
1700
1563
|
if (wasPropertyKeyModified) {
|
|
1701
1564
|
label = name;
|
|
1702
1565
|
} else {
|
|
1703
1566
|
label = utils.ADDITIONAL_PROPERTY_FLAG in schema ? name : uiOptions.title || props.schema.title || schema.title || name;
|
|
1704
1567
|
}
|
|
1705
|
-
|
|
1706
1568
|
const description = uiOptions.description || props.schema.description || schema.description || "";
|
|
1707
1569
|
const help = uiOptions.help;
|
|
1708
1570
|
const hidden = uiOptions.widget === "hidden";
|
|
1709
|
-
const classNames = ["form-group", "field",
|
|
1710
|
-
|
|
1571
|
+
const classNames = ["form-group", "field", `field-${schema.type}`];
|
|
1711
1572
|
if (!hideError && __errors && __errors.length > 0) {
|
|
1712
1573
|
classNames.push("field-error has-error has-danger");
|
|
1713
1574
|
}
|
|
1714
|
-
|
|
1715
1575
|
if (uiSchema !== null && uiSchema !== void 0 && uiSchema.classNames) {
|
|
1716
1576
|
{
|
|
1717
1577
|
console.warn("'uiSchema.classNames' is deprecated and may be removed in a major release; Use 'ui:classNames' instead.");
|
|
1718
1578
|
}
|
|
1719
|
-
|
|
1720
1579
|
classNames.push(uiSchema.classNames);
|
|
1721
1580
|
}
|
|
1722
|
-
|
|
1723
1581
|
if (uiOptions.classNames) {
|
|
1724
1582
|
classNames.push(uiOptions.classNames);
|
|
1725
1583
|
}
|
|
1726
|
-
|
|
1727
1584
|
const helpComponent = /*#__PURE__*/React__default["default"].createElement(FieldHelpTemplate, {
|
|
1728
1585
|
help: help,
|
|
1729
1586
|
idSchema: idSchema,
|
|
@@ -1742,7 +1599,7 @@ function SchemaFieldRender(props) {
|
|
|
1742
1599
|
});
|
|
1743
1600
|
const fieldProps = {
|
|
1744
1601
|
description: /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
1745
|
-
id: id
|
|
1602
|
+
id: `${id}__description`,
|
|
1746
1603
|
description: description,
|
|
1747
1604
|
schema: schema,
|
|
1748
1605
|
uiSchema: uiSchema,
|
|
@@ -1773,7 +1630,8 @@ function SchemaFieldRender(props) {
|
|
|
1773
1630
|
};
|
|
1774
1631
|
const _AnyOfField = registry.fields.AnyOfField;
|
|
1775
1632
|
const _OneOfField = registry.fields.OneOfField;
|
|
1776
|
-
return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, {
|
|
1633
|
+
return /*#__PURE__*/React__default["default"].createElement(FieldTemplate, {
|
|
1634
|
+
...fieldProps
|
|
1777
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, {
|
|
1778
1636
|
name: name,
|
|
1779
1637
|
disabled: disabled,
|
|
@@ -1817,25 +1675,21 @@ function SchemaFieldRender(props) {
|
|
|
1817
1675
|
/** The `SchemaField` component determines whether it is necessary to rerender the component based on any props changes
|
|
1818
1676
|
* and if so, calls the `SchemaFieldRender` component with the props.
|
|
1819
1677
|
*/
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
1678
|
class SchemaField extends React__default["default"].Component {
|
|
1823
1679
|
shouldComponentUpdate(nextProps) {
|
|
1824
1680
|
return !utils.deepEquals(this.props, nextProps);
|
|
1825
1681
|
}
|
|
1826
|
-
|
|
1827
1682
|
render() {
|
|
1828
|
-
return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, {
|
|
1683
|
+
return /*#__PURE__*/React__default["default"].createElement(SchemaFieldRender, {
|
|
1684
|
+
...this.props
|
|
1829
1685
|
});
|
|
1830
1686
|
}
|
|
1831
|
-
|
|
1832
1687
|
}
|
|
1833
1688
|
|
|
1834
1689
|
/** The `StringField` component is used to render a schema field that represents a string type
|
|
1835
1690
|
*
|
|
1836
1691
|
* @param props - The `FieldProps` for this template
|
|
1837
1692
|
*/
|
|
1838
|
-
|
|
1839
1693
|
function StringField(props) {
|
|
1840
1694
|
const {
|
|
1841
1695
|
schema,
|
|
@@ -1864,11 +1718,9 @@ function StringField(props) {
|
|
|
1864
1718
|
} = registry;
|
|
1865
1719
|
const enumOptions = schemaUtils.isSelect(schema) ? utils.optionsList(schema) : undefined;
|
|
1866
1720
|
let defaultWidget = enumOptions ? "select" : "text";
|
|
1867
|
-
|
|
1868
1721
|
if (format && utils.hasWidget(schema, format, widgets)) {
|
|
1869
1722
|
defaultWidget = format;
|
|
1870
1723
|
}
|
|
1871
|
-
|
|
1872
1724
|
const {
|
|
1873
1725
|
widget = defaultWidget,
|
|
1874
1726
|
placeholder = "",
|
|
@@ -1876,7 +1728,8 @@ function StringField(props) {
|
|
|
1876
1728
|
} = utils.getUiOptions(uiSchema);
|
|
1877
1729
|
const Widget = utils.getWidget(schema, widget, widgets);
|
|
1878
1730
|
return /*#__PURE__*/React__default["default"].createElement(Widget, {
|
|
1879
|
-
options: {
|
|
1731
|
+
options: {
|
|
1732
|
+
...options,
|
|
1880
1733
|
enumOptions
|
|
1881
1734
|
},
|
|
1882
1735
|
schema: schema,
|
|
@@ -1903,7 +1756,6 @@ function StringField(props) {
|
|
|
1903
1756
|
*
|
|
1904
1757
|
* @param props - The `FieldProps` for this template
|
|
1905
1758
|
*/
|
|
1906
|
-
|
|
1907
1759
|
function NullField(props) {
|
|
1908
1760
|
const {
|
|
1909
1761
|
formData,
|
|
@@ -1917,25 +1769,26 @@ function NullField(props) {
|
|
|
1917
1769
|
return null;
|
|
1918
1770
|
}
|
|
1919
1771
|
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1772
|
+
function fields() {
|
|
1773
|
+
return {
|
|
1774
|
+
AnyOfField: AnyOfField,
|
|
1775
|
+
ArrayField: ArrayField,
|
|
1776
|
+
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
1777
|
+
BooleanField,
|
|
1778
|
+
NumberField,
|
|
1779
|
+
ObjectField,
|
|
1780
|
+
OneOfField: AnyOfField,
|
|
1781
|
+
SchemaField,
|
|
1782
|
+
StringField,
|
|
1783
|
+
NullField
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1932
1786
|
|
|
1933
1787
|
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
1934
1788
|
* the `idSchema`.
|
|
1935
1789
|
*
|
|
1936
1790
|
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
1937
1791
|
*/
|
|
1938
|
-
|
|
1939
1792
|
function ArrayFieldDescriptionTemplate(props) {
|
|
1940
1793
|
const {
|
|
1941
1794
|
idSchema,
|
|
@@ -1948,13 +1801,11 @@ function ArrayFieldDescriptionTemplate(props) {
|
|
|
1948
1801
|
const {
|
|
1949
1802
|
label: displayLabel = true
|
|
1950
1803
|
} = options;
|
|
1951
|
-
|
|
1952
1804
|
if (!description || !displayLabel) {
|
|
1953
1805
|
return null;
|
|
1954
1806
|
}
|
|
1955
|
-
|
|
1956
1807
|
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
1957
|
-
const id = idSchema.$id
|
|
1808
|
+
const id = `${idSchema.$id}__description`;
|
|
1958
1809
|
return /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
1959
1810
|
id: id,
|
|
1960
1811
|
description: description,
|
|
@@ -1968,7 +1819,6 @@ function ArrayFieldDescriptionTemplate(props) {
|
|
|
1968
1819
|
*
|
|
1969
1820
|
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
1970
1821
|
*/
|
|
1971
|
-
|
|
1972
1822
|
function ArrayFieldItemTemplate(props) {
|
|
1973
1823
|
const {
|
|
1974
1824
|
children,
|
|
@@ -2030,7 +1880,6 @@ function ArrayFieldItemTemplate(props) {
|
|
|
2030
1880
|
*
|
|
2031
1881
|
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
2032
1882
|
*/
|
|
2033
|
-
|
|
2034
1883
|
function ArrayFieldTemplate(props) {
|
|
2035
1884
|
const {
|
|
2036
1885
|
canAdd,
|
|
@@ -2049,8 +1898,8 @@ function ArrayFieldTemplate(props) {
|
|
|
2049
1898
|
const uiOptions = utils.getUiOptions(uiSchema);
|
|
2050
1899
|
const ArrayFieldDescriptionTemplate = utils.getTemplate("ArrayFieldDescriptionTemplate", registry, uiOptions);
|
|
2051
1900
|
const ArrayFieldItemTemplate = utils.getTemplate("ArrayFieldItemTemplate", registry, uiOptions);
|
|
2052
|
-
const ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
|
|
2053
|
-
|
|
1901
|
+
const ArrayFieldTitleTemplate = utils.getTemplate("ArrayFieldTitleTemplate", registry, uiOptions);
|
|
1902
|
+
// Button templates are not overridden in the uiSchema
|
|
2054
1903
|
const {
|
|
2055
1904
|
ButtonTemplates: {
|
|
2056
1905
|
AddButton
|
|
@@ -2096,7 +1945,6 @@ function ArrayFieldTemplate(props) {
|
|
|
2096
1945
|
*
|
|
2097
1946
|
* @param props - The `ArrayFieldTitleProps` for the component
|
|
2098
1947
|
*/
|
|
2099
|
-
|
|
2100
1948
|
function ArrayFieldTitleTemplate(props) {
|
|
2101
1949
|
const {
|
|
2102
1950
|
idSchema,
|
|
@@ -2110,13 +1958,11 @@ function ArrayFieldTitleTemplate(props) {
|
|
|
2110
1958
|
const {
|
|
2111
1959
|
label: displayLabel = true
|
|
2112
1960
|
} = options;
|
|
2113
|
-
|
|
2114
1961
|
if (!title || !displayLabel) {
|
|
2115
1962
|
return null;
|
|
2116
1963
|
}
|
|
2117
|
-
|
|
2118
1964
|
const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
|
|
2119
|
-
const id = idSchema.$id
|
|
1965
|
+
const id = `${idSchema.$id}__title`;
|
|
2120
1966
|
return /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
|
|
2121
1967
|
id: id,
|
|
2122
1968
|
title: title,
|
|
@@ -2133,7 +1979,6 @@ function ArrayFieldTitleTemplate(props) {
|
|
|
2133
1979
|
*
|
|
2134
1980
|
* @param props - The `WidgetProps` for this template
|
|
2135
1981
|
*/
|
|
2136
|
-
|
|
2137
1982
|
function BaseInputTemplate(props) {
|
|
2138
1983
|
const {
|
|
2139
1984
|
id,
|
|
@@ -2152,25 +1997,23 @@ function BaseInputTemplate(props) {
|
|
|
2152
1997
|
rawErrors,
|
|
2153
1998
|
type,
|
|
2154
1999
|
...rest
|
|
2155
|
-
} = props;
|
|
2000
|
+
} = props;
|
|
2001
|
+
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
2156
2002
|
// exclude the "options" and "schema" ones here.
|
|
2157
|
-
|
|
2158
2003
|
if (!id) {
|
|
2159
2004
|
console.log("No id for", props);
|
|
2160
|
-
throw new Error(
|
|
2005
|
+
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
2161
2006
|
}
|
|
2162
|
-
|
|
2163
|
-
|
|
2007
|
+
const inputProps = {
|
|
2008
|
+
...rest,
|
|
2164
2009
|
...utils.getInputProps(schema, type, options)
|
|
2165
2010
|
};
|
|
2166
2011
|
let inputValue;
|
|
2167
|
-
|
|
2168
2012
|
if (inputProps.type === "number" || inputProps.type === "integer") {
|
|
2169
2013
|
inputValue = value || value === 0 ? value : "";
|
|
2170
2014
|
} else {
|
|
2171
2015
|
inputValue = value == null ? "" : value;
|
|
2172
2016
|
}
|
|
2173
|
-
|
|
2174
2017
|
const _onChange = React.useCallback(_ref => {
|
|
2175
2018
|
let {
|
|
2176
2019
|
target: {
|
|
@@ -2179,7 +2022,6 @@ function BaseInputTemplate(props) {
|
|
|
2179
2022
|
} = _ref;
|
|
2180
2023
|
return onChange(value === "" ? options.emptyValue : value);
|
|
2181
2024
|
}, [onChange, options]);
|
|
2182
|
-
|
|
2183
2025
|
const _onBlur = React.useCallback(_ref2 => {
|
|
2184
2026
|
let {
|
|
2185
2027
|
target: {
|
|
@@ -2188,7 +2030,6 @@ function BaseInputTemplate(props) {
|
|
|
2188
2030
|
} = _ref2;
|
|
2189
2031
|
return onBlur(id, value);
|
|
2190
2032
|
}, [onBlur, id]);
|
|
2191
|
-
|
|
2192
2033
|
const _onFocus = React.useCallback(_ref3 => {
|
|
2193
2034
|
let {
|
|
2194
2035
|
target: {
|
|
@@ -2197,7 +2038,6 @@ function BaseInputTemplate(props) {
|
|
|
2197
2038
|
} = _ref3;
|
|
2198
2039
|
return onFocus(id, value);
|
|
2199
2040
|
}, [onFocus, id]);
|
|
2200
|
-
|
|
2201
2041
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2202
2042
|
id: id,
|
|
2203
2043
|
name: id,
|
|
@@ -2207,13 +2047,13 @@ function BaseInputTemplate(props) {
|
|
|
2207
2047
|
autoFocus: autofocus,
|
|
2208
2048
|
value: inputValue,
|
|
2209
2049
|
...inputProps,
|
|
2210
|
-
list: schema.examples ?
|
|
2050
|
+
list: schema.examples ? `examples_${id}` : undefined,
|
|
2211
2051
|
onChange: _onChange,
|
|
2212
2052
|
onBlur: _onBlur,
|
|
2213
2053
|
onFocus: _onFocus
|
|
2214
2054
|
}), Array.isArray(schema.examples) && /*#__PURE__*/React__default["default"].createElement("datalist", {
|
|
2215
|
-
key:
|
|
2216
|
-
id:
|
|
2055
|
+
key: `datalist_${id}`,
|
|
2056
|
+
id: `examples_${id}`
|
|
2217
2057
|
}, [...new Set(schema.examples.concat(schema.default ? [schema.default] : []))].map(example => /*#__PURE__*/React__default["default"].createElement("option", {
|
|
2218
2058
|
key: example,
|
|
2219
2059
|
value: example
|
|
@@ -2222,7 +2062,6 @@ function BaseInputTemplate(props) {
|
|
|
2222
2062
|
|
|
2223
2063
|
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
2224
2064
|
*/
|
|
2225
|
-
|
|
2226
2065
|
function SubmitButton(_ref) {
|
|
2227
2066
|
let {
|
|
2228
2067
|
uiSchema
|
|
@@ -2232,15 +2071,13 @@ function SubmitButton(_ref) {
|
|
|
2232
2071
|
norender,
|
|
2233
2072
|
props: submitButtonProps = {}
|
|
2234
2073
|
} = utils.getSubmitButtonOptions(uiSchema);
|
|
2235
|
-
|
|
2236
2074
|
if (norender) {
|
|
2237
2075
|
return null;
|
|
2238
2076
|
}
|
|
2239
|
-
|
|
2240
2077
|
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2241
2078
|
type: "submit",
|
|
2242
2079
|
...submitButtonProps,
|
|
2243
|
-
className:
|
|
2080
|
+
className: `btn btn-info ${submitButtonProps.className}`
|
|
2244
2081
|
}, submitText));
|
|
2245
2082
|
}
|
|
2246
2083
|
|
|
@@ -2254,10 +2091,10 @@ function IconButton(props) {
|
|
|
2254
2091
|
} = props;
|
|
2255
2092
|
return /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2256
2093
|
type: "button",
|
|
2257
|
-
className:
|
|
2094
|
+
className: `btn btn-${iconType} ${className}`,
|
|
2258
2095
|
...otherProps
|
|
2259
2096
|
}, /*#__PURE__*/React__default["default"].createElement("i", {
|
|
2260
|
-
className:
|
|
2097
|
+
className: `glyphicon glyphicon-${icon}`
|
|
2261
2098
|
}));
|
|
2262
2099
|
}
|
|
2263
2100
|
function MoveDownButton(props) {
|
|
@@ -2288,7 +2125,6 @@ function RemoveButton(props) {
|
|
|
2288
2125
|
|
|
2289
2126
|
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
2290
2127
|
*/
|
|
2291
|
-
|
|
2292
2128
|
function AddButton(_ref) {
|
|
2293
2129
|
let {
|
|
2294
2130
|
className,
|
|
@@ -2298,7 +2134,7 @@ function AddButton(_ref) {
|
|
|
2298
2134
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2299
2135
|
className: "row"
|
|
2300
2136
|
}, /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2301
|
-
className:
|
|
2137
|
+
className: `col-xs-3 col-xs-offset-9 text-right ${className}`
|
|
2302
2138
|
}, /*#__PURE__*/React__default["default"].createElement(IconButton, {
|
|
2303
2139
|
iconType: "info",
|
|
2304
2140
|
icon: "plus",
|
|
@@ -2309,29 +2145,28 @@ function AddButton(_ref) {
|
|
|
2309
2145
|
})));
|
|
2310
2146
|
}
|
|
2311
2147
|
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2148
|
+
function buttonTemplates() {
|
|
2149
|
+
return {
|
|
2150
|
+
SubmitButton,
|
|
2151
|
+
AddButton,
|
|
2152
|
+
MoveDownButton,
|
|
2153
|
+
MoveUpButton,
|
|
2154
|
+
RemoveButton
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2319
2157
|
|
|
2320
2158
|
/** The `DescriptionField` is the template to use to render the description of a field
|
|
2321
2159
|
*
|
|
2322
2160
|
* @param props - The `DescriptionFieldProps` for this component
|
|
2323
2161
|
*/
|
|
2324
|
-
|
|
2325
2162
|
function DescriptionField(props) {
|
|
2326
2163
|
const {
|
|
2327
2164
|
id,
|
|
2328
2165
|
description
|
|
2329
2166
|
} = props;
|
|
2330
|
-
|
|
2331
2167
|
if (!description) {
|
|
2332
2168
|
return null;
|
|
2333
2169
|
}
|
|
2334
|
-
|
|
2335
2170
|
if (typeof description === "string") {
|
|
2336
2171
|
return /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2337
2172
|
id: id,
|
|
@@ -2349,7 +2184,6 @@ function DescriptionField(props) {
|
|
|
2349
2184
|
*
|
|
2350
2185
|
* @param props - The `ErrorListProps` for this component
|
|
2351
2186
|
*/
|
|
2352
|
-
|
|
2353
2187
|
function ErrorList(_ref) {
|
|
2354
2188
|
let {
|
|
2355
2189
|
errors
|
|
@@ -2375,18 +2209,15 @@ const REQUIRED_FIELD_SYMBOL$1 = "*";
|
|
|
2375
2209
|
*
|
|
2376
2210
|
* @param props - The `LabelProps` for this component
|
|
2377
2211
|
*/
|
|
2378
|
-
|
|
2379
2212
|
function Label(props) {
|
|
2380
2213
|
const {
|
|
2381
2214
|
label,
|
|
2382
2215
|
required,
|
|
2383
2216
|
id
|
|
2384
2217
|
} = props;
|
|
2385
|
-
|
|
2386
2218
|
if (!label) {
|
|
2387
2219
|
return null;
|
|
2388
2220
|
}
|
|
2389
|
-
|
|
2390
2221
|
return /*#__PURE__*/React__default["default"].createElement("label", {
|
|
2391
2222
|
className: "control-label",
|
|
2392
2223
|
htmlFor: id
|
|
@@ -2400,7 +2231,6 @@ function Label(props) {
|
|
|
2400
2231
|
*
|
|
2401
2232
|
* @param props - The `FieldTemplateProps` for this component
|
|
2402
2233
|
*/
|
|
2403
|
-
|
|
2404
2234
|
function FieldTemplate(props) {
|
|
2405
2235
|
const {
|
|
2406
2236
|
id,
|
|
@@ -2417,14 +2247,13 @@ function FieldTemplate(props) {
|
|
|
2417
2247
|
} = props;
|
|
2418
2248
|
const uiOptions = utils.getUiOptions(uiSchema);
|
|
2419
2249
|
const WrapIfAdditionalTemplate = utils.getTemplate("WrapIfAdditionalTemplate", registry, uiOptions);
|
|
2420
|
-
|
|
2421
2250
|
if (hidden) {
|
|
2422
2251
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2423
2252
|
className: "hidden"
|
|
2424
2253
|
}, children);
|
|
2425
2254
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2255
|
+
return /*#__PURE__*/React__default["default"].createElement(WrapIfAdditionalTemplate, {
|
|
2256
|
+
...props
|
|
2428
2257
|
}, displayLabel && /*#__PURE__*/React__default["default"].createElement(Label, {
|
|
2429
2258
|
label: label,
|
|
2430
2259
|
required: required,
|
|
@@ -2436,18 +2265,15 @@ function FieldTemplate(props) {
|
|
|
2436
2265
|
*
|
|
2437
2266
|
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
2438
2267
|
*/
|
|
2439
|
-
|
|
2440
2268
|
function FieldErrorTemplate(props) {
|
|
2441
2269
|
const {
|
|
2442
2270
|
errors = [],
|
|
2443
2271
|
idSchema
|
|
2444
2272
|
} = props;
|
|
2445
|
-
|
|
2446
2273
|
if (errors.length === 0) {
|
|
2447
2274
|
return null;
|
|
2448
2275
|
}
|
|
2449
|
-
|
|
2450
|
-
const id = idSchema.$id + "__error";
|
|
2276
|
+
const id = `${idSchema.$id}__error`;
|
|
2451
2277
|
return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
2452
2278
|
id: id,
|
|
2453
2279
|
className: "error-detail bs-callout bs-callout-info"
|
|
@@ -2463,26 +2289,21 @@ function FieldErrorTemplate(props) {
|
|
|
2463
2289
|
*
|
|
2464
2290
|
* @param props - The `FieldHelpProps` to be rendered
|
|
2465
2291
|
*/
|
|
2466
|
-
|
|
2467
2292
|
function FieldHelpTemplate(props) {
|
|
2468
2293
|
const {
|
|
2469
2294
|
idSchema,
|
|
2470
2295
|
help
|
|
2471
2296
|
} = props;
|
|
2472
|
-
|
|
2473
2297
|
if (!help) {
|
|
2474
2298
|
return null;
|
|
2475
2299
|
}
|
|
2476
|
-
|
|
2477
|
-
const id = idSchema.$id + "__help";
|
|
2478
|
-
|
|
2300
|
+
const id = `${idSchema.$id}__help`;
|
|
2479
2301
|
if (typeof help === "string") {
|
|
2480
2302
|
return /*#__PURE__*/React__default["default"].createElement("p", {
|
|
2481
2303
|
id: id,
|
|
2482
2304
|
className: "help-block"
|
|
2483
2305
|
}, help);
|
|
2484
2306
|
}
|
|
2485
|
-
|
|
2486
2307
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2487
2308
|
id: id,
|
|
2488
2309
|
className: "help-block"
|
|
@@ -2495,7 +2316,6 @@ function FieldHelpTemplate(props) {
|
|
|
2495
2316
|
*
|
|
2496
2317
|
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
2497
2318
|
*/
|
|
2498
|
-
|
|
2499
2319
|
function ObjectFieldTemplate(props) {
|
|
2500
2320
|
const {
|
|
2501
2321
|
description,
|
|
@@ -2513,8 +2333,8 @@ function ObjectFieldTemplate(props) {
|
|
|
2513
2333
|
} = props;
|
|
2514
2334
|
const options = utils.getUiOptions(uiSchema);
|
|
2515
2335
|
const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, options);
|
|
2516
|
-
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2517
|
-
|
|
2336
|
+
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2337
|
+
// Button templates are not overridden in the uiSchema
|
|
2518
2338
|
const {
|
|
2519
2339
|
ButtonTemplates: {
|
|
2520
2340
|
AddButton
|
|
@@ -2523,14 +2343,14 @@ function ObjectFieldTemplate(props) {
|
|
|
2523
2343
|
return /*#__PURE__*/React__default["default"].createElement("fieldset", {
|
|
2524
2344
|
id: idSchema.$id
|
|
2525
2345
|
}, (options.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
|
|
2526
|
-
id: idSchema.$id
|
|
2346
|
+
id: `${idSchema.$id}__title`,
|
|
2527
2347
|
title: options.title || title,
|
|
2528
2348
|
required: required,
|
|
2529
2349
|
schema: schema,
|
|
2530
2350
|
uiSchema: uiSchema,
|
|
2531
2351
|
registry: registry
|
|
2532
2352
|
}), (options.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
2533
|
-
id: idSchema.$id
|
|
2353
|
+
id: `${idSchema.$id}__description`,
|
|
2534
2354
|
description: options.description || description,
|
|
2535
2355
|
schema: schema,
|
|
2536
2356
|
uiSchema: uiSchema,
|
|
@@ -2548,7 +2368,6 @@ const REQUIRED_FIELD_SYMBOL = "*";
|
|
|
2548
2368
|
*
|
|
2549
2369
|
* @param props - The `TitleFieldProps` for this component
|
|
2550
2370
|
*/
|
|
2551
|
-
|
|
2552
2371
|
function TitleField(props) {
|
|
2553
2372
|
const {
|
|
2554
2373
|
id,
|
|
@@ -2567,7 +2386,6 @@ function TitleField(props) {
|
|
|
2567
2386
|
*
|
|
2568
2387
|
* @param props - The `FieldProps` for this template
|
|
2569
2388
|
*/
|
|
2570
|
-
|
|
2571
2389
|
function UnsupportedField(props) {
|
|
2572
2390
|
const {
|
|
2573
2391
|
schema,
|
|
@@ -2584,7 +2402,6 @@ function UnsupportedField(props) {
|
|
|
2584
2402
|
*
|
|
2585
2403
|
* @param props - The `WrapIfAdditionalProps` for this component
|
|
2586
2404
|
*/
|
|
2587
|
-
|
|
2588
2405
|
function WrapIfAdditionalTemplate(props) {
|
|
2589
2406
|
const {
|
|
2590
2407
|
id,
|
|
@@ -2599,21 +2416,18 @@ function WrapIfAdditionalTemplate(props) {
|
|
|
2599
2416
|
children,
|
|
2600
2417
|
uiSchema,
|
|
2601
2418
|
registry
|
|
2602
|
-
} = props;
|
|
2603
|
-
|
|
2419
|
+
} = props;
|
|
2420
|
+
// Button templates are not overridden in the uiSchema
|
|
2604
2421
|
const {
|
|
2605
2422
|
RemoveButton
|
|
2606
2423
|
} = registry.templates.ButtonTemplates;
|
|
2607
|
-
const keyLabel = label
|
|
2608
|
-
|
|
2424
|
+
const keyLabel = `${label} Key`; // i18n ?
|
|
2609
2425
|
const additional = (utils.ADDITIONAL_PROPERTY_FLAG in schema);
|
|
2610
|
-
|
|
2611
2426
|
if (!additional) {
|
|
2612
2427
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2613
2428
|
className: classNames
|
|
2614
2429
|
}, children);
|
|
2615
2430
|
}
|
|
2616
|
-
|
|
2617
2431
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2618
2432
|
className: classNames
|
|
2619
2433
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -2625,11 +2439,11 @@ function WrapIfAdditionalTemplate(props) {
|
|
|
2625
2439
|
}, /*#__PURE__*/React__default["default"].createElement(Label, {
|
|
2626
2440
|
label: keyLabel,
|
|
2627
2441
|
required: required,
|
|
2628
|
-
id: id
|
|
2442
|
+
id: `${id}-key`
|
|
2629
2443
|
}), /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2630
2444
|
className: "form-control",
|
|
2631
2445
|
type: "text",
|
|
2632
|
-
id: id
|
|
2446
|
+
id: `${id}-key`,
|
|
2633
2447
|
onBlur: event => onKeyChange(event.target.value),
|
|
2634
2448
|
defaultValue: label
|
|
2635
2449
|
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -2647,46 +2461,43 @@ function WrapIfAdditionalTemplate(props) {
|
|
|
2647
2461
|
}))));
|
|
2648
2462
|
}
|
|
2649
2463
|
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2464
|
+
function templates() {
|
|
2465
|
+
return {
|
|
2466
|
+
ArrayFieldDescriptionTemplate,
|
|
2467
|
+
ArrayFieldItemTemplate,
|
|
2468
|
+
ArrayFieldTemplate,
|
|
2469
|
+
ArrayFieldTitleTemplate,
|
|
2470
|
+
ButtonTemplates: buttonTemplates(),
|
|
2471
|
+
BaseInputTemplate,
|
|
2472
|
+
DescriptionFieldTemplate: DescriptionField,
|
|
2473
|
+
ErrorListTemplate: ErrorList,
|
|
2474
|
+
FieldTemplate,
|
|
2475
|
+
FieldErrorTemplate,
|
|
2476
|
+
FieldHelpTemplate,
|
|
2477
|
+
ObjectFieldTemplate,
|
|
2478
|
+
TitleFieldTemplate: TitleField,
|
|
2479
|
+
UnsupportedFieldTemplate: UnsupportedField,
|
|
2480
|
+
WrapIfAdditionalTemplate
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2667
2483
|
|
|
2668
2484
|
function rangeOptions(start, stop) {
|
|
2669
2485
|
const options = [];
|
|
2670
|
-
|
|
2671
2486
|
for (let i = start; i <= stop; i++) {
|
|
2672
2487
|
options.push({
|
|
2673
2488
|
value: i,
|
|
2674
2489
|
label: utils.pad(i, 2)
|
|
2675
2490
|
});
|
|
2676
2491
|
}
|
|
2677
|
-
|
|
2678
2492
|
return options;
|
|
2679
2493
|
}
|
|
2680
|
-
|
|
2681
2494
|
function readyForChange(state) {
|
|
2682
2495
|
return Object.values(state).every(value => value !== -1);
|
|
2683
2496
|
}
|
|
2684
|
-
|
|
2685
2497
|
function dateElementProps(state, time, yearsRange) {
|
|
2686
2498
|
if (yearsRange === void 0) {
|
|
2687
2499
|
yearsRange = [1900, new Date().getFullYear() + 2];
|
|
2688
2500
|
}
|
|
2689
|
-
|
|
2690
2501
|
const {
|
|
2691
2502
|
year,
|
|
2692
2503
|
month,
|
|
@@ -2708,7 +2519,6 @@ function dateElementProps(state, time, yearsRange) {
|
|
|
2708
2519
|
range: [1, 31],
|
|
2709
2520
|
value: day
|
|
2710
2521
|
}];
|
|
2711
|
-
|
|
2712
2522
|
if (time) {
|
|
2713
2523
|
data.push({
|
|
2714
2524
|
type: "hour",
|
|
@@ -2724,10 +2534,8 @@ function dateElementProps(state, time, yearsRange) {
|
|
|
2724
2534
|
value: second
|
|
2725
2535
|
});
|
|
2726
2536
|
}
|
|
2727
|
-
|
|
2728
2537
|
return data;
|
|
2729
2538
|
}
|
|
2730
|
-
|
|
2731
2539
|
function DateElement(_ref) {
|
|
2732
2540
|
let {
|
|
2733
2541
|
type,
|
|
@@ -2770,8 +2578,6 @@ function DateElement(_ref) {
|
|
|
2770
2578
|
/** The `AltDateWidget` is an alternative widget for rendering date properties.
|
|
2771
2579
|
* @param props - The `WidgetProps` for this component
|
|
2772
2580
|
*/
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
2581
|
function AltDateWidget(_ref2) {
|
|
2776
2582
|
let {
|
|
2777
2583
|
time = false,
|
|
@@ -2787,7 +2593,8 @@ function AltDateWidget(_ref2) {
|
|
|
2787
2593
|
value
|
|
2788
2594
|
} = _ref2;
|
|
2789
2595
|
const [state, setState] = React.useReducer((state, action) => {
|
|
2790
|
-
return {
|
|
2596
|
+
return {
|
|
2597
|
+
...state,
|
|
2791
2598
|
...action
|
|
2792
2599
|
};
|
|
2793
2600
|
}, utils.parseDateString(value, time));
|
|
@@ -2809,21 +2616,17 @@ function AltDateWidget(_ref2) {
|
|
|
2809
2616
|
}, []);
|
|
2810
2617
|
const handleSetNow = React.useCallback(event => {
|
|
2811
2618
|
event.preventDefault();
|
|
2812
|
-
|
|
2813
2619
|
if (disabled || readonly) {
|
|
2814
2620
|
return;
|
|
2815
2621
|
}
|
|
2816
|
-
|
|
2817
2622
|
const nowDateObj = utils.parseDateString(new Date().toJSON(), time);
|
|
2818
2623
|
setState(nowDateObj);
|
|
2819
2624
|
}, [disabled, readonly, time]);
|
|
2820
2625
|
const handleClear = React.useCallback(event => {
|
|
2821
2626
|
event.preventDefault();
|
|
2822
|
-
|
|
2823
2627
|
if (disabled || readonly) {
|
|
2824
2628
|
return;
|
|
2825
2629
|
}
|
|
2826
|
-
|
|
2827
2630
|
setState(utils.parseDateString("", time));
|
|
2828
2631
|
onChange(undefined);
|
|
2829
2632
|
}, [disabled, readonly, time, onChange]);
|
|
@@ -2857,7 +2660,6 @@ function AltDateWidget(_ref2) {
|
|
|
2857
2660
|
*
|
|
2858
2661
|
* @param props - The `WidgetProps` for this component
|
|
2859
2662
|
*/
|
|
2860
|
-
|
|
2861
2663
|
function AltDateTimeWidget(_ref) {
|
|
2862
2664
|
let {
|
|
2863
2665
|
time = true,
|
|
@@ -2877,7 +2679,6 @@ function AltDateTimeWidget(_ref) {
|
|
|
2877
2679
|
*
|
|
2878
2680
|
* @param props - The `WidgetProps` for this component
|
|
2879
2681
|
*/
|
|
2880
|
-
|
|
2881
2682
|
function CheckboxWidget(_ref) {
|
|
2882
2683
|
let {
|
|
2883
2684
|
schema,
|
|
@@ -2894,16 +2695,16 @@ function CheckboxWidget(_ref) {
|
|
|
2894
2695
|
onChange,
|
|
2895
2696
|
registry
|
|
2896
2697
|
} = _ref;
|
|
2897
|
-
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2698
|
+
const DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, options);
|
|
2699
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
2898
2700
|
// the "required" attribute if the field value must be "true", due to the
|
|
2899
2701
|
// "const" or "enum" keywords
|
|
2900
|
-
|
|
2901
2702
|
const required = utils.schemaRequiresTrueValue(schema);
|
|
2902
2703
|
const handleChange = React.useCallback(event => onChange(event.target.checked), [onChange]);
|
|
2903
2704
|
const handleBlur = React.useCallback(event => onBlur(id, event.target.checked), [onBlur, id]);
|
|
2904
2705
|
const handleFocus = React.useCallback(event => onFocus(id, event.target.checked), [onFocus, id]);
|
|
2905
2706
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2906
|
-
className:
|
|
2707
|
+
className: `checkbox ${disabled || readonly ? "disabled" : ""}`
|
|
2907
2708
|
}, schema.description && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
|
|
2908
2709
|
id: id + "__description",
|
|
2909
2710
|
description: schema.description,
|
|
@@ -2926,12 +2727,11 @@ function CheckboxWidget(_ref) {
|
|
|
2926
2727
|
|
|
2927
2728
|
function selectValue(value, selected, all) {
|
|
2928
2729
|
const at = all.indexOf(value);
|
|
2929
|
-
const updated = selected.slice(0, at).concat(value, selected.slice(at));
|
|
2730
|
+
const updated = selected.slice(0, at).concat(value, selected.slice(at));
|
|
2731
|
+
// As inserting values at predefined index positions doesn't work with empty
|
|
2930
2732
|
// arrays, we need to reorder the updated selection to match the initial order
|
|
2931
|
-
|
|
2932
2733
|
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
2933
2734
|
}
|
|
2934
|
-
|
|
2935
2735
|
function deselectValue(value, selected) {
|
|
2936
2736
|
return selected.filter(v => v !== value);
|
|
2937
2737
|
}
|
|
@@ -2940,8 +2740,6 @@ function deselectValue(value, selected) {
|
|
|
2940
2740
|
*
|
|
2941
2741
|
* @param props - The `WidgetProps` for this component
|
|
2942
2742
|
*/
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
2743
|
function CheckboxesWidget(_ref) {
|
|
2946
2744
|
let {
|
|
2947
2745
|
id,
|
|
@@ -2963,7 +2761,6 @@ function CheckboxesWidget(_ref) {
|
|
|
2963
2761
|
const checked = value.indexOf(option.value) !== -1;
|
|
2964
2762
|
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
|
|
2965
2763
|
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
2966
|
-
|
|
2967
2764
|
const handleChange = event => {
|
|
2968
2765
|
const all = enumOptions.map(_ref2 => {
|
|
2969
2766
|
let {
|
|
@@ -2971,17 +2768,15 @@ function CheckboxesWidget(_ref) {
|
|
|
2971
2768
|
} = _ref2;
|
|
2972
2769
|
return value;
|
|
2973
2770
|
});
|
|
2974
|
-
|
|
2975
2771
|
if (event.target.checked) {
|
|
2976
2772
|
onChange(selectValue(option.value, value, all));
|
|
2977
2773
|
} else {
|
|
2978
2774
|
onChange(deselectValue(option.value, value));
|
|
2979
2775
|
}
|
|
2980
2776
|
};
|
|
2981
|
-
|
|
2982
2777
|
const checkbox = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
2983
2778
|
type: "checkbox",
|
|
2984
|
-
id: id
|
|
2779
|
+
id: `${id}-${option.value}`,
|
|
2985
2780
|
name: id,
|
|
2986
2781
|
checked: checked,
|
|
2987
2782
|
disabled: disabled || itemDisabled || readonly,
|
|
@@ -2990,10 +2785,10 @@ function CheckboxesWidget(_ref) {
|
|
|
2990
2785
|
}), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
|
|
2991
2786
|
return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
|
|
2992
2787
|
key: option.value,
|
|
2993
|
-
className:
|
|
2788
|
+
className: `checkbox-inline ${disabledCls}`
|
|
2994
2789
|
}, checkbox) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2995
2790
|
key: option.value,
|
|
2996
|
-
className:
|
|
2791
|
+
className: `checkbox ${disabledCls}`
|
|
2997
2792
|
}, /*#__PURE__*/React__default["default"].createElement("label", null, checkbox));
|
|
2998
2793
|
}));
|
|
2999
2794
|
}
|
|
@@ -3003,7 +2798,6 @@ function CheckboxesWidget(_ref) {
|
|
|
3003
2798
|
*
|
|
3004
2799
|
* @param props - The `WidgetProps` for this component
|
|
3005
2800
|
*/
|
|
3006
|
-
|
|
3007
2801
|
function ColorWidget(props) {
|
|
3008
2802
|
const {
|
|
3009
2803
|
disabled,
|
|
@@ -3024,7 +2818,6 @@ function ColorWidget(props) {
|
|
|
3024
2818
|
*
|
|
3025
2819
|
* @param props - The `WidgetProps` for this component
|
|
3026
2820
|
*/
|
|
3027
|
-
|
|
3028
2821
|
function DateWidget(props) {
|
|
3029
2822
|
const {
|
|
3030
2823
|
onChange,
|
|
@@ -3045,7 +2838,6 @@ function DateWidget(props) {
|
|
|
3045
2838
|
*
|
|
3046
2839
|
* @param props - The `WidgetProps` for this component
|
|
3047
2840
|
*/
|
|
3048
|
-
|
|
3049
2841
|
function DateTimeWidget(props) {
|
|
3050
2842
|
const {
|
|
3051
2843
|
onChange,
|
|
@@ -3066,7 +2858,6 @@ function DateTimeWidget(props) {
|
|
|
3066
2858
|
*
|
|
3067
2859
|
* @param props - The `WidgetProps` for this component
|
|
3068
2860
|
*/
|
|
3069
|
-
|
|
3070
2861
|
function EmailWidget(props) {
|
|
3071
2862
|
const {
|
|
3072
2863
|
options,
|
|
@@ -3083,10 +2874,8 @@ function addNameToDataURL(dataURL, name) {
|
|
|
3083
2874
|
if (dataURL === null) {
|
|
3084
2875
|
return null;
|
|
3085
2876
|
}
|
|
3086
|
-
|
|
3087
|
-
return dataURL.replace(";base64", ";name=" + encodeURIComponent(name) + ";base64");
|
|
2877
|
+
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
|
|
3088
2878
|
}
|
|
3089
|
-
|
|
3090
2879
|
function processFile(file) {
|
|
3091
2880
|
const {
|
|
3092
2881
|
name,
|
|
@@ -3096,10 +2885,8 @@ function processFile(file) {
|
|
|
3096
2885
|
return new Promise((resolve, reject) => {
|
|
3097
2886
|
const reader = new window.FileReader();
|
|
3098
2887
|
reader.onerror = reject;
|
|
3099
|
-
|
|
3100
2888
|
reader.onload = event => {
|
|
3101
2889
|
var _event$target;
|
|
3102
|
-
|
|
3103
2890
|
if (typeof ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result) === "string") {
|
|
3104
2891
|
resolve({
|
|
3105
2892
|
dataURL: addNameToDataURL(event.target.result, name),
|
|
@@ -3116,24 +2903,19 @@ function processFile(file) {
|
|
|
3116
2903
|
});
|
|
3117
2904
|
}
|
|
3118
2905
|
};
|
|
3119
|
-
|
|
3120
2906
|
reader.readAsDataURL(file);
|
|
3121
2907
|
});
|
|
3122
2908
|
}
|
|
3123
|
-
|
|
3124
2909
|
function processFiles(files) {
|
|
3125
2910
|
return Promise.all(Array.from(files).map(processFile));
|
|
3126
2911
|
}
|
|
3127
|
-
|
|
3128
2912
|
function FilesInfo(_ref) {
|
|
3129
2913
|
let {
|
|
3130
2914
|
filesInfo
|
|
3131
2915
|
} = _ref;
|
|
3132
|
-
|
|
3133
2916
|
if (filesInfo.length === 0) {
|
|
3134
2917
|
return null;
|
|
3135
2918
|
}
|
|
3136
|
-
|
|
3137
2919
|
return /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
3138
2920
|
className: "file-info"
|
|
3139
2921
|
}, filesInfo.map((fileInfo, key) => {
|
|
@@ -3147,7 +2929,6 @@ function FilesInfo(_ref) {
|
|
|
3147
2929
|
}, /*#__PURE__*/React__default["default"].createElement("strong", null, name), " (", type, ", ", size, " bytes)");
|
|
3148
2930
|
}));
|
|
3149
2931
|
}
|
|
3150
|
-
|
|
3151
2932
|
function extractFileInfo(dataURLs) {
|
|
3152
2933
|
return dataURLs.filter(dataURL => typeof dataURL !== "undefined").map(dataURL => {
|
|
3153
2934
|
const {
|
|
@@ -3165,8 +2946,6 @@ function extractFileInfo(dataURLs) {
|
|
|
3165
2946
|
* The `FileWidget` is a widget for rendering file upload fields.
|
|
3166
2947
|
* It is typically used with a string property with data-url format.
|
|
3167
2948
|
*/
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
2949
|
function FileWidget(_ref2) {
|
|
3171
2950
|
let {
|
|
3172
2951
|
multiple,
|
|
@@ -3184,11 +2963,9 @@ function FileWidget(_ref2) {
|
|
|
3184
2963
|
if (!event.target.files) {
|
|
3185
2964
|
return;
|
|
3186
2965
|
}
|
|
3187
|
-
|
|
3188
2966
|
processFiles(event.target.files).then(filesInfoEvent => {
|
|
3189
2967
|
setFilesInfo(filesInfoEvent);
|
|
3190
2968
|
const newValue = filesInfoEvent.map(fileInfo => fileInfo.dataURL);
|
|
3191
|
-
|
|
3192
2969
|
if (multiple) {
|
|
3193
2970
|
onChange(newValue);
|
|
3194
2971
|
} else {
|
|
@@ -3216,7 +2993,6 @@ function FileWidget(_ref2) {
|
|
|
3216
2993
|
*
|
|
3217
2994
|
* @param props - The `WidgetProps` for this component
|
|
3218
2995
|
*/
|
|
3219
|
-
|
|
3220
2996
|
function HiddenWidget(_ref) {
|
|
3221
2997
|
let {
|
|
3222
2998
|
id,
|
|
@@ -3234,7 +3010,6 @@ function HiddenWidget(_ref) {
|
|
|
3234
3010
|
*
|
|
3235
3011
|
* @param props - The `WidgetProps` for this component
|
|
3236
3012
|
*/
|
|
3237
|
-
|
|
3238
3013
|
function PasswordWidget(props) {
|
|
3239
3014
|
const {
|
|
3240
3015
|
options,
|
|
@@ -3252,7 +3027,6 @@ function PasswordWidget(props) {
|
|
|
3252
3027
|
*
|
|
3253
3028
|
* @param props - The `WidgetProps` for this component
|
|
3254
3029
|
*/
|
|
3255
|
-
|
|
3256
3030
|
function RadioWidget(_ref) {
|
|
3257
3031
|
let {
|
|
3258
3032
|
options,
|
|
@@ -3272,9 +3046,9 @@ function RadioWidget(_ref) {
|
|
|
3272
3046
|
enumOptions,
|
|
3273
3047
|
enumDisabled,
|
|
3274
3048
|
inline
|
|
3275
|
-
} = options;
|
|
3049
|
+
} = options;
|
|
3050
|
+
// checked={checked} has been moved above name={name}, As mentioned in #349;
|
|
3276
3051
|
// this is a temporary fix for radio button rendering bug in React, facebook/react#7630.
|
|
3277
|
-
|
|
3278
3052
|
const handleBlur = React.useCallback(event => onBlur(id, event.target.value), [onBlur, id]);
|
|
3279
3053
|
const handleFocus = React.useCallback(event => onFocus(id, event.target.value), [onFocus, id]);
|
|
3280
3054
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -3284,12 +3058,10 @@ function RadioWidget(_ref) {
|
|
|
3284
3058
|
const checked = option.value === value;
|
|
3285
3059
|
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) != -1;
|
|
3286
3060
|
const disabledCls = disabled || itemDisabled || readonly ? "disabled" : "";
|
|
3287
|
-
|
|
3288
3061
|
const handleChange = () => onChange(option.value);
|
|
3289
|
-
|
|
3290
3062
|
const radio = /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
3291
3063
|
type: "radio",
|
|
3292
|
-
id: id
|
|
3064
|
+
id: `${id}-${option.value}`,
|
|
3293
3065
|
checked: checked,
|
|
3294
3066
|
name: name,
|
|
3295
3067
|
required: required,
|
|
@@ -3302,10 +3074,10 @@ function RadioWidget(_ref) {
|
|
|
3302
3074
|
}), /*#__PURE__*/React__default["default"].createElement("span", null, option.label));
|
|
3303
3075
|
return inline ? /*#__PURE__*/React__default["default"].createElement("label", {
|
|
3304
3076
|
key: option.value,
|
|
3305
|
-
className:
|
|
3077
|
+
className: `radio-inline ${disabledCls}`
|
|
3306
3078
|
}, radio) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3307
3079
|
key: option.value,
|
|
3308
|
-
className:
|
|
3080
|
+
className: `radio ${disabledCls}`
|
|
3309
3081
|
}, /*#__PURE__*/React__default["default"].createElement("label", null, radio));
|
|
3310
3082
|
}));
|
|
3311
3083
|
}
|
|
@@ -3315,7 +3087,6 @@ function RadioWidget(_ref) {
|
|
|
3315
3087
|
*
|
|
3316
3088
|
* @param props - The `WidgetProps` for this component
|
|
3317
3089
|
*/
|
|
3318
|
-
|
|
3319
3090
|
function RangeWidget(props) {
|
|
3320
3091
|
const {
|
|
3321
3092
|
value,
|
|
@@ -3339,7 +3110,6 @@ function getValue(event, multiple) {
|
|
|
3339
3110
|
if (multiple) {
|
|
3340
3111
|
return Array.from(event.target.options).slice().filter(o => o.selected).map(o => o.value);
|
|
3341
3112
|
}
|
|
3342
|
-
|
|
3343
3113
|
return event.target.value;
|
|
3344
3114
|
}
|
|
3345
3115
|
/** The `SelectWidget` is a widget for rendering dropdowns.
|
|
@@ -3347,8 +3117,6 @@ function getValue(event, multiple) {
|
|
|
3347
3117
|
*
|
|
3348
3118
|
* @param props - The `WidgetProps` for this component
|
|
3349
3119
|
*/
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
3120
|
function SelectWidget(_ref) {
|
|
3353
3121
|
let {
|
|
3354
3122
|
schema,
|
|
@@ -3414,7 +3182,6 @@ function SelectWidget(_ref) {
|
|
|
3414
3182
|
*
|
|
3415
3183
|
* @param props - The `WidgetProps` for this component
|
|
3416
3184
|
*/
|
|
3417
|
-
|
|
3418
3185
|
function TextareaWidget(_ref) {
|
|
3419
3186
|
let {
|
|
3420
3187
|
id,
|
|
@@ -3469,7 +3236,6 @@ function TextareaWidget(_ref) {
|
|
|
3469
3236
|
onChange: handleChange
|
|
3470
3237
|
});
|
|
3471
3238
|
}
|
|
3472
|
-
|
|
3473
3239
|
TextareaWidget.defaultProps = {
|
|
3474
3240
|
autofocus: false,
|
|
3475
3241
|
options: {}
|
|
@@ -3479,14 +3245,14 @@ TextareaWidget.defaultProps = {
|
|
|
3479
3245
|
*
|
|
3480
3246
|
* @param props - The `WidgetProps` for this component
|
|
3481
3247
|
*/
|
|
3482
|
-
|
|
3483
3248
|
function TextWidget(props) {
|
|
3484
3249
|
const {
|
|
3485
3250
|
options,
|
|
3486
3251
|
registry
|
|
3487
3252
|
} = props;
|
|
3488
3253
|
const BaseInputTemplate = utils.getTemplate("BaseInputTemplate", registry, options);
|
|
3489
|
-
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
|
|
3254
|
+
return /*#__PURE__*/React__default["default"].createElement(BaseInputTemplate, {
|
|
3255
|
+
...props
|
|
3490
3256
|
});
|
|
3491
3257
|
}
|
|
3492
3258
|
|
|
@@ -3494,7 +3260,6 @@ function TextWidget(props) {
|
|
|
3494
3260
|
*
|
|
3495
3261
|
* @param props - The `WidgetProps` for this component
|
|
3496
3262
|
*/
|
|
3497
|
-
|
|
3498
3263
|
function URLWidget(props) {
|
|
3499
3264
|
const {
|
|
3500
3265
|
options,
|
|
@@ -3511,7 +3276,6 @@ function URLWidget(props) {
|
|
|
3511
3276
|
*
|
|
3512
3277
|
* @param props - The `WidgetProps` for this component
|
|
3513
3278
|
*/
|
|
3514
|
-
|
|
3515
3279
|
function UpDownWidget(props) {
|
|
3516
3280
|
const {
|
|
3517
3281
|
options,
|
|
@@ -3524,44 +3288,44 @@ function UpDownWidget(props) {
|
|
|
3524
3288
|
});
|
|
3525
3289
|
}
|
|
3526
3290
|
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3291
|
+
function widgets() {
|
|
3292
|
+
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
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3547
3313
|
|
|
3548
3314
|
/** The default registry consists of all the fields, templates and widgets provided in the core implementation,
|
|
3549
3315
|
* plus an empty `rootSchema` and `formContext. We omit schemaUtils here because it cannot be defaulted without a
|
|
3550
3316
|
* rootSchema and validator. It will be added into the computed registry later in the Form.
|
|
3551
3317
|
*/
|
|
3552
|
-
|
|
3553
3318
|
function getDefaultRegistry() {
|
|
3554
3319
|
return {
|
|
3555
|
-
fields,
|
|
3556
|
-
templates,
|
|
3557
|
-
widgets,
|
|
3320
|
+
fields: fields(),
|
|
3321
|
+
templates: templates(),
|
|
3322
|
+
widgets: widgets(),
|
|
3558
3323
|
rootSchema: {},
|
|
3559
3324
|
formContext: {}
|
|
3560
3325
|
};
|
|
3561
3326
|
}
|
|
3562
3327
|
|
|
3563
3328
|
/** The `Form` component renders the outer form and all the fields defined in the `schema` */
|
|
3564
|
-
|
|
3565
3329
|
class Form extends React.Component {
|
|
3566
3330
|
/** The ref used to hold the `form` element, this needs to be `any` because `tagName` or `_internalFormWrapper` can
|
|
3567
3331
|
* provide any possible type here
|
|
@@ -3576,36 +3340,30 @@ class Form extends React.Component {
|
|
|
3576
3340
|
constructor(props) {
|
|
3577
3341
|
super(props);
|
|
3578
3342
|
this.formElement = void 0;
|
|
3579
|
-
|
|
3580
3343
|
this.getUsedFormData = (formData, fields) => {
|
|
3581
3344
|
// For the case of a single input form
|
|
3582
3345
|
if (fields.length === 0 && typeof formData !== "object") {
|
|
3583
3346
|
return formData;
|
|
3584
3347
|
}
|
|
3585
|
-
|
|
3348
|
+
// _pick has incorrect type definition, it works with string[][], because lodash/hasIn supports it
|
|
3586
3349
|
const data = _pick__default["default"](formData, fields);
|
|
3587
|
-
|
|
3588
3350
|
if (Array.isArray(formData)) {
|
|
3589
3351
|
return Object.keys(data).map(key => data[key]);
|
|
3590
3352
|
}
|
|
3591
|
-
|
|
3592
3353
|
return data;
|
|
3593
3354
|
};
|
|
3594
|
-
|
|
3595
3355
|
this.getFieldNames = (pathSchema, formData) => {
|
|
3596
3356
|
const getAllPaths = function (_obj, acc, paths) {
|
|
3597
3357
|
if (acc === void 0) {
|
|
3598
3358
|
acc = [];
|
|
3599
3359
|
}
|
|
3600
|
-
|
|
3601
3360
|
if (paths === void 0) {
|
|
3602
|
-
paths = [
|
|
3361
|
+
paths = [[]];
|
|
3603
3362
|
}
|
|
3604
|
-
|
|
3605
3363
|
Object.keys(_obj).forEach(key => {
|
|
3606
3364
|
if (typeof _obj[key] === "object") {
|
|
3607
|
-
const newPaths = paths.map(path => path
|
|
3608
|
-
|
|
3365
|
+
const newPaths = paths.map(path => [...path, key]);
|
|
3366
|
+
// If an object is marked with additionalProperties, all its keys are valid
|
|
3609
3367
|
if (_obj[key][utils.RJSF_ADDITONAL_PROPERTIES_FLAG] && _obj[key][utils.NAME_KEY] !== "") {
|
|
3610
3368
|
acc.push(_obj[key][utils.NAME_KEY]);
|
|
3611
3369
|
} else {
|
|
@@ -3613,12 +3371,9 @@ class Form extends React.Component {
|
|
|
3613
3371
|
}
|
|
3614
3372
|
} else if (key === utils.NAME_KEY && _obj[key] !== "") {
|
|
3615
3373
|
paths.forEach(path => {
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
const formValue = get__default["default"](formData, path); // adds path to fieldNames if it points to a value
|
|
3374
|
+
const formValue = get__default["default"](formData, path);
|
|
3375
|
+
// adds path to fieldNames if it points to a value
|
|
3619
3376
|
// or an empty object/array
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
3377
|
if (typeof formValue !== "object" || _isEmpty__default["default"](formValue)) {
|
|
3623
3378
|
acc.push(path);
|
|
3624
3379
|
}
|
|
@@ -3627,10 +3382,8 @@ class Form extends React.Component {
|
|
|
3627
3382
|
});
|
|
3628
3383
|
return acc;
|
|
3629
3384
|
};
|
|
3630
|
-
|
|
3631
3385
|
return getAllPaths(pathSchema);
|
|
3632
3386
|
};
|
|
3633
|
-
|
|
3634
3387
|
this.onChange = (formData, newErrorSchema, id) => {
|
|
3635
3388
|
const {
|
|
3636
3389
|
extraErrors,
|
|
@@ -3644,19 +3397,16 @@ class Form extends React.Component {
|
|
|
3644
3397
|
schemaUtils,
|
|
3645
3398
|
schema
|
|
3646
3399
|
} = this.state;
|
|
3647
|
-
|
|
3648
3400
|
if (utils.isObject(formData) || Array.isArray(formData)) {
|
|
3649
3401
|
const newState = this.getStateFromProps(this.props, formData);
|
|
3650
3402
|
formData = newState.formData;
|
|
3651
3403
|
}
|
|
3652
|
-
|
|
3653
3404
|
const mustValidate = !noValidate && liveValidate;
|
|
3654
3405
|
let state = {
|
|
3655
3406
|
formData,
|
|
3656
3407
|
schema
|
|
3657
3408
|
};
|
|
3658
3409
|
let newFormData = formData;
|
|
3659
|
-
|
|
3660
3410
|
if (omitExtraData === true && liveOmit === true) {
|
|
3661
3411
|
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3662
3412
|
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
@@ -3666,20 +3416,17 @@ class Form extends React.Component {
|
|
|
3666
3416
|
formData: newFormData
|
|
3667
3417
|
};
|
|
3668
3418
|
}
|
|
3669
|
-
|
|
3670
3419
|
if (mustValidate) {
|
|
3671
3420
|
const schemaValidation = this.validate(newFormData);
|
|
3672
3421
|
let errors = schemaValidation.errors;
|
|
3673
3422
|
let errorSchema = schemaValidation.errorSchema;
|
|
3674
3423
|
const schemaValidationErrors = errors;
|
|
3675
3424
|
const schemaValidationErrorSchema = errorSchema;
|
|
3676
|
-
|
|
3677
3425
|
if (extraErrors) {
|
|
3678
3426
|
const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
|
|
3679
3427
|
errorSchema = merged.errorSchema;
|
|
3680
3428
|
errors = merged.errors;
|
|
3681
3429
|
}
|
|
3682
|
-
|
|
3683
3430
|
state = {
|
|
3684
3431
|
formData: newFormData,
|
|
3685
3432
|
errors,
|
|
@@ -3695,39 +3442,32 @@ class Form extends React.Component {
|
|
|
3695
3442
|
errors: schemaUtils.getValidator().toErrorList(errorSchema)
|
|
3696
3443
|
};
|
|
3697
3444
|
}
|
|
3698
|
-
|
|
3699
|
-
|
|
3445
|
+
this.setState(state, () => onChange && onChange({
|
|
3446
|
+
...this.state,
|
|
3700
3447
|
...state
|
|
3701
3448
|
}, id));
|
|
3702
3449
|
};
|
|
3703
|
-
|
|
3704
3450
|
this.onBlur = (id, data) => {
|
|
3705
3451
|
const {
|
|
3706
3452
|
onBlur
|
|
3707
3453
|
} = this.props;
|
|
3708
|
-
|
|
3709
3454
|
if (onBlur) {
|
|
3710
3455
|
onBlur(id, data);
|
|
3711
3456
|
}
|
|
3712
3457
|
};
|
|
3713
|
-
|
|
3714
3458
|
this.onFocus = (id, data) => {
|
|
3715
3459
|
const {
|
|
3716
3460
|
onFocus
|
|
3717
3461
|
} = this.props;
|
|
3718
|
-
|
|
3719
3462
|
if (onFocus) {
|
|
3720
3463
|
onFocus(id, data);
|
|
3721
3464
|
}
|
|
3722
3465
|
};
|
|
3723
|
-
|
|
3724
3466
|
this.onSubmit = event => {
|
|
3725
3467
|
event.preventDefault();
|
|
3726
|
-
|
|
3727
3468
|
if (event.target !== event.currentTarget) {
|
|
3728
3469
|
return;
|
|
3729
3470
|
}
|
|
3730
|
-
|
|
3731
3471
|
event.persist();
|
|
3732
3472
|
const {
|
|
3733
3473
|
omitExtraData,
|
|
@@ -3742,14 +3482,12 @@ class Form extends React.Component {
|
|
|
3742
3482
|
schema,
|
|
3743
3483
|
schemaUtils
|
|
3744
3484
|
} = this.state;
|
|
3745
|
-
|
|
3746
3485
|
if (omitExtraData === true) {
|
|
3747
3486
|
const retrievedSchema = schemaUtils.retrieveSchema(schema, newFormData);
|
|
3748
3487
|
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", newFormData);
|
|
3749
3488
|
const fieldNames = this.getFieldNames(pathSchema, newFormData);
|
|
3750
3489
|
newFormData = this.getUsedFormData(newFormData, fieldNames);
|
|
3751
3490
|
}
|
|
3752
|
-
|
|
3753
3491
|
if (noValidate || this.validateForm()) {
|
|
3754
3492
|
// There are no errors generated through schema validation.
|
|
3755
3493
|
// Check for user provided errors and update state accordingly.
|
|
@@ -3763,7 +3501,8 @@ class Form extends React.Component {
|
|
|
3763
3501
|
schemaValidationErrorSchema: {}
|
|
3764
3502
|
}, () => {
|
|
3765
3503
|
if (onSubmit) {
|
|
3766
|
-
onSubmit({
|
|
3504
|
+
onSubmit({
|
|
3505
|
+
...this.state,
|
|
3767
3506
|
formData: newFormData,
|
|
3768
3507
|
status: "submitted"
|
|
3769
3508
|
}, event);
|
|
@@ -3771,17 +3510,13 @@ class Form extends React.Component {
|
|
|
3771
3510
|
});
|
|
3772
3511
|
}
|
|
3773
3512
|
};
|
|
3774
|
-
|
|
3775
3513
|
if (!props.validator) {
|
|
3776
3514
|
throw new Error("A validator is required for Form functionality to work");
|
|
3777
3515
|
}
|
|
3778
|
-
|
|
3779
3516
|
this.state = this.getStateFromProps(props, props.formData);
|
|
3780
|
-
|
|
3781
3517
|
if (this.props.onChange && !utils.deepEquals(this.state.formData, this.props.formData)) {
|
|
3782
3518
|
this.props.onChange(this.state);
|
|
3783
3519
|
}
|
|
3784
|
-
|
|
3785
3520
|
this.formElement = /*#__PURE__*/React__default["default"].createRef();
|
|
3786
3521
|
}
|
|
3787
3522
|
/** React lifecycle method that gets called before new props are provided, updates the state based on new props. It
|
|
@@ -3790,15 +3525,11 @@ class Form extends React.Component {
|
|
|
3790
3525
|
*
|
|
3791
3526
|
* @param nextProps - The new set of props about to be applied to the `Form`
|
|
3792
3527
|
*/
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
3528
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
3796
3529
|
const nextState = this.getStateFromProps(nextProps, nextProps.formData);
|
|
3797
|
-
|
|
3798
3530
|
if (!utils.deepEquals(nextState.formData, nextProps.formData) && !utils.deepEquals(nextState.formData, this.state.formData) && nextProps.onChange) {
|
|
3799
3531
|
nextProps.onChange(nextState);
|
|
3800
3532
|
}
|
|
3801
|
-
|
|
3802
3533
|
this.setState(nextState);
|
|
3803
3534
|
}
|
|
3804
3535
|
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
@@ -3809,8 +3540,6 @@ class Form extends React.Component {
|
|
|
3809
3540
|
* @param inputFormData - The new or current data for the `Form`
|
|
3810
3541
|
* @returns - The new state for the `Form`
|
|
3811
3542
|
*/
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
3543
|
getStateFromProps(props, inputFormData) {
|
|
3815
3544
|
const state = this.state || {};
|
|
3816
3545
|
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
@@ -3820,14 +3549,11 @@ class Form extends React.Component {
|
|
|
3820
3549
|
const mustValidate = edit && !props.noValidate && liveValidate;
|
|
3821
3550
|
const rootSchema = schema;
|
|
3822
3551
|
let schemaUtils = state.schemaUtils;
|
|
3823
|
-
|
|
3824
3552
|
if (!schemaUtils || schemaUtils.doesSchemaUtilsDiffer(props.validator, rootSchema)) {
|
|
3825
3553
|
schemaUtils = utils.createSchemaUtils(props.validator, rootSchema);
|
|
3826
3554
|
}
|
|
3827
|
-
|
|
3828
3555
|
const formData = schemaUtils.getDefaultFormState(schema, inputFormData);
|
|
3829
3556
|
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3830
|
-
|
|
3831
3557
|
const getCurrentErrors = () => {
|
|
3832
3558
|
if (props.noValidate) {
|
|
3833
3559
|
return {
|
|
@@ -3840,18 +3566,15 @@ class Form extends React.Component {
|
|
|
3840
3566
|
errorSchema: state.schemaValidationErrorSchema || {}
|
|
3841
3567
|
};
|
|
3842
3568
|
}
|
|
3843
|
-
|
|
3844
3569
|
return {
|
|
3845
3570
|
errors: state.errors || [],
|
|
3846
3571
|
errorSchema: state.errorSchema || {}
|
|
3847
3572
|
};
|
|
3848
3573
|
};
|
|
3849
|
-
|
|
3850
3574
|
let errors;
|
|
3851
3575
|
let errorSchema;
|
|
3852
3576
|
let schemaValidationErrors = state.schemaValidationErrors;
|
|
3853
3577
|
let schemaValidationErrorSchema = state.schemaValidationErrorSchema;
|
|
3854
|
-
|
|
3855
3578
|
if (mustValidate) {
|
|
3856
3579
|
const schemaValidation = this.validate(formData, schema, schemaUtils);
|
|
3857
3580
|
errors = schemaValidation.errors;
|
|
@@ -3863,7 +3586,6 @@ class Form extends React.Component {
|
|
|
3863
3586
|
errors = currentErrors.errors;
|
|
3864
3587
|
errorSchema = currentErrors.errorSchema;
|
|
3865
3588
|
}
|
|
3866
|
-
|
|
3867
3589
|
if (props.extraErrors) {
|
|
3868
3590
|
const merged = schemaUtils.mergeValidationData({
|
|
3869
3591
|
errorSchema,
|
|
@@ -3872,7 +3594,6 @@ class Form extends React.Component {
|
|
|
3872
3594
|
errorSchema = merged.errorSchema;
|
|
3873
3595
|
errors = merged.errors;
|
|
3874
3596
|
}
|
|
3875
|
-
|
|
3876
3597
|
const idSchema = schemaUtils.toIdSchema(retrievedSchema, uiSchema["ui:rootFieldId"], formData, props.idPrefix, props.idSeparator);
|
|
3877
3598
|
const nextState = {
|
|
3878
3599
|
schemaUtils,
|
|
@@ -3894,8 +3615,6 @@ class Form extends React.Component {
|
|
|
3894
3615
|
* @param nextState - The next version of the state
|
|
3895
3616
|
* @returns - True if the component should be updated, false otherwise
|
|
3896
3617
|
*/
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
3618
|
shouldComponentUpdate(nextProps, nextState) {
|
|
3900
3619
|
return utils.shouldRender(this, nextProps, nextState);
|
|
3901
3620
|
}
|
|
@@ -3906,13 +3625,10 @@ class Form extends React.Component {
|
|
|
3906
3625
|
* @param schema - The schema used to validate against
|
|
3907
3626
|
* @param altSchemaUtils - The alternate schemaUtils to use for validation
|
|
3908
3627
|
*/
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
3628
|
validate(formData, schema, altSchemaUtils) {
|
|
3912
3629
|
if (schema === void 0) {
|
|
3913
3630
|
schema = this.props.schema;
|
|
3914
3631
|
}
|
|
3915
|
-
|
|
3916
3632
|
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
3917
3633
|
const {
|
|
3918
3634
|
customValidate,
|
|
@@ -3922,8 +3638,6 @@ class Form extends React.Component {
|
|
|
3922
3638
|
return schemaUtils.getValidator().validateFormData(formData, resolvedSchema, customValidate, transformErrors);
|
|
3923
3639
|
}
|
|
3924
3640
|
/** Renders any errors contained in the `state` in using the `ErrorList`, if not disabled by `showErrorList`. */
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
3641
|
renderErrors(registry) {
|
|
3928
3642
|
const {
|
|
3929
3643
|
errors,
|
|
@@ -3932,13 +3646,11 @@ class Form extends React.Component {
|
|
|
3932
3646
|
uiSchema
|
|
3933
3647
|
} = this.state;
|
|
3934
3648
|
const {
|
|
3935
|
-
showErrorList,
|
|
3936
3649
|
formContext
|
|
3937
3650
|
} = this.props;
|
|
3938
3651
|
const options = utils.getUiOptions(uiSchema);
|
|
3939
3652
|
const ErrorListTemplate = utils.getTemplate("ErrorListTemplate", registry, options);
|
|
3940
|
-
|
|
3941
|
-
if (errors && errors.length && showErrorList != false) {
|
|
3653
|
+
if (errors && errors.length) {
|
|
3942
3654
|
return /*#__PURE__*/React__default["default"].createElement(ErrorListTemplate, {
|
|
3943
3655
|
errors: errors,
|
|
3944
3656
|
errorSchema: errorSchema || {},
|
|
@@ -3947,7 +3659,6 @@ class Form extends React.Component {
|
|
|
3947
3659
|
formContext: formContext
|
|
3948
3660
|
});
|
|
3949
3661
|
}
|
|
3950
|
-
|
|
3951
3662
|
return null;
|
|
3952
3663
|
}
|
|
3953
3664
|
/** Returns the `formData` with only the elements specified in the `fields` list
|
|
@@ -3956,11 +3667,9 @@ class Form extends React.Component {
|
|
|
3956
3667
|
* @param fields - The fields to keep while filtering
|
|
3957
3668
|
*/
|
|
3958
3669
|
|
|
3959
|
-
|
|
3960
3670
|
/** Returns the registry for the form */
|
|
3961
3671
|
getRegistry() {
|
|
3962
3672
|
var _this$props$templates;
|
|
3963
|
-
|
|
3964
3673
|
const {
|
|
3965
3674
|
schemaUtils
|
|
3966
3675
|
} = this.state;
|
|
@@ -3971,16 +3680,20 @@ class Form extends React.Component {
|
|
|
3971
3680
|
formContext
|
|
3972
3681
|
} = getDefaultRegistry();
|
|
3973
3682
|
return {
|
|
3974
|
-
fields: {
|
|
3683
|
+
fields: {
|
|
3684
|
+
...fields,
|
|
3975
3685
|
...this.props.fields
|
|
3976
3686
|
},
|
|
3977
|
-
templates: {
|
|
3687
|
+
templates: {
|
|
3688
|
+
...templates,
|
|
3978
3689
|
...this.props.templates,
|
|
3979
|
-
ButtonTemplates: {
|
|
3690
|
+
ButtonTemplates: {
|
|
3691
|
+
...templates.ButtonTemplates,
|
|
3980
3692
|
...((_this$props$templates = this.props.templates) === null || _this$props$templates === void 0 ? void 0 : _this$props$templates.ButtonTemplates)
|
|
3981
3693
|
}
|
|
3982
3694
|
},
|
|
3983
|
-
widgets: {
|
|
3695
|
+
widgets: {
|
|
3696
|
+
...widgets,
|
|
3984
3697
|
...this.props.widgets
|
|
3985
3698
|
},
|
|
3986
3699
|
rootSchema: this.props.schema,
|
|
@@ -3989,8 +3702,6 @@ class Form extends React.Component {
|
|
|
3989
3702
|
};
|
|
3990
3703
|
}
|
|
3991
3704
|
/** Provides a function that can be used to programmatically submit the `Form` */
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
3705
|
submit() {
|
|
3995
3706
|
if (this.formElement.current) {
|
|
3996
3707
|
this.formElement.current.dispatchEvent(new CustomEvent("submit", {
|
|
@@ -4004,8 +3715,6 @@ class Form extends React.Component {
|
|
|
4004
3715
|
*
|
|
4005
3716
|
* @returns - True if the form is valid, false otherwise.
|
|
4006
3717
|
*/
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
3718
|
validateForm() {
|
|
4010
3719
|
const {
|
|
4011
3720
|
extraErrors,
|
|
@@ -4022,14 +3731,12 @@ class Form extends React.Component {
|
|
|
4022
3731
|
let errorSchema = schemaValidation.errorSchema;
|
|
4023
3732
|
const schemaValidationErrors = errors;
|
|
4024
3733
|
const schemaValidationErrorSchema = errorSchema;
|
|
4025
|
-
|
|
4026
3734
|
if (errors.length > 0) {
|
|
4027
3735
|
if (extraErrors) {
|
|
4028
3736
|
const merged = schemaUtils.mergeValidationData(schemaValidation, extraErrors);
|
|
4029
3737
|
errorSchema = merged.errorSchema;
|
|
4030
3738
|
errors = merged.errors;
|
|
4031
3739
|
}
|
|
4032
|
-
|
|
4033
3740
|
this.setState({
|
|
4034
3741
|
errors,
|
|
4035
3742
|
errorSchema,
|
|
@@ -4044,14 +3751,11 @@ class Form extends React.Component {
|
|
|
4044
3751
|
});
|
|
4045
3752
|
return false;
|
|
4046
3753
|
}
|
|
4047
|
-
|
|
4048
3754
|
return true;
|
|
4049
3755
|
}
|
|
4050
3756
|
/** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
|
|
4051
3757
|
* needed along with the submit button or any children of the form.
|
|
4052
3758
|
*/
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
3759
|
render() {
|
|
4056
3760
|
const {
|
|
4057
3761
|
children,
|
|
@@ -4071,6 +3775,7 @@ class Form extends React.Component {
|
|
|
4071
3775
|
disabled = false,
|
|
4072
3776
|
readonly = false,
|
|
4073
3777
|
formContext,
|
|
3778
|
+
showErrorList = "top",
|
|
4074
3779
|
_internalFormWrapper
|
|
4075
3780
|
} = this.props;
|
|
4076
3781
|
const {
|
|
@@ -4086,10 +3791,10 @@ class Form extends React.Component {
|
|
|
4086
3791
|
} = registry.fields;
|
|
4087
3792
|
const {
|
|
4088
3793
|
SubmitButton
|
|
4089
|
-
} = registry.templates.ButtonTemplates;
|
|
4090
|
-
//
|
|
3794
|
+
} = registry.templates.ButtonTemplates;
|
|
3795
|
+
// The `semantic-ui` and `material-ui` themes have `_internalFormWrapper`s that take an `as` prop that is the
|
|
3796
|
+
// PropTypes.elementType to use for the inner tag, so we'll need to pass `tagName` along if it is provided.
|
|
4091
3797
|
// NOTE, the `as` prop is native to `semantic-ui` and is emulated in the `material-ui` theme
|
|
4092
|
-
|
|
4093
3798
|
const as = _internalFormWrapper ? tagName : undefined;
|
|
4094
3799
|
const FormTag = _internalFormWrapper || tagName || "form";
|
|
4095
3800
|
return /*#__PURE__*/React__default["default"].createElement(FormTag, {
|
|
@@ -4106,7 +3811,7 @@ class Form extends React.Component {
|
|
|
4106
3811
|
onSubmit: this.onSubmit,
|
|
4107
3812
|
as: as,
|
|
4108
3813
|
ref: this.formElement
|
|
4109
|
-
}, this.renderErrors(registry), /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
|
|
3814
|
+
}, showErrorList === "top" && this.renderErrors(registry), /*#__PURE__*/React__default["default"].createElement(_SchemaField, {
|
|
4110
3815
|
name: "",
|
|
4111
3816
|
schema: schema,
|
|
4112
3817
|
uiSchema: uiSchema,
|
|
@@ -4124,36 +3829,38 @@ class Form extends React.Component {
|
|
|
4124
3829
|
readonly: readonly
|
|
4125
3830
|
}), children ? children : /*#__PURE__*/React__default["default"].createElement(SubmitButton, {
|
|
4126
3831
|
uiSchema: uiSchema
|
|
4127
|
-
}));
|
|
3832
|
+
}), showErrorList === "bottom" && this.renderErrors(registry));
|
|
4128
3833
|
}
|
|
4129
|
-
|
|
4130
3834
|
}
|
|
4131
3835
|
|
|
4132
3836
|
/** A Higher-Order component that creates a wrapper around a `Form` with the overrides from the `WithThemeProps` */
|
|
4133
|
-
|
|
4134
3837
|
function withTheme(themeProps) {
|
|
4135
3838
|
return /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
4136
3839
|
var _themeProps$templates, _templates;
|
|
4137
|
-
|
|
4138
3840
|
let {
|
|
4139
3841
|
fields,
|
|
4140
3842
|
widgets,
|
|
4141
3843
|
templates,
|
|
4142
3844
|
...directProps
|
|
4143
3845
|
} = _ref;
|
|
4144
|
-
fields = {
|
|
3846
|
+
fields = {
|
|
3847
|
+
...themeProps.fields,
|
|
4145
3848
|
...fields
|
|
4146
3849
|
};
|
|
4147
|
-
widgets = {
|
|
3850
|
+
widgets = {
|
|
3851
|
+
...themeProps.widgets,
|
|
4148
3852
|
...widgets
|
|
4149
3853
|
};
|
|
4150
|
-
templates = {
|
|
3854
|
+
templates = {
|
|
3855
|
+
...themeProps.templates,
|
|
4151
3856
|
...templates,
|
|
4152
|
-
ButtonTemplates: {
|
|
3857
|
+
ButtonTemplates: {
|
|
3858
|
+
...(themeProps === null || themeProps === void 0 ? void 0 : (_themeProps$templates = themeProps.templates) === null || _themeProps$templates === void 0 ? void 0 : _themeProps$templates.ButtonTemplates),
|
|
4153
3859
|
...((_templates = templates) === null || _templates === void 0 ? void 0 : _templates.ButtonTemplates)
|
|
4154
3860
|
}
|
|
4155
3861
|
};
|
|
4156
|
-
return /*#__PURE__*/React__default["default"].createElement(Form, {
|
|
3862
|
+
return /*#__PURE__*/React__default["default"].createElement(Form, {
|
|
3863
|
+
...themeProps,
|
|
4157
3864
|
...directProps,
|
|
4158
3865
|
fields: fields,
|
|
4159
3866
|
widgets: widgets,
|