@rjsf/utils 5.2.0 → 5.2.1
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/LICENSE.md +183 -183
- package/dist/index.d.ts +80 -60
- package/dist/utils.cjs.development.js +216 -199
- package/dist/utils.cjs.development.js.map +1 -1
- package/dist/utils.cjs.production.min.js +1 -1
- package/dist/utils.cjs.production.min.js.map +1 -1
- package/dist/utils.esm.js +216 -198
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +218 -202
- package/dist/utils.umd.development.js.map +1 -1
- package/dist/utils.umd.production.min.js +1 -1
- package/dist/utils.umd.production.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -17,7 +17,8 @@ var mergeAllOf = require('json-schema-merge-allof');
|
|
|
17
17
|
var union = require('lodash/union');
|
|
18
18
|
var isEqual = require('lodash/isEqual');
|
|
19
19
|
var cloneDeep = require('lodash/cloneDeep');
|
|
20
|
-
var
|
|
20
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
+
var react = require('react');
|
|
21
22
|
var ReactIs = require('react-is');
|
|
22
23
|
|
|
23
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -37,7 +38,6 @@ var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
|
|
|
37
38
|
var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
|
|
38
39
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
39
40
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
40
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
41
41
|
var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
42
42
|
|
|
43
43
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
@@ -47,13 +47,13 @@ var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
|
47
47
|
* @returns - True if it is a non-null, non-array, non-File object
|
|
48
48
|
*/
|
|
49
49
|
function isObject(thing) {
|
|
50
|
-
if (typeof File !==
|
|
50
|
+
if (typeof File !== 'undefined' && thing instanceof File) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
|
-
if (typeof Date !==
|
|
53
|
+
if (typeof Date !== 'undefined' && thing instanceof Date) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
-
return typeof thing ===
|
|
56
|
+
return typeof thing === 'object' && thing !== null && !Array.isArray(thing);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
|
|
@@ -64,7 +64,7 @@ function isObject(thing) {
|
|
|
64
64
|
*/
|
|
65
65
|
function allowAdditionalItems(schema) {
|
|
66
66
|
if (schema.additionalItems === true) {
|
|
67
|
-
console.warn(
|
|
67
|
+
console.warn('additionalItems=true is currently not supported');
|
|
68
68
|
}
|
|
69
69
|
return isObject(schema.additionalItems);
|
|
70
70
|
}
|
|
@@ -79,7 +79,7 @@ function allowAdditionalItems(schema) {
|
|
|
79
79
|
* @returns - The `value` converted to a number when appropriate, otherwise the `value`
|
|
80
80
|
*/
|
|
81
81
|
function asNumber(value) {
|
|
82
|
-
if (value ===
|
|
82
|
+
if (value === '') {
|
|
83
83
|
return undefined;
|
|
84
84
|
}
|
|
85
85
|
if (value === null) {
|
|
@@ -101,7 +101,7 @@ function asNumber(value) {
|
|
|
101
101
|
return value;
|
|
102
102
|
}
|
|
103
103
|
var n = Number(value);
|
|
104
|
-
var valid = typeof n ===
|
|
104
|
+
var valid = typeof n === 'number' && !Number.isNaN(n);
|
|
105
105
|
return valid ? n : value;
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -171,28 +171,28 @@ function _toPropertyKey(arg) {
|
|
|
171
171
|
* `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
|
|
172
172
|
* utility.
|
|
173
173
|
*/
|
|
174
|
-
var ADDITIONAL_PROPERTY_FLAG =
|
|
175
|
-
var ADDITIONAL_PROPERTIES_KEY =
|
|
176
|
-
var ALL_OF_KEY =
|
|
177
|
-
var ANY_OF_KEY =
|
|
178
|
-
var CONST_KEY =
|
|
179
|
-
var DEFAULT_KEY =
|
|
180
|
-
var DEFINITIONS_KEY =
|
|
181
|
-
var DEPENDENCIES_KEY =
|
|
182
|
-
var ENUM_KEY =
|
|
183
|
-
var ERRORS_KEY =
|
|
184
|
-
var ID_KEY =
|
|
185
|
-
var ITEMS_KEY =
|
|
186
|
-
var NAME_KEY =
|
|
187
|
-
var ONE_OF_KEY =
|
|
188
|
-
var PROPERTIES_KEY =
|
|
189
|
-
var REQUIRED_KEY =
|
|
190
|
-
var SUBMIT_BTN_OPTIONS_KEY =
|
|
191
|
-
var REF_KEY =
|
|
192
|
-
var RJSF_ADDITONAL_PROPERTIES_FLAG =
|
|
193
|
-
var UI_FIELD_KEY =
|
|
194
|
-
var UI_WIDGET_KEY =
|
|
195
|
-
var UI_OPTIONS_KEY =
|
|
174
|
+
var ADDITIONAL_PROPERTY_FLAG = '__additional_property';
|
|
175
|
+
var ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
|
|
176
|
+
var ALL_OF_KEY = 'allOf';
|
|
177
|
+
var ANY_OF_KEY = 'anyOf';
|
|
178
|
+
var CONST_KEY = 'const';
|
|
179
|
+
var DEFAULT_KEY = 'default';
|
|
180
|
+
var DEFINITIONS_KEY = 'definitions';
|
|
181
|
+
var DEPENDENCIES_KEY = 'dependencies';
|
|
182
|
+
var ENUM_KEY = 'enum';
|
|
183
|
+
var ERRORS_KEY = '__errors';
|
|
184
|
+
var ID_KEY = '$id';
|
|
185
|
+
var ITEMS_KEY = 'items';
|
|
186
|
+
var NAME_KEY = '$name';
|
|
187
|
+
var ONE_OF_KEY = 'oneOf';
|
|
188
|
+
var PROPERTIES_KEY = 'properties';
|
|
189
|
+
var REQUIRED_KEY = 'required';
|
|
190
|
+
var SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
191
|
+
var REF_KEY = '$ref';
|
|
192
|
+
var RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
|
|
193
|
+
var UI_FIELD_KEY = 'ui:field';
|
|
194
|
+
var UI_WIDGET_KEY = 'ui:widget';
|
|
195
|
+
var UI_OPTIONS_KEY = 'ui:options';
|
|
196
196
|
|
|
197
197
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
198
198
|
* stripped off.
|
|
@@ -205,12 +205,12 @@ function getUiOptions(uiSchema) {
|
|
|
205
205
|
uiSchema = {};
|
|
206
206
|
}
|
|
207
207
|
return Object.keys(uiSchema).filter(function (key) {
|
|
208
|
-
return key.indexOf(
|
|
208
|
+
return key.indexOf('ui:') === 0;
|
|
209
209
|
}).reduce(function (options, key) {
|
|
210
210
|
var _extends2;
|
|
211
211
|
var value = uiSchema[key];
|
|
212
212
|
if (key === UI_WIDGET_KEY && isObject(value)) {
|
|
213
|
-
console.error(
|
|
213
|
+
console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
|
|
214
214
|
return options;
|
|
215
215
|
}
|
|
216
216
|
if (key === UI_OPTIONS_KEY && isObject(value)) {
|
|
@@ -259,7 +259,7 @@ function canExpand(schema, uiSchema, formData) {
|
|
|
259
259
|
*/
|
|
260
260
|
function deepEquals(a, b) {
|
|
261
261
|
return isEqualWith__default["default"](a, b, function (obj, other) {
|
|
262
|
-
if (typeof obj ===
|
|
262
|
+
if (typeof obj === 'function' && typeof other === 'function') {
|
|
263
263
|
// Assume all functions are equivalent
|
|
264
264
|
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
265
265
|
return true;
|
|
@@ -294,8 +294,8 @@ function findSchemaDefinition($ref, rootSchema) {
|
|
|
294
294
|
if (rootSchema === void 0) {
|
|
295
295
|
rootSchema = {};
|
|
296
296
|
}
|
|
297
|
-
var ref = $ref ||
|
|
298
|
-
if (ref.startsWith(
|
|
297
|
+
var ref = $ref || '';
|
|
298
|
+
if (ref.startsWith('#')) {
|
|
299
299
|
// Decode URI fragment representation.
|
|
300
300
|
ref = decodeURIComponent(ref.substring(1));
|
|
301
301
|
} else {
|
|
@@ -403,25 +403,25 @@ function getFirstMatchingOption(validator, formData, options, rootSchema) {
|
|
|
403
403
|
*/
|
|
404
404
|
function guessType(value) {
|
|
405
405
|
if (Array.isArray(value)) {
|
|
406
|
-
return
|
|
406
|
+
return 'array';
|
|
407
407
|
}
|
|
408
|
-
if (typeof value ===
|
|
409
|
-
return
|
|
408
|
+
if (typeof value === 'string') {
|
|
409
|
+
return 'string';
|
|
410
410
|
}
|
|
411
411
|
if (value == null) {
|
|
412
|
-
return
|
|
412
|
+
return 'null';
|
|
413
413
|
}
|
|
414
|
-
if (typeof value ===
|
|
415
|
-
return
|
|
414
|
+
if (typeof value === 'boolean') {
|
|
415
|
+
return 'boolean';
|
|
416
416
|
}
|
|
417
417
|
if (!isNaN(value)) {
|
|
418
|
-
return
|
|
418
|
+
return 'number';
|
|
419
419
|
}
|
|
420
|
-
if (typeof value ===
|
|
421
|
-
return
|
|
420
|
+
if (typeof value === 'object') {
|
|
421
|
+
return 'object';
|
|
422
422
|
}
|
|
423
423
|
// Default to string if we can't figure it out
|
|
424
|
-
return
|
|
424
|
+
return 'string';
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
/** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
|
|
@@ -441,14 +441,14 @@ function getSchemaType(schema) {
|
|
|
441
441
|
return guessType(schema["const"]);
|
|
442
442
|
}
|
|
443
443
|
if (!type && schema["enum"]) {
|
|
444
|
-
return
|
|
444
|
+
return 'string';
|
|
445
445
|
}
|
|
446
446
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
447
|
-
return
|
|
447
|
+
return 'object';
|
|
448
448
|
}
|
|
449
|
-
if (Array.isArray(type) && type.length === 2 && type.includes(
|
|
449
|
+
if (Array.isArray(type) && type.length === 2 && type.includes('null')) {
|
|
450
450
|
type = type.find(function (type) {
|
|
451
|
-
return type !==
|
|
451
|
+
return type !== 'null';
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
454
|
return type;
|
|
@@ -469,7 +469,7 @@ function mergeSchemas(obj1, obj2) {
|
|
|
469
469
|
right = obj2[key];
|
|
470
470
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
471
471
|
acc[key] = mergeSchemas(left, right);
|
|
472
|
-
} else if (obj1 && obj2 && (getSchemaType(obj1) ===
|
|
472
|
+
} else if (obj1 && obj2 && (getSchemaType(obj1) === 'object' || getSchemaType(obj2) === 'object') && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
|
|
473
473
|
// Don't include duplicate values when merging 'required' fields.
|
|
474
474
|
acc[key] = union__default["default"](left, right);
|
|
475
475
|
} else {
|
|
@@ -499,7 +499,7 @@ function resolveCondition(validator, schema, rootSchema, formData) {
|
|
|
499
499
|
otherwise = schema["else"],
|
|
500
500
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
501
501
|
var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
|
|
502
|
-
if (conditionalSchema && typeof conditionalSchema !==
|
|
502
|
+
if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
|
|
503
503
|
return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
|
|
504
504
|
}
|
|
505
505
|
return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
|
|
@@ -571,16 +571,16 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
571
571
|
return;
|
|
572
572
|
}
|
|
573
573
|
var additionalProperties = {};
|
|
574
|
-
if (typeof schema.additionalProperties !==
|
|
574
|
+
if (typeof schema.additionalProperties !== 'boolean') {
|
|
575
575
|
if (REF_KEY in schema.additionalProperties) {
|
|
576
576
|
additionalProperties = retrieveSchema(validator, {
|
|
577
577
|
$ref: get__default["default"](schema.additionalProperties, [REF_KEY])
|
|
578
578
|
}, rootSchema, formData);
|
|
579
|
-
} else if (
|
|
579
|
+
} else if ('type' in schema.additionalProperties) {
|
|
580
580
|
additionalProperties = _extends({}, schema.additionalProperties);
|
|
581
581
|
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
582
582
|
additionalProperties = _extends({
|
|
583
|
-
type:
|
|
583
|
+
type: 'object'
|
|
584
584
|
}, schema.additionalProperties);
|
|
585
585
|
} else {
|
|
586
586
|
additionalProperties = {
|
|
@@ -617,7 +617,7 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
|
|
|
617
617
|
return {};
|
|
618
618
|
}
|
|
619
619
|
var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
|
|
620
|
-
if (
|
|
620
|
+
if ('if' in schema) {
|
|
621
621
|
return resolveCondition(validator, schema, rootSchema, rawFormData);
|
|
622
622
|
}
|
|
623
623
|
var formData = rawFormData || {};
|
|
@@ -627,7 +627,7 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
|
|
|
627
627
|
deep: false
|
|
628
628
|
});
|
|
629
629
|
} catch (e) {
|
|
630
|
-
console.warn(
|
|
630
|
+
console.warn('could not merge subschemas in allOf:\n' + e);
|
|
631
631
|
var _resolvedSchema = resolvedSchema,
|
|
632
632
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
633
633
|
return resolvedSchemaWithoutAllOf;
|
|
@@ -728,7 +728,7 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
728
728
|
}
|
|
729
729
|
// Resolve $refs inside oneOf.
|
|
730
730
|
var resolvedOneOf = oneOf.map(function (subschema) {
|
|
731
|
-
if (typeof subschema ===
|
|
731
|
+
if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
|
|
732
732
|
return subschema;
|
|
733
733
|
}
|
|
734
734
|
return resolveReference(validator, subschema, rootSchema, formData);
|
|
@@ -747,14 +747,14 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
747
747
|
*/
|
|
748
748
|
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
|
|
749
749
|
var validSubschemas = oneOf.filter(function (subschema) {
|
|
750
|
-
if (typeof subschema ===
|
|
750
|
+
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
751
751
|
return false;
|
|
752
752
|
}
|
|
753
753
|
var conditionPropertySchema = subschema.properties[dependencyKey];
|
|
754
754
|
if (conditionPropertySchema) {
|
|
755
755
|
var _properties;
|
|
756
756
|
var conditionSchema = {
|
|
757
|
-
type:
|
|
757
|
+
type: 'object',
|
|
758
758
|
properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
|
|
759
759
|
};
|
|
760
760
|
var _validator$validateFo = validator.validateFormData(formData, conditionSchema),
|
|
@@ -780,10 +780,10 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
780
780
|
* the first item
|
|
781
781
|
*/
|
|
782
782
|
var JUNK_OPTION = {
|
|
783
|
-
type:
|
|
783
|
+
type: 'object',
|
|
784
784
|
properties: {
|
|
785
785
|
__not_really_there__: {
|
|
786
|
-
type:
|
|
786
|
+
type: 'number'
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
};
|
|
@@ -816,7 +816,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
816
816
|
if (isObject__default["default"](schema.properties)) {
|
|
817
817
|
totalScore += reduce__default["default"](schema.properties, function (score, value, key) {
|
|
818
818
|
var formValue = get__default["default"](formData, key);
|
|
819
|
-
if (typeof value ===
|
|
819
|
+
if (typeof value === 'boolean') {
|
|
820
820
|
return score;
|
|
821
821
|
}
|
|
822
822
|
if (has__default["default"](value, REF_KEY)) {
|
|
@@ -826,7 +826,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
826
826
|
if (has__default["default"](value, ONE_OF_KEY) && formValue) {
|
|
827
827
|
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, ONE_OF_KEY));
|
|
828
828
|
}
|
|
829
|
-
if (value.type ===
|
|
829
|
+
if (value.type === 'object') {
|
|
830
830
|
return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
|
|
831
831
|
}
|
|
832
832
|
if (value.type === guessType(formValue)) {
|
|
@@ -986,7 +986,7 @@ function mergeObjects(obj1, obj2, concatArrays) {
|
|
|
986
986
|
acc[key] = mergeObjects(left, right, concatArrays);
|
|
987
987
|
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
988
988
|
var toMerge = right;
|
|
989
|
-
if (concatArrays ===
|
|
989
|
+
if (concatArrays === 'preventDuplicates') {
|
|
990
990
|
toMerge = right.reduce(function (result, value) {
|
|
991
991
|
if (!left.includes(value)) {
|
|
992
992
|
result.push(value);
|
|
@@ -1030,7 +1030,7 @@ function isSelect(validator, theSchema, rootSchema) {
|
|
|
1030
1030
|
}
|
|
1031
1031
|
if (Array.isArray(altSchemas)) {
|
|
1032
1032
|
return altSchemas.every(function (altSchemas) {
|
|
1033
|
-
return typeof altSchemas !==
|
|
1033
|
+
return typeof altSchemas !== 'boolean' && isConstant(altSchemas);
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
1036
|
return false;
|
|
@@ -1044,7 +1044,7 @@ function isSelect(validator, theSchema, rootSchema) {
|
|
|
1044
1044
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1045
1045
|
*/
|
|
1046
1046
|
function isMultiSelect(validator, schema, rootSchema) {
|
|
1047
|
-
if (!schema.uniqueItems || !schema.items || typeof schema.items ===
|
|
1047
|
+
if (!schema.uniqueItems || !schema.items || typeof schema.items === 'boolean') {
|
|
1048
1048
|
return false;
|
|
1049
1049
|
}
|
|
1050
1050
|
return isSelect(validator, schema.items, rootSchema);
|
|
@@ -1083,11 +1083,11 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
|
|
|
1083
1083
|
if (idx >= 0) {
|
|
1084
1084
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
1085
1085
|
var item = schema.items[idx];
|
|
1086
|
-
if (typeof item !==
|
|
1086
|
+
if (typeof item !== 'boolean') {
|
|
1087
1087
|
return item;
|
|
1088
1088
|
}
|
|
1089
1089
|
}
|
|
1090
|
-
} else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !==
|
|
1090
|
+
} else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
|
|
1091
1091
|
return schema.items;
|
|
1092
1092
|
}
|
|
1093
1093
|
if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
|
|
@@ -1179,12 +1179,12 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1179
1179
|
schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0)];
|
|
1180
1180
|
}
|
|
1181
1181
|
// Not defaults defined for this node, fallback to generic typed ones.
|
|
1182
|
-
if (typeof defaults ===
|
|
1182
|
+
if (typeof defaults === 'undefined') {
|
|
1183
1183
|
defaults = schema["default"];
|
|
1184
1184
|
}
|
|
1185
1185
|
switch (getSchemaType(schema)) {
|
|
1186
1186
|
// We need to recur for object schema inner default values.
|
|
1187
|
-
case
|
|
1187
|
+
case 'object':
|
|
1188
1188
|
{
|
|
1189
1189
|
var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
|
|
1190
1190
|
// Compute the defaults for this node, with the parent defaults we might
|
|
@@ -1204,7 +1204,7 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1204
1204
|
}
|
|
1205
1205
|
return objectDefaults;
|
|
1206
1206
|
}
|
|
1207
|
-
case
|
|
1207
|
+
case 'array':
|
|
1208
1208
|
// Inject defaults into existing array defaults
|
|
1209
1209
|
if (Array.isArray(defaults)) {
|
|
1210
1210
|
defaults = defaults.map(function (item, idx) {
|
|
@@ -1254,11 +1254,11 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1254
1254
|
includeUndefinedValues = false;
|
|
1255
1255
|
}
|
|
1256
1256
|
if (!isObject(theSchema)) {
|
|
1257
|
-
throw new Error(
|
|
1257
|
+
throw new Error('Invalid schema: ' + theSchema);
|
|
1258
1258
|
}
|
|
1259
1259
|
var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1260
1260
|
var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
|
|
1261
|
-
if (typeof formData ===
|
|
1261
|
+
if (typeof formData === 'undefined' || formData === null || typeof formData === 'number' && isNaN(formData)) {
|
|
1262
1262
|
// No form data? Use schema defaults.
|
|
1263
1263
|
return defaults;
|
|
1264
1264
|
}
|
|
@@ -1283,7 +1283,7 @@ function isCustomWidget(uiSchema) {
|
|
|
1283
1283
|
return (
|
|
1284
1284
|
// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
|
|
1285
1285
|
// https://react-jsonschema-form.readthedocs.io/en/latest/usage/widgets/#hidden-widgets
|
|
1286
|
-
|
|
1286
|
+
'widget' in getUiOptions(uiSchema) && getUiOptions(uiSchema)['widget'] !== 'hidden'
|
|
1287
1287
|
);
|
|
1288
1288
|
}
|
|
1289
1289
|
|
|
@@ -1299,12 +1299,12 @@ function isFilesArray(validator, schema, uiSchema, rootSchema) {
|
|
|
1299
1299
|
if (uiSchema === void 0) {
|
|
1300
1300
|
uiSchema = {};
|
|
1301
1301
|
}
|
|
1302
|
-
if (uiSchema[UI_WIDGET_KEY] ===
|
|
1302
|
+
if (uiSchema[UI_WIDGET_KEY] === 'files') {
|
|
1303
1303
|
return true;
|
|
1304
1304
|
}
|
|
1305
1305
|
if (schema.items) {
|
|
1306
1306
|
var itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
|
|
1307
|
-
return itemsSchema.type ===
|
|
1307
|
+
return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
|
|
1308
1308
|
}
|
|
1309
1309
|
return false;
|
|
1310
1310
|
}
|
|
@@ -1327,13 +1327,13 @@ function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
|
|
|
1327
1327
|
label = _uiOptions$label === void 0 ? true : _uiOptions$label;
|
|
1328
1328
|
var displayLabel = !!label;
|
|
1329
1329
|
var schemaType = getSchemaType(schema);
|
|
1330
|
-
if (schemaType ===
|
|
1330
|
+
if (schemaType === 'array') {
|
|
1331
1331
|
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1332
1332
|
}
|
|
1333
|
-
if (schemaType ===
|
|
1333
|
+
if (schemaType === 'object') {
|
|
1334
1334
|
displayLabel = false;
|
|
1335
1335
|
}
|
|
1336
|
-
if (schemaType ===
|
|
1336
|
+
if (schemaType === 'boolean' && !uiSchema[UI_WIDGET_KEY]) {
|
|
1337
1337
|
displayLabel = false;
|
|
1338
1338
|
}
|
|
1339
1339
|
if (uiSchema[UI_FIELD_KEY]) {
|
|
@@ -1370,7 +1370,7 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1370
1370
|
};
|
|
1371
1371
|
}
|
|
1372
1372
|
|
|
1373
|
-
var NO_VALUE = /*#__PURE__*/Symbol(
|
|
1373
|
+
var NO_VALUE = /*#__PURE__*/Symbol('no Value');
|
|
1374
1374
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
1375
1375
|
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
1376
1376
|
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
@@ -1451,8 +1451,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1451
1451
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1452
1452
|
}
|
|
1453
1453
|
// Now get types and see if they are the same
|
|
1454
|
-
var oldSchemaTypeForKey = get__default["default"](oldKeyedSchema,
|
|
1455
|
-
var newSchemaTypeForKey = get__default["default"](newKeyedSchema,
|
|
1454
|
+
var oldSchemaTypeForKey = get__default["default"](oldKeyedSchema, 'type');
|
|
1455
|
+
var newSchemaTypeForKey = get__default["default"](newKeyedSchema, 'type');
|
|
1456
1456
|
// Check if the old option has the same key with the same type
|
|
1457
1457
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1458
1458
|
if (has__default["default"](removeOldSchemaData, key)) {
|
|
@@ -1460,10 +1460,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1460
1460
|
delete removeOldSchemaData[key];
|
|
1461
1461
|
}
|
|
1462
1462
|
// If it is an object, we'll recurse and store the resulting sanitized data for the key
|
|
1463
|
-
if (newSchemaTypeForKey ===
|
|
1463
|
+
if (newSchemaTypeForKey === 'object' || newSchemaTypeForKey === 'array' && Array.isArray(formValue)) {
|
|
1464
1464
|
// SIDE-EFFECT: process the new schema type of object recursively to save iterations
|
|
1465
1465
|
var itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
|
|
1466
|
-
if (itemData !== undefined || newSchemaTypeForKey ===
|
|
1466
|
+
if (itemData !== undefined || newSchemaTypeForKey === 'array') {
|
|
1467
1467
|
// only put undefined values for the array type and not the object type
|
|
1468
1468
|
nestedData[key] = itemData;
|
|
1469
1469
|
}
|
|
@@ -1471,19 +1471,19 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1471
1471
|
// Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
|
|
1472
1472
|
// with the new default or const. This allows the case where two schemas differ that only by the default/const
|
|
1473
1473
|
// value to be properly selected
|
|
1474
|
-
var newOptionDefault = get__default["default"](newKeyedSchema,
|
|
1475
|
-
var oldOptionDefault = get__default["default"](oldKeyedSchema,
|
|
1474
|
+
var newOptionDefault = get__default["default"](newKeyedSchema, 'default', NO_VALUE);
|
|
1475
|
+
var oldOptionDefault = get__default["default"](oldKeyedSchema, 'default', NO_VALUE);
|
|
1476
1476
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1477
1477
|
if (oldOptionDefault === formValue) {
|
|
1478
1478
|
// If the old default matches the formValue, we'll update the new value to match the new default
|
|
1479
1479
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1480
|
-
} else if (get__default["default"](newKeyedSchema,
|
|
1480
|
+
} else if (get__default["default"](newKeyedSchema, 'readOnly') === true) {
|
|
1481
1481
|
// If the new schema has the default set to read-only, treat it like a const and remove the value
|
|
1482
1482
|
removeOldSchemaData[key] = undefined;
|
|
1483
1483
|
}
|
|
1484
1484
|
}
|
|
1485
|
-
var newOptionConst = get__default["default"](newKeyedSchema,
|
|
1486
|
-
var oldOptionConst = get__default["default"](oldKeyedSchema,
|
|
1485
|
+
var newOptionConst = get__default["default"](newKeyedSchema, 'const', NO_VALUE);
|
|
1486
|
+
var oldOptionConst = get__default["default"](oldKeyedSchema, 'const', NO_VALUE);
|
|
1487
1487
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1488
1488
|
// Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
|
|
1489
1489
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
|
|
@@ -1493,12 +1493,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1493
1493
|
});
|
|
1494
1494
|
newFormData = _extends({}, data, removeOldSchemaData, nestedData);
|
|
1495
1495
|
// First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
|
|
1496
|
-
} else if (get__default["default"](oldSchema,
|
|
1497
|
-
var oldSchemaItems = get__default["default"](oldSchema,
|
|
1498
|
-
var newSchemaItems = get__default["default"](newSchema,
|
|
1496
|
+
} else if (get__default["default"](oldSchema, 'type') === 'array' && get__default["default"](newSchema, 'type') === 'array' && Array.isArray(data)) {
|
|
1497
|
+
var oldSchemaItems = get__default["default"](oldSchema, 'items');
|
|
1498
|
+
var newSchemaItems = get__default["default"](newSchema, 'items');
|
|
1499
1499
|
// If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
|
|
1500
1500
|
// Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
|
|
1501
|
-
if (typeof oldSchemaItems ===
|
|
1501
|
+
if (typeof oldSchemaItems === 'object' && typeof newSchemaItems === 'object' && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1502
1502
|
if (has__default["default"](oldSchemaItems, REF_KEY)) {
|
|
1503
1503
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
1504
1504
|
}
|
|
@@ -1506,12 +1506,12 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1506
1506
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1507
1507
|
}
|
|
1508
1508
|
// Now get types and see if they are the same
|
|
1509
|
-
var oldSchemaType = get__default["default"](oldSchemaItems,
|
|
1510
|
-
var newSchemaType = get__default["default"](newSchemaItems,
|
|
1509
|
+
var oldSchemaType = get__default["default"](oldSchemaItems, 'type');
|
|
1510
|
+
var newSchemaType = get__default["default"](newSchemaItems, 'type');
|
|
1511
1511
|
// Check if the old option has the same key with the same type
|
|
1512
1512
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1513
|
-
var maxItems = get__default["default"](newSchema,
|
|
1514
|
-
if (newSchemaType ===
|
|
1513
|
+
var maxItems = get__default["default"](newSchema, 'maxItems', -1);
|
|
1514
|
+
if (newSchemaType === 'object') {
|
|
1515
1515
|
newFormData = data.reduce(function (newValue, aValue) {
|
|
1516
1516
|
var itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
|
|
1517
1517
|
if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
|
|
@@ -1523,7 +1523,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1523
1523
|
newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
|
|
1524
1524
|
}
|
|
1525
1525
|
}
|
|
1526
|
-
} else if (typeof oldSchemaItems ===
|
|
1526
|
+
} else if (typeof oldSchemaItems === 'boolean' && typeof newSchemaItems === 'boolean' && oldSchemaItems === newSchemaItems) {
|
|
1527
1527
|
// If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined
|
|
1528
1528
|
newFormData = data;
|
|
1529
1529
|
}
|
|
@@ -1546,10 +1546,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1546
1546
|
*/
|
|
1547
1547
|
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
|
|
1548
1548
|
if (idPrefix === void 0) {
|
|
1549
|
-
idPrefix =
|
|
1549
|
+
idPrefix = 'root';
|
|
1550
1550
|
}
|
|
1551
1551
|
if (idSeparator === void 0) {
|
|
1552
|
-
idSeparator =
|
|
1552
|
+
idSeparator = '_';
|
|
1553
1553
|
}
|
|
1554
1554
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1555
1555
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
@@ -1562,7 +1562,7 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSep
|
|
|
1562
1562
|
var idSchema = {
|
|
1563
1563
|
$id: $id
|
|
1564
1564
|
};
|
|
1565
|
-
if (schema.type ===
|
|
1565
|
+
if (schema.type === 'object' && PROPERTIES_KEY in schema) {
|
|
1566
1566
|
for (var name in schema.properties) {
|
|
1567
1567
|
var field = get__default["default"](schema, [PROPERTIES_KEY, name]);
|
|
1568
1568
|
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
@@ -1587,13 +1587,13 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSep
|
|
|
1587
1587
|
function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
1588
1588
|
var _pathSchema;
|
|
1589
1589
|
if (name === void 0) {
|
|
1590
|
-
name =
|
|
1590
|
+
name = '';
|
|
1591
1591
|
}
|
|
1592
1592
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1593
1593
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1594
1594
|
return toPathSchema(validator, _schema, name, rootSchema, formData);
|
|
1595
1595
|
}
|
|
1596
|
-
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./,
|
|
1596
|
+
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ''), _pathSchema);
|
|
1597
1597
|
if (ONE_OF_KEY in schema) {
|
|
1598
1598
|
var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
|
|
1599
1599
|
var _schema2 = schema.oneOf[index];
|
|
@@ -1796,10 +1796,10 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
1796
1796
|
*/;
|
|
1797
1797
|
_proto.toIdSchema = function toIdSchema$1(schema, id, formData, idPrefix, idSeparator) {
|
|
1798
1798
|
if (idPrefix === void 0) {
|
|
1799
|
-
idPrefix =
|
|
1799
|
+
idPrefix = 'root';
|
|
1800
1800
|
}
|
|
1801
1801
|
if (idSeparator === void 0) {
|
|
1802
|
-
idSeparator =
|
|
1802
|
+
idSeparator = '_';
|
|
1803
1803
|
}
|
|
1804
1804
|
return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
|
|
1805
1805
|
}
|
|
@@ -1834,38 +1834,48 @@ function createSchemaUtils(validator, rootSchema) {
|
|
|
1834
1834
|
*/
|
|
1835
1835
|
function dataURItoBlob(dataURI) {
|
|
1836
1836
|
// Split metadata from data
|
|
1837
|
-
var splitted = dataURI.split(
|
|
1837
|
+
var splitted = dataURI.split(',');
|
|
1838
1838
|
// Split params
|
|
1839
|
-
var params = splitted[0].split(
|
|
1839
|
+
var params = splitted[0].split(';');
|
|
1840
1840
|
// Get mime-type from params
|
|
1841
|
-
var type = params[0].replace(
|
|
1841
|
+
var type = params[0].replace('data:', '');
|
|
1842
1842
|
// Filter the name property from params
|
|
1843
1843
|
var properties = params.filter(function (param) {
|
|
1844
|
-
return param.split(
|
|
1844
|
+
return param.split('=')[0] === 'name';
|
|
1845
1845
|
});
|
|
1846
1846
|
// Look for the name and use unknown if no name property.
|
|
1847
1847
|
var name;
|
|
1848
1848
|
if (properties.length !== 1) {
|
|
1849
|
-
name =
|
|
1849
|
+
name = 'unknown';
|
|
1850
1850
|
} else {
|
|
1851
1851
|
// Because we filtered out the other property,
|
|
1852
|
-
// we only have the name case here
|
|
1853
|
-
name = properties[0].split(
|
|
1852
|
+
// we only have the name case here, which we decode to make it human-readable
|
|
1853
|
+
name = decodeURI(properties[0].split('=')[1]);
|
|
1854
1854
|
}
|
|
1855
1855
|
// Built the Uint8Array Blob parameter from the base64 string.
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1856
|
+
try {
|
|
1857
|
+
var binary = atob(splitted[1]);
|
|
1858
|
+
var array = [];
|
|
1859
|
+
for (var i = 0; i < binary.length; i++) {
|
|
1860
|
+
array.push(binary.charCodeAt(i));
|
|
1861
|
+
}
|
|
1862
|
+
// Create the blob object
|
|
1863
|
+
var blob = new window.Blob([new Uint8Array(array)], {
|
|
1864
|
+
type: type
|
|
1865
|
+
});
|
|
1866
|
+
return {
|
|
1867
|
+
blob: blob,
|
|
1868
|
+
name: name
|
|
1869
|
+
};
|
|
1870
|
+
} catch (error) {
|
|
1871
|
+
return {
|
|
1872
|
+
blob: {
|
|
1873
|
+
size: 0,
|
|
1874
|
+
type: error.message
|
|
1875
|
+
},
|
|
1876
|
+
name: dataURI
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1869
1879
|
}
|
|
1870
1880
|
|
|
1871
1881
|
/** Potentially substitutes all replaceable parameters with the associated value(s) from the `params` if available. When
|
|
@@ -1879,9 +1889,16 @@ function dataURItoBlob(dataURI) {
|
|
|
1879
1889
|
function replaceStringParameters(inputString, params) {
|
|
1880
1890
|
var output = inputString;
|
|
1881
1891
|
if (Array.isArray(params)) {
|
|
1892
|
+
var parts = output.split(/(%\d)/);
|
|
1882
1893
|
params.forEach(function (param, index) {
|
|
1883
|
-
|
|
1894
|
+
var partIndex = parts.findIndex(function (part) {
|
|
1895
|
+
return part === "%" + (index + 1);
|
|
1896
|
+
});
|
|
1897
|
+
if (partIndex >= 0) {
|
|
1898
|
+
parts[partIndex] = param;
|
|
1899
|
+
}
|
|
1884
1900
|
});
|
|
1901
|
+
output = parts.join('');
|
|
1885
1902
|
}
|
|
1886
1903
|
return output;
|
|
1887
1904
|
}
|
|
@@ -1921,7 +1938,7 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions, emptyValue) {
|
|
|
1921
1938
|
});
|
|
1922
1939
|
}
|
|
1923
1940
|
// So Number(null) and Number('') both return 0, so use emptyValue for those two values
|
|
1924
|
-
var index = valueIndex ===
|
|
1941
|
+
var index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
|
|
1925
1942
|
var option = allEnumOptions[index];
|
|
1926
1943
|
return option ? option.value : emptyValue;
|
|
1927
1944
|
}
|
|
@@ -1987,7 +2004,7 @@ function enumOptionsIndexForValue(value, allEnumOptions, multiple) {
|
|
|
1987
2004
|
var selectedIndexes = allEnumOptions.map(function (opt, index) {
|
|
1988
2005
|
return enumOptionsIsSelected(opt.value, value) ? String(index) : undefined;
|
|
1989
2006
|
}).filter(function (opt) {
|
|
1990
|
-
return typeof opt !==
|
|
2007
|
+
return typeof opt !== 'undefined';
|
|
1991
2008
|
});
|
|
1992
2009
|
if (!multiple) {
|
|
1993
2010
|
return selectedIndexes[0];
|
|
@@ -2055,7 +2072,7 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2055
2072
|
* @private
|
|
2056
2073
|
*/
|
|
2057
2074
|
_proto.getOrCreateErrorBlock = function getOrCreateErrorBlock(pathOfError) {
|
|
2058
|
-
var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError ===
|
|
2075
|
+
var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === 'string';
|
|
2059
2076
|
var errorBlock = hasPath ? get__default["default"](this.errorSchema, pathOfError) : this.errorSchema;
|
|
2060
2077
|
if (!errorBlock && pathOfError) {
|
|
2061
2078
|
errorBlock = {};
|
|
@@ -2167,23 +2184,23 @@ function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
|
|
|
2167
2184
|
autoDefaultStepAny = true;
|
|
2168
2185
|
}
|
|
2169
2186
|
var inputProps = _extends({
|
|
2170
|
-
type: defaultType ||
|
|
2187
|
+
type: defaultType || 'text'
|
|
2171
2188
|
}, rangeSpec(schema));
|
|
2172
2189
|
// If options.inputType is set use that as the input type
|
|
2173
2190
|
if (options.inputType) {
|
|
2174
2191
|
inputProps.type = options.inputType;
|
|
2175
2192
|
} else if (!defaultType) {
|
|
2176
2193
|
// If the schema is of type number or integer, set the input type to number
|
|
2177
|
-
if (schema.type ===
|
|
2178
|
-
inputProps.type =
|
|
2194
|
+
if (schema.type === 'number') {
|
|
2195
|
+
inputProps.type = 'number';
|
|
2179
2196
|
// Only add step if one isn't already defined and we are auto-defaulting the "any" step
|
|
2180
2197
|
if (autoDefaultStepAny && inputProps.step === undefined) {
|
|
2181
2198
|
// Setting step to 'any' fixes a bug in Safari where decimals are not
|
|
2182
2199
|
// allowed in number inputs
|
|
2183
|
-
inputProps.step =
|
|
2200
|
+
inputProps.step = 'any';
|
|
2184
2201
|
}
|
|
2185
|
-
} else if (schema.type ===
|
|
2186
|
-
inputProps.type =
|
|
2202
|
+
} else if (schema.type === 'integer') {
|
|
2203
|
+
inputProps.type = 'number';
|
|
2187
2204
|
// Only add step if one isn't already defined
|
|
2188
2205
|
if (inputProps.step === undefined) {
|
|
2189
2206
|
// Since this is integer, you always want to step up or down in multiples of 1
|
|
@@ -2203,7 +2220,7 @@ var DEFAULT_OPTIONS = {
|
|
|
2203
2220
|
props: {
|
|
2204
2221
|
disabled: false
|
|
2205
2222
|
},
|
|
2206
|
-
submitText:
|
|
2223
|
+
submitText: 'Submit',
|
|
2207
2224
|
norender: false
|
|
2208
2225
|
};
|
|
2209
2226
|
/** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
|
|
@@ -2236,7 +2253,7 @@ function getTemplate(name, registry, uiOptions) {
|
|
|
2236
2253
|
uiOptions = {};
|
|
2237
2254
|
}
|
|
2238
2255
|
var templates = registry.templates;
|
|
2239
|
-
if (name ===
|
|
2256
|
+
if (name === 'ButtonTemplates') {
|
|
2240
2257
|
return templates[name];
|
|
2241
2258
|
}
|
|
2242
2259
|
return (
|
|
@@ -2251,53 +2268,53 @@ var _excluded = ["options"];
|
|
|
2251
2268
|
*/
|
|
2252
2269
|
var widgetMap = {
|
|
2253
2270
|
"boolean": {
|
|
2254
|
-
checkbox:
|
|
2255
|
-
radio:
|
|
2256
|
-
select:
|
|
2257
|
-
hidden:
|
|
2271
|
+
checkbox: 'CheckboxWidget',
|
|
2272
|
+
radio: 'RadioWidget',
|
|
2273
|
+
select: 'SelectWidget',
|
|
2274
|
+
hidden: 'HiddenWidget'
|
|
2258
2275
|
},
|
|
2259
2276
|
string: {
|
|
2260
|
-
text:
|
|
2261
|
-
password:
|
|
2262
|
-
email:
|
|
2263
|
-
hostname:
|
|
2264
|
-
ipv4:
|
|
2265
|
-
ipv6:
|
|
2266
|
-
uri:
|
|
2267
|
-
|
|
2268
|
-
radio:
|
|
2269
|
-
select:
|
|
2270
|
-
textarea:
|
|
2271
|
-
hidden:
|
|
2272
|
-
date:
|
|
2273
|
-
datetime:
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
color:
|
|
2278
|
-
file:
|
|
2277
|
+
text: 'TextWidget',
|
|
2278
|
+
password: 'PasswordWidget',
|
|
2279
|
+
email: 'EmailWidget',
|
|
2280
|
+
hostname: 'TextWidget',
|
|
2281
|
+
ipv4: 'TextWidget',
|
|
2282
|
+
ipv6: 'TextWidget',
|
|
2283
|
+
uri: 'URLWidget',
|
|
2284
|
+
'data-url': 'FileWidget',
|
|
2285
|
+
radio: 'RadioWidget',
|
|
2286
|
+
select: 'SelectWidget',
|
|
2287
|
+
textarea: 'TextareaWidget',
|
|
2288
|
+
hidden: 'HiddenWidget',
|
|
2289
|
+
date: 'DateWidget',
|
|
2290
|
+
datetime: 'DateTimeWidget',
|
|
2291
|
+
'date-time': 'DateTimeWidget',
|
|
2292
|
+
'alt-date': 'AltDateWidget',
|
|
2293
|
+
'alt-datetime': 'AltDateTimeWidget',
|
|
2294
|
+
color: 'ColorWidget',
|
|
2295
|
+
file: 'FileWidget'
|
|
2279
2296
|
},
|
|
2280
2297
|
number: {
|
|
2281
|
-
text:
|
|
2282
|
-
select:
|
|
2283
|
-
updown:
|
|
2284
|
-
range:
|
|
2285
|
-
radio:
|
|
2286
|
-
hidden:
|
|
2298
|
+
text: 'TextWidget',
|
|
2299
|
+
select: 'SelectWidget',
|
|
2300
|
+
updown: 'UpDownWidget',
|
|
2301
|
+
range: 'RangeWidget',
|
|
2302
|
+
radio: 'RadioWidget',
|
|
2303
|
+
hidden: 'HiddenWidget'
|
|
2287
2304
|
},
|
|
2288
2305
|
integer: {
|
|
2289
|
-
text:
|
|
2290
|
-
select:
|
|
2291
|
-
updown:
|
|
2292
|
-
range:
|
|
2293
|
-
radio:
|
|
2294
|
-
hidden:
|
|
2306
|
+
text: 'TextWidget',
|
|
2307
|
+
select: 'SelectWidget',
|
|
2308
|
+
updown: 'UpDownWidget',
|
|
2309
|
+
range: 'RangeWidget',
|
|
2310
|
+
radio: 'RadioWidget',
|
|
2311
|
+
hidden: 'HiddenWidget'
|
|
2295
2312
|
},
|
|
2296
2313
|
array: {
|
|
2297
|
-
select:
|
|
2298
|
-
checkboxes:
|
|
2299
|
-
files:
|
|
2300
|
-
hidden:
|
|
2314
|
+
select: 'SelectWidget',
|
|
2315
|
+
checkboxes: 'CheckboxesWidget',
|
|
2316
|
+
files: 'FileWidget',
|
|
2317
|
+
hidden: 'HiddenWidget'
|
|
2301
2318
|
}
|
|
2302
2319
|
};
|
|
2303
2320
|
/** Wraps the given widget with stateless functional component that will merge any `defaultProps.options` with the
|
|
@@ -2308,18 +2325,18 @@ var widgetMap = {
|
|
|
2308
2325
|
* @returns - The wrapper widget
|
|
2309
2326
|
*/
|
|
2310
2327
|
function mergeWidgetOptions(AWidget) {
|
|
2311
|
-
var MergedWidget = get__default["default"](AWidget,
|
|
2328
|
+
var MergedWidget = get__default["default"](AWidget, 'MergedWidget');
|
|
2312
2329
|
// cache return value as property of widget for proper react reconciliation
|
|
2313
2330
|
if (!MergedWidget) {
|
|
2314
2331
|
var defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2315
2332
|
MergedWidget = function MergedWidget(_ref) {
|
|
2316
2333
|
var options = _ref.options,
|
|
2317
2334
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
2318
|
-
return
|
|
2335
|
+
return jsxRuntime.jsx(AWidget, _extends({
|
|
2319
2336
|
options: _extends({}, defaultOptions, options)
|
|
2320
2337
|
}, props));
|
|
2321
2338
|
};
|
|
2322
|
-
set__default["default"](AWidget,
|
|
2339
|
+
set__default["default"](AWidget, 'MergedWidget', MergedWidget);
|
|
2323
2340
|
}
|
|
2324
2341
|
return MergedWidget;
|
|
2325
2342
|
}
|
|
@@ -2339,17 +2356,17 @@ function getWidget(schema, widget, registeredWidgets) {
|
|
|
2339
2356
|
registeredWidgets = {};
|
|
2340
2357
|
}
|
|
2341
2358
|
var type = getSchemaType(schema);
|
|
2342
|
-
if (typeof widget ===
|
|
2359
|
+
if (typeof widget === 'function' || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/react.createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
|
|
2343
2360
|
return mergeWidgetOptions(widget);
|
|
2344
2361
|
}
|
|
2345
|
-
if (typeof widget !==
|
|
2362
|
+
if (typeof widget !== 'string') {
|
|
2346
2363
|
throw new Error("Unsupported widget definition: " + typeof widget);
|
|
2347
2364
|
}
|
|
2348
2365
|
if (widget in registeredWidgets) {
|
|
2349
2366
|
var registeredWidget = registeredWidgets[widget];
|
|
2350
2367
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2351
2368
|
}
|
|
2352
|
-
if (typeof type ===
|
|
2369
|
+
if (typeof type === 'string') {
|
|
2353
2370
|
if (!(type in widgetMap)) {
|
|
2354
2371
|
throw new Error("No widget for type '" + type + "'");
|
|
2355
2372
|
}
|
|
@@ -2378,7 +2395,7 @@ function hasWidget(schema, widget, registeredWidgets) {
|
|
|
2378
2395
|
return true;
|
|
2379
2396
|
} catch (e) {
|
|
2380
2397
|
var err = e;
|
|
2381
|
-
if (err.message && (err.message.startsWith(
|
|
2398
|
+
if (err.message && (err.message.startsWith('No widget') || err.message.startsWith('Unsupported widget'))) {
|
|
2382
2399
|
return false;
|
|
2383
2400
|
}
|
|
2384
2401
|
throw e;
|
|
@@ -2400,7 +2417,7 @@ function idGenerator(id, suffix) {
|
|
|
2400
2417
|
* @returns - The consistent id for the field description element from the given `id`
|
|
2401
2418
|
*/
|
|
2402
2419
|
function descriptionId(id) {
|
|
2403
|
-
return idGenerator(id,
|
|
2420
|
+
return idGenerator(id, 'description');
|
|
2404
2421
|
}
|
|
2405
2422
|
/** Return a consistent `id` for the field error element
|
|
2406
2423
|
*
|
|
@@ -2408,7 +2425,7 @@ function descriptionId(id) {
|
|
|
2408
2425
|
* @returns - The consistent id for the field error element from the given `id`
|
|
2409
2426
|
*/
|
|
2410
2427
|
function errorId(id) {
|
|
2411
|
-
return idGenerator(id,
|
|
2428
|
+
return idGenerator(id, 'error');
|
|
2412
2429
|
}
|
|
2413
2430
|
/** Return a consistent `id` for the field examples element
|
|
2414
2431
|
*
|
|
@@ -2416,7 +2433,7 @@ function errorId(id) {
|
|
|
2416
2433
|
* @returns - The consistent id for the field examples element from the given `id`
|
|
2417
2434
|
*/
|
|
2418
2435
|
function examplesId(id) {
|
|
2419
|
-
return idGenerator(id,
|
|
2436
|
+
return idGenerator(id, 'examples');
|
|
2420
2437
|
}
|
|
2421
2438
|
/** Return a consistent `id` for the field help element
|
|
2422
2439
|
*
|
|
@@ -2424,7 +2441,7 @@ function examplesId(id) {
|
|
|
2424
2441
|
* @returns - The consistent id for the field help element from the given `id`
|
|
2425
2442
|
*/
|
|
2426
2443
|
function helpId(id) {
|
|
2427
|
-
return idGenerator(id,
|
|
2444
|
+
return idGenerator(id, 'help');
|
|
2428
2445
|
}
|
|
2429
2446
|
/** Return a consistent `id` for the field title element
|
|
2430
2447
|
*
|
|
@@ -2432,7 +2449,7 @@ function helpId(id) {
|
|
|
2432
2449
|
* @returns - The consistent id for the field title element from the given `id`
|
|
2433
2450
|
*/
|
|
2434
2451
|
function titleId(id) {
|
|
2435
|
-
return idGenerator(id,
|
|
2452
|
+
return idGenerator(id, 'title');
|
|
2436
2453
|
}
|
|
2437
2454
|
/** Return a list of element ids that contain additional information about the field that can be used to as the aria
|
|
2438
2455
|
* description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
|
|
@@ -2446,7 +2463,7 @@ function ariaDescribedByIds(id, includeExamples) {
|
|
|
2446
2463
|
if (includeExamples === void 0) {
|
|
2447
2464
|
includeExamples = false;
|
|
2448
2465
|
}
|
|
2449
|
-
var examples = includeExamples ? " " + examplesId(id) :
|
|
2466
|
+
var examples = includeExamples ? " " + examplesId(id) : '';
|
|
2450
2467
|
return errorId(id) + " " + descriptionId(id) + " " + helpId(id) + examples;
|
|
2451
2468
|
}
|
|
2452
2469
|
/** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
|
|
@@ -2482,7 +2499,7 @@ function toConstant(schema) {
|
|
|
2482
2499
|
if (CONST_KEY in schema) {
|
|
2483
2500
|
return schema["const"];
|
|
2484
2501
|
}
|
|
2485
|
-
throw new Error(
|
|
2502
|
+
throw new Error('schema cannot be inferred as a constant');
|
|
2486
2503
|
}
|
|
2487
2504
|
|
|
2488
2505
|
/** Gets the list of options from the schema. If the schema has an enum list, then those enum values are returned. The
|
|
@@ -2497,8 +2514,8 @@ function optionsList(schema) {
|
|
|
2497
2514
|
// enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
|
|
2498
2515
|
// Cast the type to include enumNames so the feature still works.
|
|
2499
2516
|
var schemaWithEnumNames = schema;
|
|
2500
|
-
if (schemaWithEnumNames.enumNames && "development" !==
|
|
2501
|
-
console.warn(
|
|
2517
|
+
if (schemaWithEnumNames.enumNames && "development" !== 'production') {
|
|
2518
|
+
console.warn('The enumNames property is deprecated and may be removed in a future major release.');
|
|
2502
2519
|
}
|
|
2503
2520
|
if (schema["enum"]) {
|
|
2504
2521
|
return schema["enum"].map(function (value, i) {
|
|
@@ -2547,21 +2564,21 @@ function orderProperties(properties, order) {
|
|
|
2547
2564
|
};
|
|
2548
2565
|
var propertyHash = arrayToHash(properties);
|
|
2549
2566
|
var orderFiltered = order.filter(function (prop) {
|
|
2550
|
-
return prop ===
|
|
2567
|
+
return prop === '*' || propertyHash[prop];
|
|
2551
2568
|
});
|
|
2552
2569
|
var orderHash = arrayToHash(orderFiltered);
|
|
2553
2570
|
var rest = properties.filter(function (prop) {
|
|
2554
2571
|
return !orderHash[prop];
|
|
2555
2572
|
});
|
|
2556
|
-
var restIndex = orderFiltered.indexOf(
|
|
2573
|
+
var restIndex = orderFiltered.indexOf('*');
|
|
2557
2574
|
if (restIndex === -1) {
|
|
2558
2575
|
if (rest.length) {
|
|
2559
2576
|
throw new Error("uiSchema order list does not contain " + errorPropList(rest));
|
|
2560
2577
|
}
|
|
2561
2578
|
return orderFiltered;
|
|
2562
2579
|
}
|
|
2563
|
-
if (restIndex !== orderFiltered.lastIndexOf(
|
|
2564
|
-
throw new Error(
|
|
2580
|
+
if (restIndex !== orderFiltered.lastIndexOf('*')) {
|
|
2581
|
+
throw new Error('uiSchema order list contains more than one wildcard item');
|
|
2565
2582
|
}
|
|
2566
2583
|
var complete = [].concat(orderFiltered);
|
|
2567
2584
|
complete.splice.apply(complete, [restIndex, 1].concat(rest));
|
|
@@ -2577,7 +2594,7 @@ function orderProperties(properties, order) {
|
|
|
2577
2594
|
function pad(num, width) {
|
|
2578
2595
|
var s = String(num);
|
|
2579
2596
|
while (s.length < width) {
|
|
2580
|
-
s =
|
|
2597
|
+
s = '0' + s;
|
|
2581
2598
|
}
|
|
2582
2599
|
return s;
|
|
2583
2600
|
}
|
|
@@ -2605,7 +2622,7 @@ function parseDateString(dateString, includeTime) {
|
|
|
2605
2622
|
}
|
|
2606
2623
|
var date = new Date(dateString);
|
|
2607
2624
|
if (Number.isNaN(date.getTime())) {
|
|
2608
|
-
throw new Error(
|
|
2625
|
+
throw new Error('Unable to parse date ' + dateString);
|
|
2609
2626
|
}
|
|
2610
2627
|
return {
|
|
2611
2628
|
year: date.getUTCFullYear(),
|
|
@@ -2699,7 +2716,7 @@ function toDateString(dateObject, time) {
|
|
|
2699
2716
|
*/
|
|
2700
2717
|
function utcToLocal(jsonDate) {
|
|
2701
2718
|
if (!jsonDate) {
|
|
2702
|
-
return
|
|
2719
|
+
return '';
|
|
2703
2720
|
}
|
|
2704
2721
|
// required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
|
|
2705
2722
|
// https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
|