@rjsf/utils 5.2.0 → 5.3.0
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 +126 -79
- package/dist/utils.cjs.development.js +238 -208
- 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 +238 -208
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +240 -211
- 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 +7 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/has'), require('lodash-es/isObject'), require('lodash-es/isString'), require('lodash-es/reduce'), require('lodash-es/times'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEqual'), require('lodash-es/cloneDeep'), require('react'), require('react-is')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/isObject', 'lodash-es/isString', 'lodash-es/reduce', 'lodash-es/times', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEqual', 'lodash-es/cloneDeep', 'react', 'react-is'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.has, global.isObject$1, global.isString, global.reduce, global.times, global.set, global.mergeAllOf, global.union, global.isEqual, global.cloneDeep, global.React, global.ReactIs));
|
|
5
|
-
})(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, has, isObject$1, isString, reduce, times, set, mergeAllOf, union, isEqual, cloneDeep,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/isEqualWith'), require('lodash-es/get'), require('lodash-es/isEmpty'), require('jsonpointer'), require('lodash-es/omit'), require('lodash-es/has'), require('lodash-es/isObject'), require('lodash-es/isString'), require('lodash-es/reduce'), require('lodash-es/times'), require('lodash-es/set'), require('json-schema-merge-allof'), require('lodash-es/union'), require('lodash-es/isEqual'), require('lodash-es/cloneDeep'), require('react/jsx-runtime'), require('react'), require('react-is')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/isEqualWith', 'lodash-es/get', 'lodash-es/isEmpty', 'jsonpointer', 'lodash-es/omit', 'lodash-es/has', 'lodash-es/isObject', 'lodash-es/isString', 'lodash-es/reduce', 'lodash-es/times', 'lodash-es/set', 'json-schema-merge-allof', 'lodash-es/union', 'lodash-es/isEqual', 'lodash-es/cloneDeep', 'react/jsx-runtime', 'react', 'react-is'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isEqualWith, global.get, global.isEmpty, global.jsonpointer, global.omit, global.has, global.isObject$1, global.isString, global.reduce, global.times, global.set, global.mergeAllOf, global.union, global.isEqual, global.cloneDeep, global.jsxRuntime, global.React, global.ReactIs));
|
|
5
|
+
})(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, has, isObject$1, isString, reduce, times, set, mergeAllOf, union, isEqual, cloneDeep, jsxRuntime, react, ReactIs) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
|
|
22
22
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
23
23
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
24
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
25
24
|
var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
26
25
|
|
|
27
26
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
@@ -31,13 +30,13 @@
|
|
|
31
30
|
* @returns - True if it is a non-null, non-array, non-File object
|
|
32
31
|
*/
|
|
33
32
|
function isObject(thing) {
|
|
34
|
-
if (typeof File !==
|
|
33
|
+
if (typeof File !== 'undefined' && thing instanceof File) {
|
|
35
34
|
return false;
|
|
36
35
|
}
|
|
37
|
-
if (typeof Date !==
|
|
36
|
+
if (typeof Date !== 'undefined' && thing instanceof Date) {
|
|
38
37
|
return false;
|
|
39
38
|
}
|
|
40
|
-
return typeof thing ===
|
|
39
|
+
return typeof thing === 'object' && thing !== null && !Array.isArray(thing);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
/** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
*/
|
|
49
48
|
function allowAdditionalItems(schema) {
|
|
50
49
|
if (schema.additionalItems === true) {
|
|
51
|
-
console.warn(
|
|
50
|
+
console.warn('additionalItems=true is currently not supported');
|
|
52
51
|
}
|
|
53
52
|
return isObject(schema.additionalItems);
|
|
54
53
|
}
|
|
@@ -63,7 +62,7 @@
|
|
|
63
62
|
* @returns - The `value` converted to a number when appropriate, otherwise the `value`
|
|
64
63
|
*/
|
|
65
64
|
function asNumber(value) {
|
|
66
|
-
if (value ===
|
|
65
|
+
if (value === '') {
|
|
67
66
|
return undefined;
|
|
68
67
|
}
|
|
69
68
|
if (value === null) {
|
|
@@ -85,7 +84,7 @@
|
|
|
85
84
|
return value;
|
|
86
85
|
}
|
|
87
86
|
var n = Number(value);
|
|
88
|
-
var valid = typeof n ===
|
|
87
|
+
var valid = typeof n === 'number' && !Number.isNaN(n);
|
|
89
88
|
return valid ? n : value;
|
|
90
89
|
}
|
|
91
90
|
|
|
@@ -155,53 +154,58 @@
|
|
|
155
154
|
* `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
|
|
156
155
|
* utility.
|
|
157
156
|
*/
|
|
158
|
-
var ADDITIONAL_PROPERTY_FLAG =
|
|
159
|
-
var ADDITIONAL_PROPERTIES_KEY =
|
|
160
|
-
var ALL_OF_KEY =
|
|
161
|
-
var ANY_OF_KEY =
|
|
162
|
-
var CONST_KEY =
|
|
163
|
-
var DEFAULT_KEY =
|
|
164
|
-
var DEFINITIONS_KEY =
|
|
165
|
-
var DEPENDENCIES_KEY =
|
|
166
|
-
var ENUM_KEY =
|
|
167
|
-
var ERRORS_KEY =
|
|
168
|
-
var ID_KEY =
|
|
169
|
-
var ITEMS_KEY =
|
|
170
|
-
var NAME_KEY =
|
|
171
|
-
var ONE_OF_KEY =
|
|
172
|
-
var PROPERTIES_KEY =
|
|
173
|
-
var REQUIRED_KEY =
|
|
174
|
-
var SUBMIT_BTN_OPTIONS_KEY =
|
|
175
|
-
var REF_KEY =
|
|
176
|
-
var RJSF_ADDITONAL_PROPERTIES_FLAG =
|
|
177
|
-
var UI_FIELD_KEY =
|
|
178
|
-
var UI_WIDGET_KEY =
|
|
179
|
-
var UI_OPTIONS_KEY =
|
|
157
|
+
var ADDITIONAL_PROPERTY_FLAG = '__additional_property';
|
|
158
|
+
var ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
|
|
159
|
+
var ALL_OF_KEY = 'allOf';
|
|
160
|
+
var ANY_OF_KEY = 'anyOf';
|
|
161
|
+
var CONST_KEY = 'const';
|
|
162
|
+
var DEFAULT_KEY = 'default';
|
|
163
|
+
var DEFINITIONS_KEY = 'definitions';
|
|
164
|
+
var DEPENDENCIES_KEY = 'dependencies';
|
|
165
|
+
var ENUM_KEY = 'enum';
|
|
166
|
+
var ERRORS_KEY = '__errors';
|
|
167
|
+
var ID_KEY = '$id';
|
|
168
|
+
var ITEMS_KEY = 'items';
|
|
169
|
+
var NAME_KEY = '$name';
|
|
170
|
+
var ONE_OF_KEY = 'oneOf';
|
|
171
|
+
var PROPERTIES_KEY = 'properties';
|
|
172
|
+
var REQUIRED_KEY = 'required';
|
|
173
|
+
var SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
174
|
+
var REF_KEY = '$ref';
|
|
175
|
+
var RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
|
|
176
|
+
var UI_FIELD_KEY = 'ui:field';
|
|
177
|
+
var UI_WIDGET_KEY = 'ui:widget';
|
|
178
|
+
var UI_OPTIONS_KEY = 'ui:options';
|
|
179
|
+
var UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
|
|
180
180
|
|
|
181
181
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
182
|
-
* stripped off.
|
|
182
|
+
* stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
|
|
183
183
|
*
|
|
184
184
|
* @param [uiSchema={}] - The UI Schema from which to get any `ui:xxx` options
|
|
185
|
-
* @
|
|
185
|
+
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
186
|
+
* @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions`
|
|
186
187
|
*/
|
|
187
|
-
function getUiOptions(uiSchema) {
|
|
188
|
+
function getUiOptions(uiSchema, globalOptions) {
|
|
188
189
|
if (uiSchema === void 0) {
|
|
189
190
|
uiSchema = {};
|
|
190
191
|
}
|
|
192
|
+
if (globalOptions === void 0) {
|
|
193
|
+
globalOptions = {};
|
|
194
|
+
}
|
|
191
195
|
return Object.keys(uiSchema).filter(function (key) {
|
|
192
|
-
return key.indexOf(
|
|
196
|
+
return key.indexOf('ui:') === 0;
|
|
193
197
|
}).reduce(function (options, key) {
|
|
194
198
|
var _extends2;
|
|
195
199
|
var value = uiSchema[key];
|
|
196
200
|
if (key === UI_WIDGET_KEY && isObject(value)) {
|
|
197
|
-
console.error(
|
|
201
|
+
console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
|
|
198
202
|
return options;
|
|
199
203
|
}
|
|
200
204
|
if (key === UI_OPTIONS_KEY && isObject(value)) {
|
|
201
205
|
return _extends({}, options, value);
|
|
202
206
|
}
|
|
203
207
|
return _extends({}, options, (_extends2 = {}, _extends2[key.substring(3)] = value, _extends2));
|
|
204
|
-
}, {});
|
|
208
|
+
}, _extends({}, globalOptions));
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
/** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
|
|
@@ -243,7 +247,7 @@
|
|
|
243
247
|
*/
|
|
244
248
|
function deepEquals(a, b) {
|
|
245
249
|
return isEqualWith__default["default"](a, b, function (obj, other) {
|
|
246
|
-
if (typeof obj ===
|
|
250
|
+
if (typeof obj === 'function' && typeof other === 'function') {
|
|
247
251
|
// Assume all functions are equivalent
|
|
248
252
|
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
249
253
|
return true;
|
|
@@ -278,8 +282,8 @@
|
|
|
278
282
|
if (rootSchema === void 0) {
|
|
279
283
|
rootSchema = {};
|
|
280
284
|
}
|
|
281
|
-
var ref = $ref ||
|
|
282
|
-
if (ref.startsWith(
|
|
285
|
+
var ref = $ref || '';
|
|
286
|
+
if (ref.startsWith('#')) {
|
|
283
287
|
// Decode URI fragment representation.
|
|
284
288
|
ref = decodeURIComponent(ref.substring(1));
|
|
285
289
|
} else {
|
|
@@ -387,25 +391,25 @@
|
|
|
387
391
|
*/
|
|
388
392
|
function guessType(value) {
|
|
389
393
|
if (Array.isArray(value)) {
|
|
390
|
-
return
|
|
394
|
+
return 'array';
|
|
391
395
|
}
|
|
392
|
-
if (typeof value ===
|
|
393
|
-
return
|
|
396
|
+
if (typeof value === 'string') {
|
|
397
|
+
return 'string';
|
|
394
398
|
}
|
|
395
399
|
if (value == null) {
|
|
396
|
-
return
|
|
400
|
+
return 'null';
|
|
397
401
|
}
|
|
398
|
-
if (typeof value ===
|
|
399
|
-
return
|
|
402
|
+
if (typeof value === 'boolean') {
|
|
403
|
+
return 'boolean';
|
|
400
404
|
}
|
|
401
405
|
if (!isNaN(value)) {
|
|
402
|
-
return
|
|
406
|
+
return 'number';
|
|
403
407
|
}
|
|
404
|
-
if (typeof value ===
|
|
405
|
-
return
|
|
408
|
+
if (typeof value === 'object') {
|
|
409
|
+
return 'object';
|
|
406
410
|
}
|
|
407
411
|
// Default to string if we can't figure it out
|
|
408
|
-
return
|
|
412
|
+
return 'string';
|
|
409
413
|
}
|
|
410
414
|
|
|
411
415
|
/** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
|
|
@@ -425,14 +429,14 @@
|
|
|
425
429
|
return guessType(schema["const"]);
|
|
426
430
|
}
|
|
427
431
|
if (!type && schema["enum"]) {
|
|
428
|
-
return
|
|
432
|
+
return 'string';
|
|
429
433
|
}
|
|
430
434
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
431
|
-
return
|
|
435
|
+
return 'object';
|
|
432
436
|
}
|
|
433
|
-
if (Array.isArray(type) && type.length === 2 && type.includes(
|
|
437
|
+
if (Array.isArray(type) && type.length === 2 && type.includes('null')) {
|
|
434
438
|
type = type.find(function (type) {
|
|
435
|
-
return type !==
|
|
439
|
+
return type !== 'null';
|
|
436
440
|
});
|
|
437
441
|
}
|
|
438
442
|
return type;
|
|
@@ -453,7 +457,7 @@
|
|
|
453
457
|
right = obj2[key];
|
|
454
458
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
455
459
|
acc[key] = mergeSchemas(left, right);
|
|
456
|
-
} else if (obj1 && obj2 && (getSchemaType(obj1) ===
|
|
460
|
+
} else if (obj1 && obj2 && (getSchemaType(obj1) === 'object' || getSchemaType(obj2) === 'object') && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
|
|
457
461
|
// Don't include duplicate values when merging 'required' fields.
|
|
458
462
|
acc[key] = union__default["default"](left, right);
|
|
459
463
|
} else {
|
|
@@ -483,7 +487,7 @@
|
|
|
483
487
|
otherwise = schema["else"],
|
|
484
488
|
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
485
489
|
var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
|
|
486
|
-
if (conditionalSchema && typeof conditionalSchema !==
|
|
490
|
+
if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
|
|
487
491
|
return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
|
|
488
492
|
}
|
|
489
493
|
return retrieveSchema(validator, resolvedSchemaLessConditional, rootSchema, formData);
|
|
@@ -555,16 +559,16 @@
|
|
|
555
559
|
return;
|
|
556
560
|
}
|
|
557
561
|
var additionalProperties = {};
|
|
558
|
-
if (typeof schema.additionalProperties !==
|
|
562
|
+
if (typeof schema.additionalProperties !== 'boolean') {
|
|
559
563
|
if (REF_KEY in schema.additionalProperties) {
|
|
560
564
|
additionalProperties = retrieveSchema(validator, {
|
|
561
565
|
$ref: get__default["default"](schema.additionalProperties, [REF_KEY])
|
|
562
566
|
}, rootSchema, formData);
|
|
563
|
-
} else if (
|
|
567
|
+
} else if ('type' in schema.additionalProperties) {
|
|
564
568
|
additionalProperties = _extends({}, schema.additionalProperties);
|
|
565
569
|
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
566
570
|
additionalProperties = _extends({
|
|
567
|
-
type:
|
|
571
|
+
type: 'object'
|
|
568
572
|
}, schema.additionalProperties);
|
|
569
573
|
} else {
|
|
570
574
|
additionalProperties = {
|
|
@@ -601,7 +605,7 @@
|
|
|
601
605
|
return {};
|
|
602
606
|
}
|
|
603
607
|
var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
|
|
604
|
-
if (
|
|
608
|
+
if ('if' in schema) {
|
|
605
609
|
return resolveCondition(validator, schema, rootSchema, rawFormData);
|
|
606
610
|
}
|
|
607
611
|
var formData = rawFormData || {};
|
|
@@ -611,7 +615,7 @@
|
|
|
611
615
|
deep: false
|
|
612
616
|
});
|
|
613
617
|
} catch (e) {
|
|
614
|
-
console.warn(
|
|
618
|
+
console.warn('could not merge subschemas in allOf:\n' + e);
|
|
615
619
|
var _resolvedSchema = resolvedSchema,
|
|
616
620
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
617
621
|
return resolvedSchemaWithoutAllOf;
|
|
@@ -712,7 +716,7 @@
|
|
|
712
716
|
}
|
|
713
717
|
// Resolve $refs inside oneOf.
|
|
714
718
|
var resolvedOneOf = oneOf.map(function (subschema) {
|
|
715
|
-
if (typeof subschema ===
|
|
719
|
+
if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
|
|
716
720
|
return subschema;
|
|
717
721
|
}
|
|
718
722
|
return resolveReference(validator, subschema, rootSchema, formData);
|
|
@@ -731,14 +735,14 @@
|
|
|
731
735
|
*/
|
|
732
736
|
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
|
|
733
737
|
var validSubschemas = oneOf.filter(function (subschema) {
|
|
734
|
-
if (typeof subschema ===
|
|
738
|
+
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
735
739
|
return false;
|
|
736
740
|
}
|
|
737
741
|
var conditionPropertySchema = subschema.properties[dependencyKey];
|
|
738
742
|
if (conditionPropertySchema) {
|
|
739
743
|
var _properties;
|
|
740
744
|
var conditionSchema = {
|
|
741
|
-
type:
|
|
745
|
+
type: 'object',
|
|
742
746
|
properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
|
|
743
747
|
};
|
|
744
748
|
var _validator$validateFo = validator.validateFormData(formData, conditionSchema),
|
|
@@ -764,10 +768,10 @@
|
|
|
764
768
|
* the first item
|
|
765
769
|
*/
|
|
766
770
|
var JUNK_OPTION = {
|
|
767
|
-
type:
|
|
771
|
+
type: 'object',
|
|
768
772
|
properties: {
|
|
769
773
|
__not_really_there__: {
|
|
770
|
-
type:
|
|
774
|
+
type: 'number'
|
|
771
775
|
}
|
|
772
776
|
}
|
|
773
777
|
};
|
|
@@ -800,7 +804,7 @@
|
|
|
800
804
|
if (isObject__default["default"](schema.properties)) {
|
|
801
805
|
totalScore += reduce__default["default"](schema.properties, function (score, value, key) {
|
|
802
806
|
var formValue = get__default["default"](formData, key);
|
|
803
|
-
if (typeof value ===
|
|
807
|
+
if (typeof value === 'boolean') {
|
|
804
808
|
return score;
|
|
805
809
|
}
|
|
806
810
|
if (has__default["default"](value, REF_KEY)) {
|
|
@@ -810,7 +814,7 @@
|
|
|
810
814
|
if (has__default["default"](value, ONE_OF_KEY) && formValue) {
|
|
811
815
|
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, ONE_OF_KEY));
|
|
812
816
|
}
|
|
813
|
-
if (value.type ===
|
|
817
|
+
if (value.type === 'object') {
|
|
814
818
|
return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
|
|
815
819
|
}
|
|
816
820
|
if (value.type === guessType(formValue)) {
|
|
@@ -970,7 +974,7 @@
|
|
|
970
974
|
acc[key] = mergeObjects(left, right, concatArrays);
|
|
971
975
|
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
972
976
|
var toMerge = right;
|
|
973
|
-
if (concatArrays ===
|
|
977
|
+
if (concatArrays === 'preventDuplicates') {
|
|
974
978
|
toMerge = right.reduce(function (result, value) {
|
|
975
979
|
if (!left.includes(value)) {
|
|
976
980
|
result.push(value);
|
|
@@ -1014,7 +1018,7 @@
|
|
|
1014
1018
|
}
|
|
1015
1019
|
if (Array.isArray(altSchemas)) {
|
|
1016
1020
|
return altSchemas.every(function (altSchemas) {
|
|
1017
|
-
return typeof altSchemas !==
|
|
1021
|
+
return typeof altSchemas !== 'boolean' && isConstant(altSchemas);
|
|
1018
1022
|
});
|
|
1019
1023
|
}
|
|
1020
1024
|
return false;
|
|
@@ -1028,7 +1032,7 @@
|
|
|
1028
1032
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1029
1033
|
*/
|
|
1030
1034
|
function isMultiSelect(validator, schema, rootSchema) {
|
|
1031
|
-
if (!schema.uniqueItems || !schema.items || typeof schema.items ===
|
|
1035
|
+
if (!schema.uniqueItems || !schema.items || typeof schema.items === 'boolean') {
|
|
1032
1036
|
return false;
|
|
1033
1037
|
}
|
|
1034
1038
|
return isSelect(validator, schema.items, rootSchema);
|
|
@@ -1067,11 +1071,11 @@
|
|
|
1067
1071
|
if (idx >= 0) {
|
|
1068
1072
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
1069
1073
|
var item = schema.items[idx];
|
|
1070
|
-
if (typeof item !==
|
|
1074
|
+
if (typeof item !== 'boolean') {
|
|
1071
1075
|
return item;
|
|
1072
1076
|
}
|
|
1073
1077
|
}
|
|
1074
|
-
} else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !==
|
|
1078
|
+
} else if (schema.items && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
|
|
1075
1079
|
return schema.items;
|
|
1076
1080
|
}
|
|
1077
1081
|
if (additionalItems !== AdditionalItemsHandling.Ignore && isObject(schema.additionalItems)) {
|
|
@@ -1163,12 +1167,12 @@
|
|
|
1163
1167
|
schema = schema.anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, schema.anyOf, 0)];
|
|
1164
1168
|
}
|
|
1165
1169
|
// Not defaults defined for this node, fallback to generic typed ones.
|
|
1166
|
-
if (typeof defaults ===
|
|
1170
|
+
if (typeof defaults === 'undefined') {
|
|
1167
1171
|
defaults = schema["default"];
|
|
1168
1172
|
}
|
|
1169
1173
|
switch (getSchemaType(schema)) {
|
|
1170
1174
|
// We need to recur for object schema inner default values.
|
|
1171
|
-
case
|
|
1175
|
+
case 'object':
|
|
1172
1176
|
{
|
|
1173
1177
|
var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
|
|
1174
1178
|
// Compute the defaults for this node, with the parent defaults we might
|
|
@@ -1188,7 +1192,7 @@
|
|
|
1188
1192
|
}
|
|
1189
1193
|
return objectDefaults;
|
|
1190
1194
|
}
|
|
1191
|
-
case
|
|
1195
|
+
case 'array':
|
|
1192
1196
|
// Inject defaults into existing array defaults
|
|
1193
1197
|
if (Array.isArray(defaults)) {
|
|
1194
1198
|
defaults = defaults.map(function (item, idx) {
|
|
@@ -1238,11 +1242,11 @@
|
|
|
1238
1242
|
includeUndefinedValues = false;
|
|
1239
1243
|
}
|
|
1240
1244
|
if (!isObject(theSchema)) {
|
|
1241
|
-
throw new Error(
|
|
1245
|
+
throw new Error('Invalid schema: ' + theSchema);
|
|
1242
1246
|
}
|
|
1243
1247
|
var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1244
1248
|
var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
|
|
1245
|
-
if (typeof formData ===
|
|
1249
|
+
if (typeof formData === 'undefined' || formData === null || typeof formData === 'number' && isNaN(formData)) {
|
|
1246
1250
|
// No form data? Use schema defaults.
|
|
1247
1251
|
return defaults;
|
|
1248
1252
|
}
|
|
@@ -1266,8 +1270,8 @@
|
|
|
1266
1270
|
}
|
|
1267
1271
|
return (
|
|
1268
1272
|
// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
|
|
1269
|
-
// https://react-jsonschema-form
|
|
1270
|
-
|
|
1273
|
+
// https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
|
|
1274
|
+
'widget' in getUiOptions(uiSchema) && getUiOptions(uiSchema)['widget'] !== 'hidden'
|
|
1271
1275
|
);
|
|
1272
1276
|
}
|
|
1273
1277
|
|
|
@@ -1283,12 +1287,12 @@
|
|
|
1283
1287
|
if (uiSchema === void 0) {
|
|
1284
1288
|
uiSchema = {};
|
|
1285
1289
|
}
|
|
1286
|
-
if (uiSchema[UI_WIDGET_KEY] ===
|
|
1290
|
+
if (uiSchema[UI_WIDGET_KEY] === 'files') {
|
|
1287
1291
|
return true;
|
|
1288
1292
|
}
|
|
1289
1293
|
if (schema.items) {
|
|
1290
1294
|
var itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
|
|
1291
|
-
return itemsSchema.type ===
|
|
1295
|
+
return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
|
|
1292
1296
|
}
|
|
1293
1297
|
return false;
|
|
1294
1298
|
}
|
|
@@ -1300,24 +1304,25 @@
|
|
|
1300
1304
|
* @param schema - The schema for which the display label flag is desired
|
|
1301
1305
|
* @param [uiSchema={}] - The UI schema from which to derive potentially displayable information
|
|
1302
1306
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1307
|
+
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
1303
1308
|
* @returns - True if the label should be displayed or false if it should not
|
|
1304
1309
|
*/
|
|
1305
|
-
function getDisplayLabel(validator, schema, uiSchema, rootSchema) {
|
|
1310
|
+
function getDisplayLabel(validator, schema, uiSchema, rootSchema, globalOptions) {
|
|
1306
1311
|
if (uiSchema === void 0) {
|
|
1307
1312
|
uiSchema = {};
|
|
1308
1313
|
}
|
|
1309
|
-
var uiOptions = getUiOptions(uiSchema);
|
|
1314
|
+
var uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1310
1315
|
var _uiOptions$label = uiOptions.label,
|
|
1311
1316
|
label = _uiOptions$label === void 0 ? true : _uiOptions$label;
|
|
1312
1317
|
var displayLabel = !!label;
|
|
1313
1318
|
var schemaType = getSchemaType(schema);
|
|
1314
|
-
if (schemaType ===
|
|
1319
|
+
if (schemaType === 'array') {
|
|
1315
1320
|
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1316
1321
|
}
|
|
1317
|
-
if (schemaType ===
|
|
1322
|
+
if (schemaType === 'object') {
|
|
1318
1323
|
displayLabel = false;
|
|
1319
1324
|
}
|
|
1320
|
-
if (schemaType ===
|
|
1325
|
+
if (schemaType === 'boolean' && !uiSchema[UI_WIDGET_KEY]) {
|
|
1321
1326
|
displayLabel = false;
|
|
1322
1327
|
}
|
|
1323
1328
|
if (uiSchema[UI_FIELD_KEY]) {
|
|
@@ -1354,7 +1359,7 @@
|
|
|
1354
1359
|
};
|
|
1355
1360
|
}
|
|
1356
1361
|
|
|
1357
|
-
var NO_VALUE = /*#__PURE__*/Symbol(
|
|
1362
|
+
var NO_VALUE = /*#__PURE__*/Symbol('no Value');
|
|
1358
1363
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
1359
1364
|
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
1360
1365
|
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
@@ -1435,8 +1440,8 @@
|
|
|
1435
1440
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1436
1441
|
}
|
|
1437
1442
|
// Now get types and see if they are the same
|
|
1438
|
-
var oldSchemaTypeForKey = get__default["default"](oldKeyedSchema,
|
|
1439
|
-
var newSchemaTypeForKey = get__default["default"](newKeyedSchema,
|
|
1443
|
+
var oldSchemaTypeForKey = get__default["default"](oldKeyedSchema, 'type');
|
|
1444
|
+
var newSchemaTypeForKey = get__default["default"](newKeyedSchema, 'type');
|
|
1440
1445
|
// Check if the old option has the same key with the same type
|
|
1441
1446
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1442
1447
|
if (has__default["default"](removeOldSchemaData, key)) {
|
|
@@ -1444,10 +1449,10 @@
|
|
|
1444
1449
|
delete removeOldSchemaData[key];
|
|
1445
1450
|
}
|
|
1446
1451
|
// If it is an object, we'll recurse and store the resulting sanitized data for the key
|
|
1447
|
-
if (newSchemaTypeForKey ===
|
|
1452
|
+
if (newSchemaTypeForKey === 'object' || newSchemaTypeForKey === 'array' && Array.isArray(formValue)) {
|
|
1448
1453
|
// SIDE-EFFECT: process the new schema type of object recursively to save iterations
|
|
1449
1454
|
var itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
|
|
1450
|
-
if (itemData !== undefined || newSchemaTypeForKey ===
|
|
1455
|
+
if (itemData !== undefined || newSchemaTypeForKey === 'array') {
|
|
1451
1456
|
// only put undefined values for the array type and not the object type
|
|
1452
1457
|
nestedData[key] = itemData;
|
|
1453
1458
|
}
|
|
@@ -1455,19 +1460,19 @@
|
|
|
1455
1460
|
// Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
|
|
1456
1461
|
// with the new default or const. This allows the case where two schemas differ that only by the default/const
|
|
1457
1462
|
// value to be properly selected
|
|
1458
|
-
var newOptionDefault = get__default["default"](newKeyedSchema,
|
|
1459
|
-
var oldOptionDefault = get__default["default"](oldKeyedSchema,
|
|
1463
|
+
var newOptionDefault = get__default["default"](newKeyedSchema, 'default', NO_VALUE);
|
|
1464
|
+
var oldOptionDefault = get__default["default"](oldKeyedSchema, 'default', NO_VALUE);
|
|
1460
1465
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1461
1466
|
if (oldOptionDefault === formValue) {
|
|
1462
1467
|
// If the old default matches the formValue, we'll update the new value to match the new default
|
|
1463
1468
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1464
|
-
} else if (get__default["default"](newKeyedSchema,
|
|
1469
|
+
} else if (get__default["default"](newKeyedSchema, 'readOnly') === true) {
|
|
1465
1470
|
// If the new schema has the default set to read-only, treat it like a const and remove the value
|
|
1466
1471
|
removeOldSchemaData[key] = undefined;
|
|
1467
1472
|
}
|
|
1468
1473
|
}
|
|
1469
|
-
var newOptionConst = get__default["default"](newKeyedSchema,
|
|
1470
|
-
var oldOptionConst = get__default["default"](oldKeyedSchema,
|
|
1474
|
+
var newOptionConst = get__default["default"](newKeyedSchema, 'const', NO_VALUE);
|
|
1475
|
+
var oldOptionConst = get__default["default"](oldKeyedSchema, 'const', NO_VALUE);
|
|
1471
1476
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1472
1477
|
// Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
|
|
1473
1478
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
|
|
@@ -1477,12 +1482,12 @@
|
|
|
1477
1482
|
});
|
|
1478
1483
|
newFormData = _extends({}, data, removeOldSchemaData, nestedData);
|
|
1479
1484
|
// First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
|
|
1480
|
-
} else if (get__default["default"](oldSchema,
|
|
1481
|
-
var oldSchemaItems = get__default["default"](oldSchema,
|
|
1482
|
-
var newSchemaItems = get__default["default"](newSchema,
|
|
1485
|
+
} else if (get__default["default"](oldSchema, 'type') === 'array' && get__default["default"](newSchema, 'type') === 'array' && Array.isArray(data)) {
|
|
1486
|
+
var oldSchemaItems = get__default["default"](oldSchema, 'items');
|
|
1487
|
+
var newSchemaItems = get__default["default"](newSchema, 'items');
|
|
1483
1488
|
// If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
|
|
1484
1489
|
// Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
|
|
1485
|
-
if (typeof oldSchemaItems ===
|
|
1490
|
+
if (typeof oldSchemaItems === 'object' && typeof newSchemaItems === 'object' && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1486
1491
|
if (has__default["default"](oldSchemaItems, REF_KEY)) {
|
|
1487
1492
|
oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
|
|
1488
1493
|
}
|
|
@@ -1490,12 +1495,12 @@
|
|
|
1490
1495
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1491
1496
|
}
|
|
1492
1497
|
// Now get types and see if they are the same
|
|
1493
|
-
var oldSchemaType = get__default["default"](oldSchemaItems,
|
|
1494
|
-
var newSchemaType = get__default["default"](newSchemaItems,
|
|
1498
|
+
var oldSchemaType = get__default["default"](oldSchemaItems, 'type');
|
|
1499
|
+
var newSchemaType = get__default["default"](newSchemaItems, 'type');
|
|
1495
1500
|
// Check if the old option has the same key with the same type
|
|
1496
1501
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1497
|
-
var maxItems = get__default["default"](newSchema,
|
|
1498
|
-
if (newSchemaType ===
|
|
1502
|
+
var maxItems = get__default["default"](newSchema, 'maxItems', -1);
|
|
1503
|
+
if (newSchemaType === 'object') {
|
|
1499
1504
|
newFormData = data.reduce(function (newValue, aValue) {
|
|
1500
1505
|
var itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
|
|
1501
1506
|
if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
|
|
@@ -1507,7 +1512,7 @@
|
|
|
1507
1512
|
newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
|
|
1508
1513
|
}
|
|
1509
1514
|
}
|
|
1510
|
-
} else if (typeof oldSchemaItems ===
|
|
1515
|
+
} else if (typeof oldSchemaItems === 'boolean' && typeof newSchemaItems === 'boolean' && oldSchemaItems === newSchemaItems) {
|
|
1511
1516
|
// If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined
|
|
1512
1517
|
newFormData = data;
|
|
1513
1518
|
}
|
|
@@ -1530,10 +1535,10 @@
|
|
|
1530
1535
|
*/
|
|
1531
1536
|
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
|
|
1532
1537
|
if (idPrefix === void 0) {
|
|
1533
|
-
idPrefix =
|
|
1538
|
+
idPrefix = 'root';
|
|
1534
1539
|
}
|
|
1535
1540
|
if (idSeparator === void 0) {
|
|
1536
|
-
idSeparator =
|
|
1541
|
+
idSeparator = '_';
|
|
1537
1542
|
}
|
|
1538
1543
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1539
1544
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
@@ -1546,7 +1551,7 @@
|
|
|
1546
1551
|
var idSchema = {
|
|
1547
1552
|
$id: $id
|
|
1548
1553
|
};
|
|
1549
|
-
if (schema.type ===
|
|
1554
|
+
if (schema.type === 'object' && PROPERTIES_KEY in schema) {
|
|
1550
1555
|
for (var name in schema.properties) {
|
|
1551
1556
|
var field = get__default["default"](schema, [PROPERTIES_KEY, name]);
|
|
1552
1557
|
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
@@ -1571,13 +1576,13 @@
|
|
|
1571
1576
|
function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
1572
1577
|
var _pathSchema;
|
|
1573
1578
|
if (name === void 0) {
|
|
1574
|
-
name =
|
|
1579
|
+
name = '';
|
|
1575
1580
|
}
|
|
1576
1581
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1577
1582
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1578
1583
|
return toPathSchema(validator, _schema, name, rootSchema, formData);
|
|
1579
1584
|
}
|
|
1580
|
-
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./,
|
|
1585
|
+
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ''), _pathSchema);
|
|
1581
1586
|
if (ONE_OF_KEY in schema) {
|
|
1582
1587
|
var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
|
|
1583
1588
|
var _schema2 = schema.oneOf[index];
|
|
@@ -1667,10 +1672,11 @@
|
|
|
1667
1672
|
*
|
|
1668
1673
|
* @param schema - The schema for which the display label flag is desired
|
|
1669
1674
|
* @param [uiSchema] - The UI schema from which to derive potentially displayable information
|
|
1675
|
+
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
1670
1676
|
* @returns - True if the label should be displayed or false if it should not
|
|
1671
1677
|
*/;
|
|
1672
|
-
_proto.getDisplayLabel = function getDisplayLabel$1(schema, uiSchema) {
|
|
1673
|
-
return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema);
|
|
1678
|
+
_proto.getDisplayLabel = function getDisplayLabel$1(schema, uiSchema, globalOptions) {
|
|
1679
|
+
return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema, globalOptions);
|
|
1674
1680
|
}
|
|
1675
1681
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1676
1682
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1780,10 +1786,10 @@
|
|
|
1780
1786
|
*/;
|
|
1781
1787
|
_proto.toIdSchema = function toIdSchema$1(schema, id, formData, idPrefix, idSeparator) {
|
|
1782
1788
|
if (idPrefix === void 0) {
|
|
1783
|
-
idPrefix =
|
|
1789
|
+
idPrefix = 'root';
|
|
1784
1790
|
}
|
|
1785
1791
|
if (idSeparator === void 0) {
|
|
1786
|
-
idSeparator =
|
|
1792
|
+
idSeparator = '_';
|
|
1787
1793
|
}
|
|
1788
1794
|
return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
|
|
1789
1795
|
}
|
|
@@ -1818,38 +1824,48 @@
|
|
|
1818
1824
|
*/
|
|
1819
1825
|
function dataURItoBlob(dataURI) {
|
|
1820
1826
|
// Split metadata from data
|
|
1821
|
-
var splitted = dataURI.split(
|
|
1827
|
+
var splitted = dataURI.split(',');
|
|
1822
1828
|
// Split params
|
|
1823
|
-
var params = splitted[0].split(
|
|
1829
|
+
var params = splitted[0].split(';');
|
|
1824
1830
|
// Get mime-type from params
|
|
1825
|
-
var type = params[0].replace(
|
|
1831
|
+
var type = params[0].replace('data:', '');
|
|
1826
1832
|
// Filter the name property from params
|
|
1827
1833
|
var properties = params.filter(function (param) {
|
|
1828
|
-
return param.split(
|
|
1834
|
+
return param.split('=')[0] === 'name';
|
|
1829
1835
|
});
|
|
1830
1836
|
// Look for the name and use unknown if no name property.
|
|
1831
1837
|
var name;
|
|
1832
1838
|
if (properties.length !== 1) {
|
|
1833
|
-
name =
|
|
1839
|
+
name = 'unknown';
|
|
1834
1840
|
} else {
|
|
1835
1841
|
// Because we filtered out the other property,
|
|
1836
|
-
// we only have the name case here
|
|
1837
|
-
name = properties[0].split(
|
|
1842
|
+
// we only have the name case here, which we decode to make it human-readable
|
|
1843
|
+
name = decodeURI(properties[0].split('=')[1]);
|
|
1838
1844
|
}
|
|
1839
1845
|
// Built the Uint8Array Blob parameter from the base64 string.
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1846
|
+
try {
|
|
1847
|
+
var binary = atob(splitted[1]);
|
|
1848
|
+
var array = [];
|
|
1849
|
+
for (var i = 0; i < binary.length; i++) {
|
|
1850
|
+
array.push(binary.charCodeAt(i));
|
|
1851
|
+
}
|
|
1852
|
+
// Create the blob object
|
|
1853
|
+
var blob = new window.Blob([new Uint8Array(array)], {
|
|
1854
|
+
type: type
|
|
1855
|
+
});
|
|
1856
|
+
return {
|
|
1857
|
+
blob: blob,
|
|
1858
|
+
name: name
|
|
1859
|
+
};
|
|
1860
|
+
} catch (error) {
|
|
1861
|
+
return {
|
|
1862
|
+
blob: {
|
|
1863
|
+
size: 0,
|
|
1864
|
+
type: error.message
|
|
1865
|
+
},
|
|
1866
|
+
name: dataURI
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1853
1869
|
}
|
|
1854
1870
|
|
|
1855
1871
|
/** Potentially substitutes all replaceable parameters with the associated value(s) from the `params` if available. When
|
|
@@ -1863,9 +1879,16 @@
|
|
|
1863
1879
|
function replaceStringParameters(inputString, params) {
|
|
1864
1880
|
var output = inputString;
|
|
1865
1881
|
if (Array.isArray(params)) {
|
|
1882
|
+
var parts = output.split(/(%\d)/);
|
|
1866
1883
|
params.forEach(function (param, index) {
|
|
1867
|
-
|
|
1884
|
+
var partIndex = parts.findIndex(function (part) {
|
|
1885
|
+
return part === "%" + (index + 1);
|
|
1886
|
+
});
|
|
1887
|
+
if (partIndex >= 0) {
|
|
1888
|
+
parts[partIndex] = param;
|
|
1889
|
+
}
|
|
1868
1890
|
});
|
|
1891
|
+
output = parts.join('');
|
|
1869
1892
|
}
|
|
1870
1893
|
return output;
|
|
1871
1894
|
}
|
|
@@ -1905,7 +1928,7 @@
|
|
|
1905
1928
|
});
|
|
1906
1929
|
}
|
|
1907
1930
|
// So Number(null) and Number('') both return 0, so use emptyValue for those two values
|
|
1908
|
-
var index = valueIndex ===
|
|
1931
|
+
var index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
|
|
1909
1932
|
var option = allEnumOptions[index];
|
|
1910
1933
|
return option ? option.value : emptyValue;
|
|
1911
1934
|
}
|
|
@@ -1971,7 +1994,7 @@
|
|
|
1971
1994
|
var selectedIndexes = allEnumOptions.map(function (opt, index) {
|
|
1972
1995
|
return enumOptionsIsSelected(opt.value, value) ? String(index) : undefined;
|
|
1973
1996
|
}).filter(function (opt) {
|
|
1974
|
-
return typeof opt !==
|
|
1997
|
+
return typeof opt !== 'undefined';
|
|
1975
1998
|
});
|
|
1976
1999
|
if (!multiple) {
|
|
1977
2000
|
return selectedIndexes[0];
|
|
@@ -2039,7 +2062,7 @@
|
|
|
2039
2062
|
* @private
|
|
2040
2063
|
*/
|
|
2041
2064
|
_proto.getOrCreateErrorBlock = function getOrCreateErrorBlock(pathOfError) {
|
|
2042
|
-
var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError ===
|
|
2065
|
+
var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === 'string';
|
|
2043
2066
|
var errorBlock = hasPath ? get__default["default"](this.errorSchema, pathOfError) : this.errorSchema;
|
|
2044
2067
|
if (!errorBlock && pathOfError) {
|
|
2045
2068
|
errorBlock = {};
|
|
@@ -2151,23 +2174,23 @@
|
|
|
2151
2174
|
autoDefaultStepAny = true;
|
|
2152
2175
|
}
|
|
2153
2176
|
var inputProps = _extends({
|
|
2154
|
-
type: defaultType ||
|
|
2177
|
+
type: defaultType || 'text'
|
|
2155
2178
|
}, rangeSpec(schema));
|
|
2156
2179
|
// If options.inputType is set use that as the input type
|
|
2157
2180
|
if (options.inputType) {
|
|
2158
2181
|
inputProps.type = options.inputType;
|
|
2159
2182
|
} else if (!defaultType) {
|
|
2160
2183
|
// If the schema is of type number or integer, set the input type to number
|
|
2161
|
-
if (schema.type ===
|
|
2162
|
-
inputProps.type =
|
|
2184
|
+
if (schema.type === 'number') {
|
|
2185
|
+
inputProps.type = 'number';
|
|
2163
2186
|
// Only add step if one isn't already defined and we are auto-defaulting the "any" step
|
|
2164
2187
|
if (autoDefaultStepAny && inputProps.step === undefined) {
|
|
2165
2188
|
// Setting step to 'any' fixes a bug in Safari where decimals are not
|
|
2166
2189
|
// allowed in number inputs
|
|
2167
|
-
inputProps.step =
|
|
2190
|
+
inputProps.step = 'any';
|
|
2168
2191
|
}
|
|
2169
|
-
} else if (schema.type ===
|
|
2170
|
-
inputProps.type =
|
|
2192
|
+
} else if (schema.type === 'integer') {
|
|
2193
|
+
inputProps.type = 'number';
|
|
2171
2194
|
// Only add step if one isn't already defined
|
|
2172
2195
|
if (inputProps.step === undefined) {
|
|
2173
2196
|
// Since this is integer, you always want to step up or down in multiples of 1
|
|
@@ -2187,7 +2210,7 @@
|
|
|
2187
2210
|
props: {
|
|
2188
2211
|
disabled: false
|
|
2189
2212
|
},
|
|
2190
|
-
submitText:
|
|
2213
|
+
submitText: 'Submit',
|
|
2191
2214
|
norender: false
|
|
2192
2215
|
};
|
|
2193
2216
|
/** Extracts any `ui:submitButtonOptions` from the `uiSchema` and merges them onto the `DEFAULT_OPTIONS`
|
|
@@ -2220,7 +2243,7 @@
|
|
|
2220
2243
|
uiOptions = {};
|
|
2221
2244
|
}
|
|
2222
2245
|
var templates = registry.templates;
|
|
2223
|
-
if (name ===
|
|
2246
|
+
if (name === 'ButtonTemplates') {
|
|
2224
2247
|
return templates[name];
|
|
2225
2248
|
}
|
|
2226
2249
|
return (
|
|
@@ -2235,53 +2258,54 @@
|
|
|
2235
2258
|
*/
|
|
2236
2259
|
var widgetMap = {
|
|
2237
2260
|
"boolean": {
|
|
2238
|
-
checkbox:
|
|
2239
|
-
radio:
|
|
2240
|
-
select:
|
|
2241
|
-
hidden:
|
|
2261
|
+
checkbox: 'CheckboxWidget',
|
|
2262
|
+
radio: 'RadioWidget',
|
|
2263
|
+
select: 'SelectWidget',
|
|
2264
|
+
hidden: 'HiddenWidget'
|
|
2242
2265
|
},
|
|
2243
2266
|
string: {
|
|
2244
|
-
text:
|
|
2245
|
-
password:
|
|
2246
|
-
email:
|
|
2247
|
-
hostname:
|
|
2248
|
-
ipv4:
|
|
2249
|
-
ipv6:
|
|
2250
|
-
uri:
|
|
2251
|
-
|
|
2252
|
-
radio:
|
|
2253
|
-
select:
|
|
2254
|
-
textarea:
|
|
2255
|
-
hidden:
|
|
2256
|
-
date:
|
|
2257
|
-
datetime:
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2267
|
+
text: 'TextWidget',
|
|
2268
|
+
password: 'PasswordWidget',
|
|
2269
|
+
email: 'EmailWidget',
|
|
2270
|
+
hostname: 'TextWidget',
|
|
2271
|
+
ipv4: 'TextWidget',
|
|
2272
|
+
ipv6: 'TextWidget',
|
|
2273
|
+
uri: 'URLWidget',
|
|
2274
|
+
'data-url': 'FileWidget',
|
|
2275
|
+
radio: 'RadioWidget',
|
|
2276
|
+
select: 'SelectWidget',
|
|
2277
|
+
textarea: 'TextareaWidget',
|
|
2278
|
+
hidden: 'HiddenWidget',
|
|
2279
|
+
date: 'DateWidget',
|
|
2280
|
+
datetime: 'DateTimeWidget',
|
|
2281
|
+
'date-time': 'DateTimeWidget',
|
|
2282
|
+
'alt-date': 'AltDateWidget',
|
|
2283
|
+
'alt-datetime': 'AltDateTimeWidget',
|
|
2284
|
+
time: 'TimeWidget',
|
|
2285
|
+
color: 'ColorWidget',
|
|
2286
|
+
file: 'FileWidget'
|
|
2263
2287
|
},
|
|
2264
2288
|
number: {
|
|
2265
|
-
text:
|
|
2266
|
-
select:
|
|
2267
|
-
updown:
|
|
2268
|
-
range:
|
|
2269
|
-
radio:
|
|
2270
|
-
hidden:
|
|
2289
|
+
text: 'TextWidget',
|
|
2290
|
+
select: 'SelectWidget',
|
|
2291
|
+
updown: 'UpDownWidget',
|
|
2292
|
+
range: 'RangeWidget',
|
|
2293
|
+
radio: 'RadioWidget',
|
|
2294
|
+
hidden: 'HiddenWidget'
|
|
2271
2295
|
},
|
|
2272
2296
|
integer: {
|
|
2273
|
-
text:
|
|
2274
|
-
select:
|
|
2275
|
-
updown:
|
|
2276
|
-
range:
|
|
2277
|
-
radio:
|
|
2278
|
-
hidden:
|
|
2297
|
+
text: 'TextWidget',
|
|
2298
|
+
select: 'SelectWidget',
|
|
2299
|
+
updown: 'UpDownWidget',
|
|
2300
|
+
range: 'RangeWidget',
|
|
2301
|
+
radio: 'RadioWidget',
|
|
2302
|
+
hidden: 'HiddenWidget'
|
|
2279
2303
|
},
|
|
2280
2304
|
array: {
|
|
2281
|
-
select:
|
|
2282
|
-
checkboxes:
|
|
2283
|
-
files:
|
|
2284
|
-
hidden:
|
|
2305
|
+
select: 'SelectWidget',
|
|
2306
|
+
checkboxes: 'CheckboxesWidget',
|
|
2307
|
+
files: 'FileWidget',
|
|
2308
|
+
hidden: 'HiddenWidget'
|
|
2285
2309
|
}
|
|
2286
2310
|
};
|
|
2287
2311
|
/** Wraps the given widget with stateless functional component that will merge any `defaultProps.options` with the
|
|
@@ -2292,18 +2316,18 @@
|
|
|
2292
2316
|
* @returns - The wrapper widget
|
|
2293
2317
|
*/
|
|
2294
2318
|
function mergeWidgetOptions(AWidget) {
|
|
2295
|
-
var MergedWidget = get__default["default"](AWidget,
|
|
2319
|
+
var MergedWidget = get__default["default"](AWidget, 'MergedWidget');
|
|
2296
2320
|
// cache return value as property of widget for proper react reconciliation
|
|
2297
2321
|
if (!MergedWidget) {
|
|
2298
2322
|
var defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2299
2323
|
MergedWidget = function MergedWidget(_ref) {
|
|
2300
2324
|
var options = _ref.options,
|
|
2301
2325
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
2302
|
-
return
|
|
2326
|
+
return jsxRuntime.jsx(AWidget, _extends({
|
|
2303
2327
|
options: _extends({}, defaultOptions, options)
|
|
2304
2328
|
}, props));
|
|
2305
2329
|
};
|
|
2306
|
-
set__default["default"](AWidget,
|
|
2330
|
+
set__default["default"](AWidget, 'MergedWidget', MergedWidget);
|
|
2307
2331
|
}
|
|
2308
2332
|
return MergedWidget;
|
|
2309
2333
|
}
|
|
@@ -2323,17 +2347,17 @@
|
|
|
2323
2347
|
registeredWidgets = {};
|
|
2324
2348
|
}
|
|
2325
2349
|
var type = getSchemaType(schema);
|
|
2326
|
-
if (typeof widget ===
|
|
2350
|
+
if (typeof widget === 'function' || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/react.createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
|
|
2327
2351
|
return mergeWidgetOptions(widget);
|
|
2328
2352
|
}
|
|
2329
|
-
if (typeof widget !==
|
|
2353
|
+
if (typeof widget !== 'string') {
|
|
2330
2354
|
throw new Error("Unsupported widget definition: " + typeof widget);
|
|
2331
2355
|
}
|
|
2332
2356
|
if (widget in registeredWidgets) {
|
|
2333
2357
|
var registeredWidget = registeredWidgets[widget];
|
|
2334
2358
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2335
2359
|
}
|
|
2336
|
-
if (typeof type ===
|
|
2360
|
+
if (typeof type === 'string') {
|
|
2337
2361
|
if (!(type in widgetMap)) {
|
|
2338
2362
|
throw new Error("No widget for type '" + type + "'");
|
|
2339
2363
|
}
|
|
@@ -2362,7 +2386,7 @@
|
|
|
2362
2386
|
return true;
|
|
2363
2387
|
} catch (e) {
|
|
2364
2388
|
var err = e;
|
|
2365
|
-
if (err.message && (err.message.startsWith(
|
|
2389
|
+
if (err.message && (err.message.startsWith('No widget') || err.message.startsWith('Unsupported widget'))) {
|
|
2366
2390
|
return false;
|
|
2367
2391
|
}
|
|
2368
2392
|
throw e;
|
|
@@ -2384,7 +2408,7 @@
|
|
|
2384
2408
|
* @returns - The consistent id for the field description element from the given `id`
|
|
2385
2409
|
*/
|
|
2386
2410
|
function descriptionId(id) {
|
|
2387
|
-
return idGenerator(id,
|
|
2411
|
+
return idGenerator(id, 'description');
|
|
2388
2412
|
}
|
|
2389
2413
|
/** Return a consistent `id` for the field error element
|
|
2390
2414
|
*
|
|
@@ -2392,7 +2416,7 @@
|
|
|
2392
2416
|
* @returns - The consistent id for the field error element from the given `id`
|
|
2393
2417
|
*/
|
|
2394
2418
|
function errorId(id) {
|
|
2395
|
-
return idGenerator(id,
|
|
2419
|
+
return idGenerator(id, 'error');
|
|
2396
2420
|
}
|
|
2397
2421
|
/** Return a consistent `id` for the field examples element
|
|
2398
2422
|
*
|
|
@@ -2400,7 +2424,7 @@
|
|
|
2400
2424
|
* @returns - The consistent id for the field examples element from the given `id`
|
|
2401
2425
|
*/
|
|
2402
2426
|
function examplesId(id) {
|
|
2403
|
-
return idGenerator(id,
|
|
2427
|
+
return idGenerator(id, 'examples');
|
|
2404
2428
|
}
|
|
2405
2429
|
/** Return a consistent `id` for the field help element
|
|
2406
2430
|
*
|
|
@@ -2408,7 +2432,7 @@
|
|
|
2408
2432
|
* @returns - The consistent id for the field help element from the given `id`
|
|
2409
2433
|
*/
|
|
2410
2434
|
function helpId(id) {
|
|
2411
|
-
return idGenerator(id,
|
|
2435
|
+
return idGenerator(id, 'help');
|
|
2412
2436
|
}
|
|
2413
2437
|
/** Return a consistent `id` for the field title element
|
|
2414
2438
|
*
|
|
@@ -2416,7 +2440,7 @@
|
|
|
2416
2440
|
* @returns - The consistent id for the field title element from the given `id`
|
|
2417
2441
|
*/
|
|
2418
2442
|
function titleId(id) {
|
|
2419
|
-
return idGenerator(id,
|
|
2443
|
+
return idGenerator(id, 'title');
|
|
2420
2444
|
}
|
|
2421
2445
|
/** Return a list of element ids that contain additional information about the field that can be used to as the aria
|
|
2422
2446
|
* description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
|
|
@@ -2430,7 +2454,7 @@
|
|
|
2430
2454
|
if (includeExamples === void 0) {
|
|
2431
2455
|
includeExamples = false;
|
|
2432
2456
|
}
|
|
2433
|
-
var examples = includeExamples ? " " + examplesId(id) :
|
|
2457
|
+
var examples = includeExamples ? " " + examplesId(id) : '';
|
|
2434
2458
|
return errorId(id) + " " + descriptionId(id) + " " + helpId(id) + examples;
|
|
2435
2459
|
}
|
|
2436
2460
|
/** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
|
|
@@ -2466,7 +2490,7 @@
|
|
|
2466
2490
|
if (CONST_KEY in schema) {
|
|
2467
2491
|
return schema["const"];
|
|
2468
2492
|
}
|
|
2469
|
-
throw new Error(
|
|
2493
|
+
throw new Error('schema cannot be inferred as a constant');
|
|
2470
2494
|
}
|
|
2471
2495
|
|
|
2472
2496
|
/** Gets the list of options from the schema. If the schema has an enum list, then those enum values are returned. The
|
|
@@ -2481,8 +2505,8 @@
|
|
|
2481
2505
|
// enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
|
|
2482
2506
|
// Cast the type to include enumNames so the feature still works.
|
|
2483
2507
|
var schemaWithEnumNames = schema;
|
|
2484
|
-
if (schemaWithEnumNames.enumNames && "development" !==
|
|
2485
|
-
console.warn(
|
|
2508
|
+
if (schemaWithEnumNames.enumNames && "development" !== 'production') {
|
|
2509
|
+
console.warn('The enumNames property is deprecated and may be removed in a future major release.');
|
|
2486
2510
|
}
|
|
2487
2511
|
if (schema["enum"]) {
|
|
2488
2512
|
return schema["enum"].map(function (value, i) {
|
|
@@ -2531,21 +2555,21 @@
|
|
|
2531
2555
|
};
|
|
2532
2556
|
var propertyHash = arrayToHash(properties);
|
|
2533
2557
|
var orderFiltered = order.filter(function (prop) {
|
|
2534
|
-
return prop ===
|
|
2558
|
+
return prop === '*' || propertyHash[prop];
|
|
2535
2559
|
});
|
|
2536
2560
|
var orderHash = arrayToHash(orderFiltered);
|
|
2537
2561
|
var rest = properties.filter(function (prop) {
|
|
2538
2562
|
return !orderHash[prop];
|
|
2539
2563
|
});
|
|
2540
|
-
var restIndex = orderFiltered.indexOf(
|
|
2564
|
+
var restIndex = orderFiltered.indexOf('*');
|
|
2541
2565
|
if (restIndex === -1) {
|
|
2542
2566
|
if (rest.length) {
|
|
2543
2567
|
throw new Error("uiSchema order list does not contain " + errorPropList(rest));
|
|
2544
2568
|
}
|
|
2545
2569
|
return orderFiltered;
|
|
2546
2570
|
}
|
|
2547
|
-
if (restIndex !== orderFiltered.lastIndexOf(
|
|
2548
|
-
throw new Error(
|
|
2571
|
+
if (restIndex !== orderFiltered.lastIndexOf('*')) {
|
|
2572
|
+
throw new Error('uiSchema order list contains more than one wildcard item');
|
|
2549
2573
|
}
|
|
2550
2574
|
var complete = [].concat(orderFiltered);
|
|
2551
2575
|
complete.splice.apply(complete, [restIndex, 1].concat(rest));
|
|
@@ -2561,7 +2585,7 @@
|
|
|
2561
2585
|
function pad(num, width) {
|
|
2562
2586
|
var s = String(num);
|
|
2563
2587
|
while (s.length < width) {
|
|
2564
|
-
s =
|
|
2588
|
+
s = '0' + s;
|
|
2565
2589
|
}
|
|
2566
2590
|
return s;
|
|
2567
2591
|
}
|
|
@@ -2589,7 +2613,7 @@
|
|
|
2589
2613
|
}
|
|
2590
2614
|
var date = new Date(dateString);
|
|
2591
2615
|
if (Number.isNaN(date.getTime())) {
|
|
2592
|
-
throw new Error(
|
|
2616
|
+
throw new Error('Unable to parse date ' + dateString);
|
|
2593
2617
|
}
|
|
2594
2618
|
return {
|
|
2595
2619
|
year: date.getUTCFullYear(),
|
|
@@ -2683,7 +2707,7 @@
|
|
|
2683
2707
|
*/
|
|
2684
2708
|
function utcToLocal(jsonDate) {
|
|
2685
2709
|
if (!jsonDate) {
|
|
2686
|
-
return
|
|
2710
|
+
return '';
|
|
2687
2711
|
}
|
|
2688
2712
|
// required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
|
|
2689
2713
|
// https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
|
|
@@ -2727,6 +2751,8 @@
|
|
|
2727
2751
|
TranslatableString["AddButton"] = "Add";
|
|
2728
2752
|
/** Add button title, used by AddButton */
|
|
2729
2753
|
TranslatableString["AddItemButton"] = "Add Item";
|
|
2754
|
+
/** Copy button title, used by IconButton */
|
|
2755
|
+
TranslatableString["CopyButton"] = "Copy";
|
|
2730
2756
|
/** Move down button title, used by IconButton */
|
|
2731
2757
|
TranslatableString["MoveDownButton"] = "Move down";
|
|
2732
2758
|
/** Move up button title, used by IconButton */
|
|
@@ -2755,6 +2781,8 @@
|
|
|
2755
2781
|
/** Key label, where %1 will be replaced by the label as provided by WrapIfAdditionalTemplate */
|
|
2756
2782
|
TranslatableString["KeyLabel"] = "%1 Key";
|
|
2757
2783
|
// Strings with replaceable parameters AND/OR that support markdown and html
|
|
2784
|
+
/** Invalid object field configuration as provided by the ObjectField */
|
|
2785
|
+
TranslatableString["InvalidObjectField"] = "Invalid \"%1\" object field configuration: <em>%2</em>.";
|
|
2758
2786
|
/** Unsupported field schema, used by UnsupportedField */
|
|
2759
2787
|
TranslatableString["UnsupportedField"] = "Unsupported field schema.";
|
|
2760
2788
|
/** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField */
|
|
@@ -2792,6 +2820,7 @@
|
|
|
2792
2820
|
exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
|
|
2793
2821
|
exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
|
|
2794
2822
|
exports.UI_FIELD_KEY = UI_FIELD_KEY;
|
|
2823
|
+
exports.UI_GLOBAL_OPTIONS_KEY = UI_GLOBAL_OPTIONS_KEY;
|
|
2795
2824
|
exports.UI_OPTIONS_KEY = UI_OPTIONS_KEY;
|
|
2796
2825
|
exports.UI_WIDGET_KEY = UI_WIDGET_KEY;
|
|
2797
2826
|
exports.allowAdditionalItems = allowAdditionalItems;
|