@rjsf/utils 5.0.0-beta.13 → 5.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +76 -8
- package/dist/utils.cjs.development.js +532 -383
- 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 +531 -384
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +535 -387
- 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
|
@@ -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/set'), require('json-schema-merge-allof'), require('lodash-es/union'), 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/set', 'json-schema-merge-allof', 'lodash-es/union', '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.set, global.mergeAllOf, global.union, global.React, global.ReactIs));
|
|
5
|
-
})(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, set, mergeAllOf, union, React, ReactIs) { 'use strict';
|
|
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/set'), require('json-schema-merge-allof'), require('lodash-es/union'), 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/set', 'json-schema-merge-allof', 'lodash-es/union', '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.set, global.mergeAllOf, global.union, global.cloneDeep, global.React, global.ReactIs));
|
|
5
|
+
})(this, (function (exports, isEqualWith, get, isEmpty, jsonpointer, omit, set, mergeAllOf, union, cloneDeep, React, ReactIs) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
|
|
15
15
|
var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
|
|
16
16
|
var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
|
|
17
|
+
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
17
18
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
19
|
var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
19
20
|
|
|
@@ -27,6 +28,9 @@
|
|
|
27
28
|
if (typeof File !== "undefined" && thing instanceof File) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
31
|
+
if (typeof Date !== "undefined" && thing instanceof Date) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
30
34
|
return typeof thing === "object" && thing !== null && !Array.isArray(thing);
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -74,38 +78,85 @@
|
|
|
74
78
|
// specific precision or number of significant digits)
|
|
75
79
|
return value;
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
var n = Number(value);
|
|
82
|
+
var valid = typeof n === "number" && !Number.isNaN(n);
|
|
79
83
|
return valid ? n : value;
|
|
80
84
|
}
|
|
81
85
|
|
|
86
|
+
function _defineProperties(target, props) {
|
|
87
|
+
for (var i = 0; i < props.length; i++) {
|
|
88
|
+
var descriptor = props[i];
|
|
89
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
90
|
+
descriptor.configurable = true;
|
|
91
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
92
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
96
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
97
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
98
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
99
|
+
writable: false
|
|
100
|
+
});
|
|
101
|
+
return Constructor;
|
|
102
|
+
}
|
|
103
|
+
function _extends() {
|
|
104
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
105
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
106
|
+
var source = arguments[i];
|
|
107
|
+
for (var key in source) {
|
|
108
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
109
|
+
target[key] = source[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return target;
|
|
114
|
+
};
|
|
115
|
+
return _extends.apply(this, arguments);
|
|
116
|
+
}
|
|
117
|
+
function _objectDestructuringEmpty(obj) {
|
|
118
|
+
if (obj == null) throw new TypeError("Cannot destructure " + obj);
|
|
119
|
+
}
|
|
120
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
121
|
+
if (source == null) return {};
|
|
122
|
+
var target = {};
|
|
123
|
+
var sourceKeys = Object.keys(source);
|
|
124
|
+
var key, i;
|
|
125
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
126
|
+
key = sourceKeys[i];
|
|
127
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
128
|
+
target[key] = source[key];
|
|
129
|
+
}
|
|
130
|
+
return target;
|
|
131
|
+
}
|
|
132
|
+
|
|
82
133
|
/** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
|
|
83
134
|
* utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
|
|
84
135
|
* `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
|
|
85
136
|
* utility.
|
|
86
137
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
var ADDITIONAL_PROPERTY_FLAG = "__additional_property";
|
|
139
|
+
var ADDITIONAL_PROPERTIES_KEY = "additionalProperties";
|
|
140
|
+
var ALL_OF_KEY = "allOf";
|
|
141
|
+
var ANY_OF_KEY = "anyOf";
|
|
142
|
+
var CONST_KEY = "const";
|
|
143
|
+
var DEFAULT_KEY = "default";
|
|
144
|
+
var DEFINITIONS_KEY = "definitions";
|
|
145
|
+
var DEPENDENCIES_KEY = "dependencies";
|
|
146
|
+
var ENUM_KEY = "enum";
|
|
147
|
+
var ERRORS_KEY = "__errors";
|
|
148
|
+
var ID_KEY = "$id";
|
|
149
|
+
var ITEMS_KEY = "items";
|
|
150
|
+
var NAME_KEY = "$name";
|
|
151
|
+
var ONE_OF_KEY = "oneOf";
|
|
152
|
+
var PROPERTIES_KEY = "properties";
|
|
153
|
+
var REQUIRED_KEY = "required";
|
|
154
|
+
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
155
|
+
var REF_KEY = "$ref";
|
|
156
|
+
var RJSF_ADDITONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
157
|
+
var UI_FIELD_KEY = "ui:field";
|
|
158
|
+
var UI_WIDGET_KEY = "ui:widget";
|
|
159
|
+
var UI_OPTIONS_KEY = "ui:options";
|
|
109
160
|
|
|
110
161
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
111
162
|
* stripped off.
|
|
@@ -117,22 +168,19 @@
|
|
|
117
168
|
if (uiSchema === void 0) {
|
|
118
169
|
uiSchema = {};
|
|
119
170
|
}
|
|
120
|
-
return Object.keys(uiSchema).filter(
|
|
121
|
-
|
|
171
|
+
return Object.keys(uiSchema).filter(function (key) {
|
|
172
|
+
return key.indexOf("ui:") === 0;
|
|
173
|
+
}).reduce(function (options, key) {
|
|
174
|
+
var _extends2;
|
|
175
|
+
var value = uiSchema[key];
|
|
122
176
|
if (key === UI_WIDGET_KEY && isObject(value)) {
|
|
123
177
|
console.error("Setting options via ui:widget object is no longer supported, use ui:options instead");
|
|
124
178
|
return options;
|
|
125
179
|
}
|
|
126
180
|
if (key === UI_OPTIONS_KEY && isObject(value)) {
|
|
127
|
-
return {
|
|
128
|
-
...options,
|
|
129
|
-
...value
|
|
130
|
-
};
|
|
181
|
+
return _extends({}, options, value);
|
|
131
182
|
}
|
|
132
|
-
return {
|
|
133
|
-
...options,
|
|
134
|
-
[key.substring(3)]: value
|
|
135
|
-
};
|
|
183
|
+
return _extends({}, options, (_extends2 = {}, _extends2[key.substring(3)] = value, _extends2));
|
|
136
184
|
}, {});
|
|
137
185
|
}
|
|
138
186
|
|
|
@@ -152,9 +200,9 @@
|
|
|
152
200
|
if (!schema.additionalProperties) {
|
|
153
201
|
return false;
|
|
154
202
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
203
|
+
var _getUiOptions = getUiOptions(uiSchema),
|
|
204
|
+
_getUiOptions$expanda = _getUiOptions.expandable,
|
|
205
|
+
expandable = _getUiOptions$expanda === void 0 ? true : _getUiOptions$expanda;
|
|
158
206
|
if (expandable === false) {
|
|
159
207
|
return expandable;
|
|
160
208
|
}
|
|
@@ -174,7 +222,7 @@
|
|
|
174
222
|
* @returns - True if the `a` and `b` are deeply equal, false otherwise
|
|
175
223
|
*/
|
|
176
224
|
function deepEquals(a, b) {
|
|
177
|
-
return isEqualWith__default["default"](a, b, (obj, other)
|
|
225
|
+
return isEqualWith__default["default"](a, b, function (obj, other) {
|
|
178
226
|
if (typeof obj === "function" && typeof other === "function") {
|
|
179
227
|
// Assume all functions are equivalent
|
|
180
228
|
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
@@ -193,8 +241,8 @@
|
|
|
193
241
|
* value from `object[key]`
|
|
194
242
|
*/
|
|
195
243
|
function splitKeyElementFromObject(key, object) {
|
|
196
|
-
|
|
197
|
-
|
|
244
|
+
var value = object[key];
|
|
245
|
+
var remaining = omit__default["default"](object, [key]);
|
|
198
246
|
return [remaining, value];
|
|
199
247
|
}
|
|
200
248
|
/** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
|
|
@@ -210,25 +258,24 @@
|
|
|
210
258
|
if (rootSchema === void 0) {
|
|
211
259
|
rootSchema = {};
|
|
212
260
|
}
|
|
213
|
-
|
|
261
|
+
var ref = $ref || "";
|
|
214
262
|
if (ref.startsWith("#")) {
|
|
215
263
|
// Decode URI fragment representation.
|
|
216
264
|
ref = decodeURIComponent(ref.substring(1));
|
|
217
265
|
} else {
|
|
218
|
-
throw new Error(
|
|
266
|
+
throw new Error("Could not find a definition for " + $ref + ".");
|
|
219
267
|
}
|
|
220
|
-
|
|
268
|
+
var current = jsonpointer__default["default"].get(rootSchema, ref);
|
|
221
269
|
if (current === undefined) {
|
|
222
|
-
throw new Error(
|
|
270
|
+
throw new Error("Could not find a definition for " + $ref + ".");
|
|
223
271
|
}
|
|
224
272
|
if (current[REF_KEY]) {
|
|
225
|
-
|
|
226
|
-
|
|
273
|
+
var _splitKeyElementFromO = splitKeyElementFromObject(REF_KEY, current),
|
|
274
|
+
remaining = _splitKeyElementFromO[0],
|
|
275
|
+
theRef = _splitKeyElementFromO[1];
|
|
276
|
+
var subSchema = findSchemaDefinition(theRef, rootSchema);
|
|
227
277
|
if (Object.keys(remaining).length > 0) {
|
|
228
|
-
return {
|
|
229
|
-
...remaining,
|
|
230
|
-
...subSchema
|
|
231
|
-
};
|
|
278
|
+
return _extends({}, remaining, subSchema);
|
|
232
279
|
}
|
|
233
280
|
return subSchema;
|
|
234
281
|
}
|
|
@@ -249,8 +296,8 @@
|
|
|
249
296
|
if (formData === undefined) {
|
|
250
297
|
return 0;
|
|
251
298
|
}
|
|
252
|
-
for (
|
|
253
|
-
|
|
299
|
+
for (var i = 0; i < options.length; i++) {
|
|
300
|
+
var option = options[i];
|
|
254
301
|
// If the schema describes an object then we need to add slightly more
|
|
255
302
|
// strict matching to the schema, because unless the schema uses the
|
|
256
303
|
// "requires" keyword, an object will match the schema as long as it
|
|
@@ -261,18 +308,18 @@
|
|
|
261
308
|
if (option.properties) {
|
|
262
309
|
// Create an "anyOf" schema that requires at least one of the keys in the
|
|
263
310
|
// "properties" object
|
|
264
|
-
|
|
265
|
-
anyOf: Object.keys(option.properties).map(key
|
|
266
|
-
|
|
267
|
-
|
|
311
|
+
var requiresAnyOf = {
|
|
312
|
+
anyOf: Object.keys(option.properties).map(function (key) {
|
|
313
|
+
return {
|
|
314
|
+
required: [key]
|
|
315
|
+
};
|
|
316
|
+
})
|
|
268
317
|
};
|
|
269
|
-
|
|
318
|
+
var augmentedSchema = void 0;
|
|
270
319
|
// If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
|
|
271
320
|
if (option.anyOf) {
|
|
272
321
|
// Create a shallow clone of the option
|
|
273
|
-
|
|
274
|
-
...shallowClone
|
|
275
|
-
} = option;
|
|
322
|
+
var shallowClone = _extends({}, (_objectDestructuringEmpty(option), option));
|
|
276
323
|
if (!shallowClone.allOf) {
|
|
277
324
|
shallowClone.allOf = [];
|
|
278
325
|
} else {
|
|
@@ -338,20 +385,20 @@
|
|
|
338
385
|
* @returns - The type of the schema
|
|
339
386
|
*/
|
|
340
387
|
function getSchemaType(schema) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (!type && schema.const) {
|
|
345
|
-
return guessType(schema.const);
|
|
388
|
+
var type = schema.type;
|
|
389
|
+
if (!type && schema["const"]) {
|
|
390
|
+
return guessType(schema["const"]);
|
|
346
391
|
}
|
|
347
|
-
if (!type && schema
|
|
392
|
+
if (!type && schema["enum"]) {
|
|
348
393
|
return "string";
|
|
349
394
|
}
|
|
350
395
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
351
396
|
return "object";
|
|
352
397
|
}
|
|
353
398
|
if (Array.isArray(type) && type.length === 2 && type.includes("null")) {
|
|
354
|
-
type = type.find(
|
|
399
|
+
type = type.find(function (type) {
|
|
400
|
+
return type !== "null";
|
|
401
|
+
});
|
|
355
402
|
}
|
|
356
403
|
return type;
|
|
357
404
|
}
|
|
@@ -363,7 +410,9 @@
|
|
|
363
410
|
* @returns - True if there are fixed items in the schema, false otherwise
|
|
364
411
|
*/
|
|
365
412
|
function isFixedItems(schema) {
|
|
366
|
-
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(
|
|
413
|
+
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(function (item) {
|
|
414
|
+
return isObject(item);
|
|
415
|
+
});
|
|
367
416
|
}
|
|
368
417
|
|
|
369
418
|
/** Merges the `defaults` object of type `T` into the `formData` of type `T`
|
|
@@ -382,8 +431,8 @@
|
|
|
382
431
|
*/
|
|
383
432
|
function mergeDefaultsWithFormData(defaults, formData) {
|
|
384
433
|
if (Array.isArray(formData)) {
|
|
385
|
-
|
|
386
|
-
|
|
434
|
+
var defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
435
|
+
var mapped = formData.map(function (value, idx) {
|
|
387
436
|
if (defaultsArray[idx]) {
|
|
388
437
|
return mergeDefaultsWithFormData(defaultsArray[idx], value);
|
|
389
438
|
}
|
|
@@ -392,8 +441,8 @@
|
|
|
392
441
|
return mapped;
|
|
393
442
|
}
|
|
394
443
|
if (isObject(formData)) {
|
|
395
|
-
|
|
396
|
-
return Object.keys(formData).reduce((acc, key)
|
|
444
|
+
var acc = Object.assign({}, defaults); // Prevent mutation of source object.
|
|
445
|
+
return Object.keys(formData).reduce(function (acc, key) {
|
|
397
446
|
acc[key] = mergeDefaultsWithFormData(defaults ? get__default["default"](defaults, key) : {}, get__default["default"](formData, key));
|
|
398
447
|
return acc;
|
|
399
448
|
}, acc);
|
|
@@ -405,20 +454,31 @@
|
|
|
405
454
|
*
|
|
406
455
|
* @param obj1 - The first object to merge
|
|
407
456
|
* @param obj2 - The second object to merge
|
|
408
|
-
* @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated
|
|
457
|
+
* @param [concatArrays=false] - Optional flag that, when true, will cause arrays to be concatenated. Use
|
|
458
|
+
* "preventDuplicates" to merge arrays in a manner that prevents any duplicate entries from being merged.
|
|
459
|
+
* NOTE: Uses shallow comparison for the duplicate checking.
|
|
409
460
|
* @returns - A new object that is the merge of the two given objects
|
|
410
461
|
*/
|
|
411
462
|
function mergeObjects(obj1, obj2, concatArrays) {
|
|
412
463
|
if (concatArrays === void 0) {
|
|
413
464
|
concatArrays = false;
|
|
414
465
|
}
|
|
415
|
-
return Object.keys(obj2).reduce((acc, key)
|
|
416
|
-
|
|
466
|
+
return Object.keys(obj2).reduce(function (acc, key) {
|
|
467
|
+
var left = obj1 ? obj1[key] : {},
|
|
417
468
|
right = obj2[key];
|
|
418
469
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
419
470
|
acc[key] = mergeObjects(left, right, concatArrays);
|
|
420
471
|
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
421
|
-
|
|
472
|
+
var toMerge = right;
|
|
473
|
+
if (concatArrays === "preventDuplicates") {
|
|
474
|
+
toMerge = right.reduce(function (result, value) {
|
|
475
|
+
if (!left.includes(value)) {
|
|
476
|
+
result.push(value);
|
|
477
|
+
}
|
|
478
|
+
return result;
|
|
479
|
+
}, []);
|
|
480
|
+
}
|
|
481
|
+
acc[key] = left.concat(toMerge);
|
|
422
482
|
} else {
|
|
423
483
|
acc[key] = right;
|
|
424
484
|
}
|
|
@@ -433,7 +493,7 @@
|
|
|
433
493
|
* @returns - True if the `schema` has a single constant value, false otherwise
|
|
434
494
|
*/
|
|
435
495
|
function isConstant(schema) {
|
|
436
|
-
return Array.isArray(schema
|
|
496
|
+
return Array.isArray(schema["enum"]) && schema["enum"].length === 1 || CONST_KEY in schema;
|
|
437
497
|
}
|
|
438
498
|
|
|
439
499
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
@@ -445,9 +505,9 @@
|
|
|
445
505
|
* @returns - The merged schema object
|
|
446
506
|
*/
|
|
447
507
|
function mergeSchemas(obj1, obj2) {
|
|
448
|
-
|
|
449
|
-
return Object.keys(obj2).reduce((acc, key)
|
|
450
|
-
|
|
508
|
+
var acc = Object.assign({}, obj1); // Prevent mutation of source object.
|
|
509
|
+
return Object.keys(obj2).reduce(function (acc, key) {
|
|
510
|
+
var left = obj1 ? obj1[key] : {},
|
|
451
511
|
right = obj2[key];
|
|
452
512
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
453
513
|
acc[key] = mergeSchemas(left, right);
|
|
@@ -461,6 +521,11 @@
|
|
|
461
521
|
}, acc);
|
|
462
522
|
}
|
|
463
523
|
|
|
524
|
+
var _excluded$1 = ["if", "then", "else"],
|
|
525
|
+
_excluded2 = ["$ref"],
|
|
526
|
+
_excluded3 = ["allOf"],
|
|
527
|
+
_excluded4 = ["dependencies"],
|
|
528
|
+
_excluded5 = ["oneOf"];
|
|
464
529
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
465
530
|
* with the rest of the schema
|
|
466
531
|
*
|
|
@@ -471,13 +536,11 @@
|
|
|
471
536
|
* @returns - A schema with the appropriate condition resolved
|
|
472
537
|
*/
|
|
473
538
|
function resolveCondition(validator, schema, rootSchema, formData) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
} = schema;
|
|
480
|
-
const conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
|
|
539
|
+
var expression = schema["if"],
|
|
540
|
+
then = schema.then,
|
|
541
|
+
otherwise = schema["else"],
|
|
542
|
+
resolvedSchemaLessConditional = _objectWithoutPropertiesLoose(schema, _excluded$1);
|
|
543
|
+
var conditionalSchema = validator.isValid(expression, formData, rootSchema) ? then : otherwise;
|
|
481
544
|
if (conditionalSchema && typeof conditionalSchema !== "boolean") {
|
|
482
545
|
return retrieveSchema(validator, mergeSchemas(resolvedSchemaLessConditional, retrieveSchema(validator, conditionalSchema, rootSchema, formData)), rootSchema, formData);
|
|
483
546
|
}
|
|
@@ -500,14 +563,15 @@
|
|
|
500
563
|
return resolveReference(validator, schema, rootSchema, formData);
|
|
501
564
|
}
|
|
502
565
|
if (DEPENDENCIES_KEY in schema) {
|
|
503
|
-
|
|
566
|
+
var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
|
|
504
567
|
return retrieveSchema(validator, resolvedSchema, rootSchema, formData);
|
|
505
568
|
}
|
|
506
569
|
if (ALL_OF_KEY in schema) {
|
|
507
|
-
return {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
570
|
+
return _extends({}, schema, {
|
|
571
|
+
allOf: schema.allOf.map(function (allOfSubschema) {
|
|
572
|
+
return retrieveSchema(validator, allOfSubschema, rootSchema, formData);
|
|
573
|
+
})
|
|
574
|
+
});
|
|
511
575
|
}
|
|
512
576
|
// No $ref or dependencies attribute found, returning the original schema.
|
|
513
577
|
return schema;
|
|
@@ -522,17 +586,11 @@
|
|
|
522
586
|
*/
|
|
523
587
|
function resolveReference(validator, schema, rootSchema, formData) {
|
|
524
588
|
// Retrieve the referenced schema definition.
|
|
525
|
-
|
|
589
|
+
var $refSchema = findSchemaDefinition(schema.$ref, rootSchema);
|
|
526
590
|
// Drop the $ref property of the source schema.
|
|
527
|
-
|
|
528
|
-
$ref,
|
|
529
|
-
...localSchema
|
|
530
|
-
} = schema;
|
|
591
|
+
var localSchema = _objectWithoutPropertiesLoose(schema, _excluded2);
|
|
531
592
|
// Update referenced schema definition with local schema properties.
|
|
532
|
-
return retrieveSchema(validator, {
|
|
533
|
-
...$refSchema,
|
|
534
|
-
...localSchema
|
|
535
|
-
}, rootSchema, formData);
|
|
593
|
+
return retrieveSchema(validator, _extends({}, $refSchema, localSchema), rootSchema, formData);
|
|
536
594
|
}
|
|
537
595
|
/** Creates new 'properties' items for each key in the `formData`
|
|
538
596
|
*
|
|
@@ -544,29 +602,24 @@
|
|
|
544
602
|
*/
|
|
545
603
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
546
604
|
// Clone the schema so we don't ruin the consumer's original
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
...theSchema.properties
|
|
551
|
-
}
|
|
552
|
-
};
|
|
605
|
+
var schema = _extends({}, theSchema, {
|
|
606
|
+
properties: _extends({}, theSchema.properties)
|
|
607
|
+
});
|
|
553
608
|
// make sure formData is an object
|
|
554
|
-
|
|
555
|
-
Object.keys(formData).forEach(key
|
|
609
|
+
var formData = aFormData && isObject(aFormData) ? aFormData : {};
|
|
610
|
+
Object.keys(formData).forEach(function (key) {
|
|
556
611
|
if (key in schema.properties) {
|
|
557
612
|
// No need to stub, our schema already has the property
|
|
558
613
|
return;
|
|
559
614
|
}
|
|
560
|
-
|
|
615
|
+
var additionalProperties = {};
|
|
561
616
|
if (typeof schema.additionalProperties !== "boolean") {
|
|
562
617
|
if (REF_KEY in schema.additionalProperties) {
|
|
563
618
|
additionalProperties = retrieveSchema(validator, {
|
|
564
619
|
$ref: get__default["default"](schema.additionalProperties, [REF_KEY])
|
|
565
620
|
}, rootSchema, formData);
|
|
566
621
|
} else if ("type" in schema.additionalProperties) {
|
|
567
|
-
additionalProperties = {
|
|
568
|
-
...schema.additionalProperties
|
|
569
|
-
};
|
|
622
|
+
additionalProperties = _extends({}, schema.additionalProperties);
|
|
570
623
|
} else {
|
|
571
624
|
additionalProperties = {
|
|
572
625
|
type: guessType(get__default["default"](formData, [key]))
|
|
@@ -601,46 +654,24 @@
|
|
|
601
654
|
if (!isObject(schema)) {
|
|
602
655
|
return {};
|
|
603
656
|
}
|
|
604
|
-
|
|
657
|
+
var resolvedSchema = resolveSchema(validator, schema, rootSchema, rawFormData);
|
|
605
658
|
if ("if" in schema) {
|
|
606
659
|
return resolveCondition(validator, schema, rootSchema, rawFormData);
|
|
607
660
|
}
|
|
608
|
-
|
|
609
|
-
// For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
|
|
610
|
-
// Otherwise, nested allOf subschemas will not be correctly displayed.
|
|
611
|
-
if (resolvedSchema.properties) {
|
|
612
|
-
const properties = {};
|
|
613
|
-
Object.entries(resolvedSchema.properties).forEach(entries => {
|
|
614
|
-
const propName = entries[0];
|
|
615
|
-
const propSchema = entries[1];
|
|
616
|
-
const rawPropData = formData[propName];
|
|
617
|
-
const propData = isObject(rawPropData) ? rawPropData : {};
|
|
618
|
-
const resolvedPropSchema = retrieveSchema(validator, propSchema, rootSchema, propData);
|
|
619
|
-
properties[propName] = resolvedPropSchema;
|
|
620
|
-
if (propSchema !== resolvedPropSchema && resolvedSchema.properties !== properties) {
|
|
621
|
-
resolvedSchema = {
|
|
622
|
-
...resolvedSchema,
|
|
623
|
-
properties
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
}
|
|
661
|
+
var formData = rawFormData || {};
|
|
628
662
|
if (ALL_OF_KEY in schema) {
|
|
629
663
|
try {
|
|
630
|
-
resolvedSchema = mergeAllOf__default["default"]({
|
|
631
|
-
|
|
632
|
-
allOf: resolvedSchema.allOf
|
|
664
|
+
resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
|
|
665
|
+
deep: false
|
|
633
666
|
});
|
|
634
667
|
} catch (e) {
|
|
635
668
|
console.warn("could not merge subschemas in allOf:\n" + e);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
...resolvedSchemaWithoutAllOf
|
|
639
|
-
} = resolvedSchema;
|
|
669
|
+
var _resolvedSchema = resolvedSchema,
|
|
670
|
+
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
640
671
|
return resolvedSchemaWithoutAllOf;
|
|
641
672
|
}
|
|
642
673
|
}
|
|
643
|
-
|
|
674
|
+
var hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
644
675
|
if (hasAdditionalProperties) {
|
|
645
676
|
return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, formData);
|
|
646
677
|
}
|
|
@@ -656,11 +687,9 @@
|
|
|
656
687
|
*/
|
|
657
688
|
function resolveDependencies(validator, schema, rootSchema, formData) {
|
|
658
689
|
// Drop the dependencies from the source schema.
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
} = schema;
|
|
663
|
-
let resolvedSchema = remainingSchema;
|
|
690
|
+
var dependencies = schema.dependencies,
|
|
691
|
+
remainingSchema = _objectWithoutPropertiesLoose(schema, _excluded4);
|
|
692
|
+
var resolvedSchema = remainingSchema;
|
|
664
693
|
if (Array.isArray(resolvedSchema.oneOf)) {
|
|
665
694
|
resolvedSchema = resolvedSchema.oneOf[getMatchingOption(validator, formData, resolvedSchema.oneOf, rootSchema)];
|
|
666
695
|
} else if (Array.isArray(resolvedSchema.anyOf)) {
|
|
@@ -678,9 +707,9 @@
|
|
|
678
707
|
* @returns - The schema with the `dependencies` resolved into it
|
|
679
708
|
*/
|
|
680
709
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, formData) {
|
|
681
|
-
|
|
710
|
+
var schema = resolvedSchema;
|
|
682
711
|
// Process dependencies updating the local schema properties as appropriate.
|
|
683
|
-
for (
|
|
712
|
+
for (var dependencyKey in dependencies) {
|
|
684
713
|
// Skip this dependency if its trigger property is not present.
|
|
685
714
|
if (get__default["default"](formData, [dependencyKey]) === undefined) {
|
|
686
715
|
continue;
|
|
@@ -689,7 +718,9 @@
|
|
|
689
718
|
if (schema.properties && !(dependencyKey in schema.properties)) {
|
|
690
719
|
continue;
|
|
691
720
|
}
|
|
692
|
-
|
|
721
|
+
var _splitKeyElementFromO = splitKeyElementFromObject(dependencyKey, dependencies),
|
|
722
|
+
remainingDependencies = _splitKeyElementFromO[0],
|
|
723
|
+
dependencyValue = _splitKeyElementFromO[1];
|
|
693
724
|
if (Array.isArray(dependencyValue)) {
|
|
694
725
|
schema = withDependentProperties(schema, dependencyValue);
|
|
695
726
|
} else if (isObject(dependencyValue)) {
|
|
@@ -709,11 +740,10 @@
|
|
|
709
740
|
if (!additionallyRequired) {
|
|
710
741
|
return schema;
|
|
711
742
|
}
|
|
712
|
-
|
|
713
|
-
return {
|
|
714
|
-
...schema,
|
|
743
|
+
var required = Array.isArray(schema.required) ? Array.from(new Set([].concat(schema.required, additionallyRequired))) : additionallyRequired;
|
|
744
|
+
return _extends({}, schema, {
|
|
715
745
|
required: required
|
|
716
|
-
};
|
|
746
|
+
});
|
|
717
747
|
}
|
|
718
748
|
/** Merges a dependent schema into the `schema` dealing with oneOfs and references
|
|
719
749
|
*
|
|
@@ -726,17 +756,16 @@
|
|
|
726
756
|
* @returns - The schema with the dependent schema resolved into it
|
|
727
757
|
*/
|
|
728
758
|
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, formData) {
|
|
729
|
-
|
|
730
|
-
oneOf,
|
|
731
|
-
|
|
732
|
-
} = retrieveSchema(validator, dependencyValue, rootSchema, formData);
|
|
759
|
+
var _retrieveSchema = retrieveSchema(validator, dependencyValue, rootSchema, formData),
|
|
760
|
+
oneOf = _retrieveSchema.oneOf,
|
|
761
|
+
dependentSchema = _objectWithoutPropertiesLoose(_retrieveSchema, _excluded5);
|
|
733
762
|
schema = mergeSchemas(schema, dependentSchema);
|
|
734
763
|
// Since it does not contain oneOf, we return the original schema.
|
|
735
764
|
if (oneOf === undefined) {
|
|
736
765
|
return schema;
|
|
737
766
|
}
|
|
738
767
|
// Resolve $refs inside oneOf.
|
|
739
|
-
|
|
768
|
+
var resolvedOneOf = oneOf.map(function (subschema) {
|
|
740
769
|
if (typeof subschema === "boolean" || !(REF_KEY in subschema)) {
|
|
741
770
|
return subschema;
|
|
742
771
|
}
|
|
@@ -755,23 +784,19 @@
|
|
|
755
784
|
* @returns The schema with the best choice of oneOf schemas merged into
|
|
756
785
|
*/
|
|
757
786
|
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, formData) {
|
|
758
|
-
|
|
787
|
+
var validSubschemas = oneOf.filter(function (subschema) {
|
|
759
788
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
760
789
|
return false;
|
|
761
790
|
}
|
|
762
|
-
|
|
763
|
-
[dependencyKey]: conditionPropertySchema
|
|
764
|
-
} = subschema.properties;
|
|
791
|
+
var conditionPropertySchema = subschema.properties[dependencyKey];
|
|
765
792
|
if (conditionPropertySchema) {
|
|
766
|
-
|
|
793
|
+
var _properties;
|
|
794
|
+
var conditionSchema = {
|
|
767
795
|
type: "object",
|
|
768
|
-
properties: {
|
|
769
|
-
[dependencyKey]: conditionPropertySchema
|
|
770
|
-
}
|
|
796
|
+
properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
|
|
771
797
|
};
|
|
772
|
-
|
|
773
|
-
errors
|
|
774
|
-
} = validator.validateFormData(formData, conditionSchema);
|
|
798
|
+
var _validator$validateFo = validator.validateFormData(formData, conditionSchema),
|
|
799
|
+
errors = _validator$validateFo.errors;
|
|
775
800
|
return errors.length === 0;
|
|
776
801
|
}
|
|
777
802
|
return false;
|
|
@@ -780,12 +805,12 @@
|
|
|
780
805
|
console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
|
|
781
806
|
return schema;
|
|
782
807
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
808
|
+
var subschema = validSubschemas[0];
|
|
809
|
+
var _splitKeyElementFromO2 = splitKeyElementFromObject(dependencyKey, subschema.properties),
|
|
810
|
+
dependentSubschema = _splitKeyElementFromO2[0];
|
|
811
|
+
var dependentSchema = _extends({}, subschema, {
|
|
787
812
|
properties: dependentSubschema
|
|
788
|
-
};
|
|
813
|
+
});
|
|
789
814
|
return mergeSchemas(schema, retrieveSchema(validator, dependentSchema, rootSchema, formData));
|
|
790
815
|
}
|
|
791
816
|
|
|
@@ -800,13 +825,15 @@
|
|
|
800
825
|
if (rootSchema === void 0) {
|
|
801
826
|
rootSchema = {};
|
|
802
827
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (Array.isArray(schema
|
|
828
|
+
var schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
|
|
829
|
+
var altSchemas = schema.oneOf || schema.anyOf;
|
|
830
|
+
if (Array.isArray(schema["enum"])) {
|
|
806
831
|
return true;
|
|
807
832
|
}
|
|
808
833
|
if (Array.isArray(altSchemas)) {
|
|
809
|
-
return altSchemas.every(
|
|
834
|
+
return altSchemas.every(function (altSchemas) {
|
|
835
|
+
return typeof altSchemas !== "boolean" && isConstant(altSchemas);
|
|
836
|
+
});
|
|
810
837
|
}
|
|
811
838
|
return false;
|
|
812
839
|
}
|
|
@@ -857,7 +884,7 @@
|
|
|
857
884
|
}
|
|
858
885
|
if (idx >= 0) {
|
|
859
886
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
860
|
-
|
|
887
|
+
var item = schema.items[idx];
|
|
861
888
|
if (typeof item !== "boolean") {
|
|
862
889
|
return item;
|
|
863
890
|
}
|
|
@@ -878,34 +905,39 @@
|
|
|
878
905
|
* @param [parentDefaults] - Any defaults provided by the parent field in the schema
|
|
879
906
|
* @param [rootSchema] - The options root schema, used to primarily to look up `$ref`s
|
|
880
907
|
* @param [rawFormData] - The current formData, if any, onto which to provide any missing defaults
|
|
881
|
-
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
|
|
908
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
909
|
+
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
910
|
+
* object properties.
|
|
882
911
|
* @returns - The resulting `formData` with all the defaults provided
|
|
883
912
|
*/
|
|
884
|
-
function computeDefaults(validator,
|
|
913
|
+
function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
|
|
885
914
|
if (rootSchema === void 0) {
|
|
886
915
|
rootSchema = {};
|
|
887
916
|
}
|
|
888
917
|
if (includeUndefinedValues === void 0) {
|
|
889
918
|
includeUndefinedValues = false;
|
|
890
919
|
}
|
|
891
|
-
|
|
920
|
+
var formData = isObject(rawFormData) ? rawFormData : {};
|
|
921
|
+
var schema = isObject(rawSchema) ? rawSchema : {};
|
|
892
922
|
// Compute the defaults recursively: give highest priority to deepest nodes.
|
|
893
|
-
|
|
894
|
-
if (isObject(defaults) && isObject(schema
|
|
923
|
+
var defaults = parentDefaults;
|
|
924
|
+
if (isObject(defaults) && isObject(schema["default"])) {
|
|
895
925
|
// For object defaults, only override parent defaults that are defined in
|
|
896
926
|
// schema.default.
|
|
897
|
-
defaults = mergeObjects(defaults, schema
|
|
927
|
+
defaults = mergeObjects(defaults, schema["default"]);
|
|
898
928
|
} else if (DEFAULT_KEY in schema) {
|
|
899
|
-
defaults = schema
|
|
929
|
+
defaults = schema["default"];
|
|
900
930
|
} else if (REF_KEY in schema) {
|
|
901
931
|
// Use referenced schema defaults for this node.
|
|
902
|
-
|
|
932
|
+
var refSchema = findSchemaDefinition(schema[REF_KEY], rootSchema);
|
|
903
933
|
return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues);
|
|
904
934
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
905
|
-
|
|
935
|
+
var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
|
|
906
936
|
return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues);
|
|
907
937
|
} else if (isFixedItems(schema)) {
|
|
908
|
-
defaults = schema.items.map((itemSchema, idx)
|
|
938
|
+
defaults = schema.items.map(function (itemSchema, idx) {
|
|
939
|
+
return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues);
|
|
940
|
+
});
|
|
909
941
|
} else if (ONE_OF_KEY in schema) {
|
|
910
942
|
schema = schema.oneOf[getMatchingOption(validator, isEmpty__default["default"](formData) ? undefined : formData, schema.oneOf, rootSchema)];
|
|
911
943
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -913,16 +945,24 @@
|
|
|
913
945
|
}
|
|
914
946
|
// Not defaults defined for this node, fallback to generic typed ones.
|
|
915
947
|
if (typeof defaults === "undefined") {
|
|
916
|
-
defaults = schema
|
|
948
|
+
defaults = schema["default"];
|
|
917
949
|
}
|
|
918
950
|
switch (getSchemaType(schema)) {
|
|
919
951
|
// We need to recur for object schema inner default values.
|
|
920
952
|
case "object":
|
|
921
|
-
return Object.keys(schema.properties || {}).reduce((acc, key)
|
|
953
|
+
return Object.keys(schema.properties || {}).reduce(function (acc, key) {
|
|
922
954
|
// Compute the defaults for this node, with the parent defaults we might
|
|
923
955
|
// have from a previous run: defaults[key].
|
|
924
|
-
|
|
925
|
-
if (includeUndefinedValues
|
|
956
|
+
var computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), get__default["default"](defaults, [key]), rootSchema, get__default["default"](formData, [key]), includeUndefinedValues === "excludeObjectChildren" ? false : includeUndefinedValues);
|
|
957
|
+
if (includeUndefinedValues) {
|
|
958
|
+
acc[key] = computedDefault;
|
|
959
|
+
} else if (isObject(computedDefault)) {
|
|
960
|
+
// Store computedDefault if it's a non-empty object (e.g. not {})
|
|
961
|
+
if (!isEmpty__default["default"](computedDefault)) {
|
|
962
|
+
acc[key] = computedDefault;
|
|
963
|
+
}
|
|
964
|
+
} else if (computedDefault !== undefined) {
|
|
965
|
+
// Store computedDefault if it's a defined primitive (e.g. true)
|
|
926
966
|
acc[key] = computedDefault;
|
|
927
967
|
}
|
|
928
968
|
return acc;
|
|
@@ -930,27 +970,27 @@
|
|
|
930
970
|
case "array":
|
|
931
971
|
// Inject defaults into existing array defaults
|
|
932
972
|
if (Array.isArray(defaults)) {
|
|
933
|
-
defaults = defaults.map((item, idx)
|
|
934
|
-
|
|
973
|
+
defaults = defaults.map(function (item, idx) {
|
|
974
|
+
var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
|
|
935
975
|
return computeDefaults(validator, schemaItem, item, rootSchema);
|
|
936
976
|
});
|
|
937
977
|
}
|
|
938
978
|
// Deeply inject defaults into already existing form data
|
|
939
979
|
if (Array.isArray(rawFormData)) {
|
|
940
|
-
|
|
941
|
-
defaults = rawFormData.map((item, idx)
|
|
980
|
+
var schemaItem = getInnerSchemaForArrayItem(schema);
|
|
981
|
+
defaults = rawFormData.map(function (item, idx) {
|
|
942
982
|
return computeDefaults(validator, schemaItem, get__default["default"](defaults, [idx]), rootSchema, item);
|
|
943
983
|
});
|
|
944
984
|
}
|
|
945
985
|
if (schema.minItems) {
|
|
946
986
|
if (!isMultiSelect(validator, schema, rootSchema)) {
|
|
947
|
-
|
|
987
|
+
var defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
948
988
|
if (schema.minItems > defaultsLength) {
|
|
949
|
-
|
|
989
|
+
var defaultEntries = defaults || [];
|
|
950
990
|
// populate the array with the defaults
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
991
|
+
var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
|
|
992
|
+
var fillerDefault = fillerSchema["default"];
|
|
993
|
+
var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema));
|
|
954
994
|
// then fill up the rest with either the item default or empty, up to minItems
|
|
955
995
|
return defaultEntries.concat(fillerEntries);
|
|
956
996
|
}
|
|
@@ -967,7 +1007,9 @@
|
|
|
967
1007
|
* @param theSchema - The schema for which the default state is desired
|
|
968
1008
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
969
1009
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
970
|
-
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
|
|
1010
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1011
|
+
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
1012
|
+
* object properties.
|
|
971
1013
|
* @returns - The resulting `formData` with all the defaults provided
|
|
972
1014
|
*/
|
|
973
1015
|
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues) {
|
|
@@ -977,8 +1019,8 @@
|
|
|
977
1019
|
if (!isObject(theSchema)) {
|
|
978
1020
|
throw new Error("Invalid schema: " + theSchema);
|
|
979
1021
|
}
|
|
980
|
-
|
|
981
|
-
|
|
1022
|
+
var schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1023
|
+
var defaults = computeDefaults(validator, schema, undefined, rootSchema, formData, includeUndefinedValues);
|
|
982
1024
|
if (typeof formData === "undefined" || formData === null || typeof formData === "number" && isNaN(formData)) {
|
|
983
1025
|
// No form data? Use schema defaults.
|
|
984
1026
|
return defaults;
|
|
@@ -1024,7 +1066,7 @@
|
|
|
1024
1066
|
return true;
|
|
1025
1067
|
}
|
|
1026
1068
|
if (schema.items) {
|
|
1027
|
-
|
|
1069
|
+
var itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
|
|
1028
1070
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1029
1071
|
}
|
|
1030
1072
|
return false;
|
|
@@ -1043,12 +1085,11 @@
|
|
|
1043
1085
|
if (uiSchema === void 0) {
|
|
1044
1086
|
uiSchema = {};
|
|
1045
1087
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
label = true
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
const schemaType = getSchemaType(schema);
|
|
1088
|
+
var uiOptions = getUiOptions(uiSchema);
|
|
1089
|
+
var _uiOptions$label = uiOptions.label,
|
|
1090
|
+
label = _uiOptions$label === void 0 ? true : _uiOptions$label;
|
|
1091
|
+
var displayLabel = !!label;
|
|
1092
|
+
var schemaType = getSchemaType(schema);
|
|
1052
1093
|
if (schemaType === "array") {
|
|
1053
1094
|
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1054
1095
|
}
|
|
@@ -1078,19 +1119,17 @@
|
|
|
1078
1119
|
if (!additionalErrorSchema) {
|
|
1079
1120
|
return validationData;
|
|
1080
1121
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1086
|
-
let errorSchema = additionalErrorSchema;
|
|
1122
|
+
var oldErrors = validationData.errors,
|
|
1123
|
+
oldErrorSchema = validationData.errorSchema;
|
|
1124
|
+
var errors = validator.toErrorList(additionalErrorSchema);
|
|
1125
|
+
var errorSchema = additionalErrorSchema;
|
|
1087
1126
|
if (!isEmpty__default["default"](oldErrorSchema)) {
|
|
1088
1127
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1089
|
-
errors = [
|
|
1128
|
+
errors = [].concat(oldErrors).concat(errors);
|
|
1090
1129
|
}
|
|
1091
1130
|
return {
|
|
1092
|
-
errorSchema,
|
|
1093
|
-
errors
|
|
1131
|
+
errorSchema: errorSchema,
|
|
1132
|
+
errors: errors
|
|
1094
1133
|
};
|
|
1095
1134
|
}
|
|
1096
1135
|
|
|
@@ -1113,20 +1152,20 @@
|
|
|
1113
1152
|
idSeparator = "_";
|
|
1114
1153
|
}
|
|
1115
1154
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1116
|
-
|
|
1155
|
+
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1117
1156
|
return toIdSchema(validator, _schema, id, rootSchema, formData, idPrefix, idSeparator);
|
|
1118
1157
|
}
|
|
1119
1158
|
if (ITEMS_KEY in schema && !get__default["default"](schema, [ITEMS_KEY, REF_KEY])) {
|
|
1120
1159
|
return toIdSchema(validator, get__default["default"](schema, ITEMS_KEY), id, rootSchema, formData, idPrefix, idSeparator);
|
|
1121
1160
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
$id
|
|
1161
|
+
var $id = id || idPrefix;
|
|
1162
|
+
var idSchema = {
|
|
1163
|
+
$id: $id
|
|
1125
1164
|
};
|
|
1126
1165
|
if (schema.type === "object" && PROPERTIES_KEY in schema) {
|
|
1127
|
-
for (
|
|
1128
|
-
|
|
1129
|
-
|
|
1166
|
+
for (var name in schema.properties) {
|
|
1167
|
+
var field = get__default["default"](schema, [PROPERTIES_KEY, name]);
|
|
1168
|
+
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1130
1169
|
idSchema[name] = toIdSchema(validator, isObject(field) ? field : {}, fieldId, rootSchema,
|
|
1131
1170
|
// It's possible that formData is not an object -- this can happen if an
|
|
1132
1171
|
// array item has just been added, but not populated with data yet
|
|
@@ -1146,27 +1185,26 @@
|
|
|
1146
1185
|
* @returns - The `PathSchema` object for the `schema`
|
|
1147
1186
|
*/
|
|
1148
1187
|
function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
1188
|
+
var _pathSchema;
|
|
1149
1189
|
if (name === void 0) {
|
|
1150
1190
|
name = "";
|
|
1151
1191
|
}
|
|
1152
1192
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1153
|
-
|
|
1193
|
+
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1154
1194
|
return toPathSchema(validator, _schema, name, rootSchema, formData);
|
|
1155
1195
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
};
|
|
1159
|
-
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] === true) {
|
|
1196
|
+
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ""), _pathSchema);
|
|
1197
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
1160
1198
|
set__default["default"](pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
|
|
1161
1199
|
}
|
|
1162
1200
|
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
1163
|
-
formData.forEach((element, i)
|
|
1164
|
-
pathSchema[i] = toPathSchema(validator, schema.items,
|
|
1201
|
+
formData.forEach(function (element, i) {
|
|
1202
|
+
pathSchema[i] = toPathSchema(validator, schema.items, name + "." + i, rootSchema, element);
|
|
1165
1203
|
});
|
|
1166
1204
|
} else if (PROPERTIES_KEY in schema) {
|
|
1167
|
-
for (
|
|
1168
|
-
|
|
1169
|
-
pathSchema[property] = toPathSchema(validator, field,
|
|
1205
|
+
for (var property in schema.properties) {
|
|
1206
|
+
var field = get__default["default"](schema, [PROPERTIES_KEY, property]);
|
|
1207
|
+
pathSchema[property] = toPathSchema(validator, field, name + "." + property, rootSchema,
|
|
1170
1208
|
// It's possible that formData is not an object -- this can happen if an
|
|
1171
1209
|
// array item has just been added, but not populated with data yet
|
|
1172
1210
|
get__default["default"](formData, [property]));
|
|
@@ -1180,13 +1218,13 @@
|
|
|
1180
1218
|
* and `rootSchema` generally does not change across a `Form`, this allows for providing a simplified set of APIs to the
|
|
1181
1219
|
* `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
|
|
1182
1220
|
*/
|
|
1183
|
-
|
|
1221
|
+
var SchemaUtils = /*#__PURE__*/function () {
|
|
1184
1222
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
1185
1223
|
*
|
|
1186
1224
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1187
1225
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1188
1226
|
*/
|
|
1189
|
-
|
|
1227
|
+
function SchemaUtils(validator, rootSchema) {
|
|
1190
1228
|
this.rootSchema = void 0;
|
|
1191
1229
|
this.validator = void 0;
|
|
1192
1230
|
this.rootSchema = rootSchema;
|
|
@@ -1196,7 +1234,8 @@
|
|
|
1196
1234
|
*
|
|
1197
1235
|
* @returns - The `ValidatorType`
|
|
1198
1236
|
*/
|
|
1199
|
-
|
|
1237
|
+
var _proto = SchemaUtils.prototype;
|
|
1238
|
+
_proto.getValidator = function getValidator() {
|
|
1200
1239
|
return this.validator;
|
|
1201
1240
|
}
|
|
1202
1241
|
/** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
|
|
@@ -1206,8 +1245,8 @@
|
|
|
1206
1245
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1207
1246
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1208
1247
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1209
|
-
|
|
1210
|
-
doesSchemaUtilsDiffer(validator, rootSchema) {
|
|
1248
|
+
*/;
|
|
1249
|
+
_proto.doesSchemaUtilsDiffer = function doesSchemaUtilsDiffer(validator, rootSchema) {
|
|
1211
1250
|
if (!validator || !rootSchema) {
|
|
1212
1251
|
return false;
|
|
1213
1252
|
}
|
|
@@ -1218,10 +1257,12 @@
|
|
|
1218
1257
|
*
|
|
1219
1258
|
* @param schema - The schema for which the default state is desired
|
|
1220
1259
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1221
|
-
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults
|
|
1260
|
+
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1261
|
+
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
1262
|
+
* object properties.
|
|
1222
1263
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1223
|
-
|
|
1224
|
-
getDefaultFormState(schema, formData, includeUndefinedValues) {
|
|
1264
|
+
*/;
|
|
1265
|
+
_proto.getDefaultFormState = function getDefaultFormState$1(schema, formData, includeUndefinedValues) {
|
|
1225
1266
|
if (includeUndefinedValues === void 0) {
|
|
1226
1267
|
includeUndefinedValues = false;
|
|
1227
1268
|
}
|
|
@@ -1233,8 +1274,8 @@
|
|
|
1233
1274
|
* @param schema - The schema for which the display label flag is desired
|
|
1234
1275
|
* @param [uiSchema] - The UI schema from which to derive potentially displayable information
|
|
1235
1276
|
* @returns - True if the label should be displayed or false if it should not
|
|
1236
|
-
|
|
1237
|
-
getDisplayLabel(schema, uiSchema) {
|
|
1277
|
+
*/;
|
|
1278
|
+
_proto.getDisplayLabel = function getDisplayLabel$1(schema, uiSchema) {
|
|
1238
1279
|
return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema);
|
|
1239
1280
|
}
|
|
1240
1281
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
@@ -1242,8 +1283,8 @@
|
|
|
1242
1283
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
1243
1284
|
* @param options - The list of options to find a matching options from
|
|
1244
1285
|
* @returns - The index of the matched option or 0 if none is available
|
|
1245
|
-
|
|
1246
|
-
getMatchingOption(formData, options) {
|
|
1286
|
+
*/;
|
|
1287
|
+
_proto.getMatchingOption = function getMatchingOption$1(formData, options) {
|
|
1247
1288
|
return getMatchingOption(this.validator, formData, options, this.rootSchema);
|
|
1248
1289
|
}
|
|
1249
1290
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
@@ -1251,24 +1292,24 @@
|
|
|
1251
1292
|
* @param schema - The schema for which check for array of files flag is desired
|
|
1252
1293
|
* @param [uiSchema] - The UI schema from which to check the widget
|
|
1253
1294
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1254
|
-
|
|
1255
|
-
isFilesArray(schema, uiSchema) {
|
|
1295
|
+
*/;
|
|
1296
|
+
_proto.isFilesArray = function isFilesArray$1(schema, uiSchema) {
|
|
1256
1297
|
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
1257
1298
|
}
|
|
1258
1299
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1259
1300
|
*
|
|
1260
1301
|
* @param schema - The schema for which check for a multi-select flag is desired
|
|
1261
1302
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1262
|
-
|
|
1263
|
-
isMultiSelect(schema) {
|
|
1303
|
+
*/;
|
|
1304
|
+
_proto.isMultiSelect = function isMultiSelect$1(schema) {
|
|
1264
1305
|
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
1265
1306
|
}
|
|
1266
1307
|
/** Checks to see if the `schema` combination represents a select
|
|
1267
1308
|
*
|
|
1268
1309
|
* @param schema - The schema for which check for a select flag is desired
|
|
1269
1310
|
* @returns - True if schema contains a select, otherwise false
|
|
1270
|
-
|
|
1271
|
-
isSelect(schema) {
|
|
1311
|
+
*/;
|
|
1312
|
+
_proto.isSelect = function isSelect$1(schema) {
|
|
1272
1313
|
return isSelect(this.validator, schema, this.rootSchema);
|
|
1273
1314
|
}
|
|
1274
1315
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
@@ -1279,8 +1320,8 @@
|
|
|
1279
1320
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1280
1321
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
1281
1322
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1282
|
-
|
|
1283
|
-
mergeValidationData(validationData, additionalErrorSchema) {
|
|
1323
|
+
*/;
|
|
1324
|
+
_proto.mergeValidationData = function mergeValidationData$1(validationData, additionalErrorSchema) {
|
|
1284
1325
|
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
1285
1326
|
}
|
|
1286
1327
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
@@ -1290,8 +1331,8 @@
|
|
|
1290
1331
|
* @param schema - The schema for which retrieving a schema is desired
|
|
1291
1332
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
1292
1333
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1293
|
-
|
|
1294
|
-
retrieveSchema(schema, rawFormData) {
|
|
1334
|
+
*/;
|
|
1335
|
+
_proto.retrieveSchema = function retrieveSchema$1(schema, rawFormData) {
|
|
1295
1336
|
return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
|
|
1296
1337
|
}
|
|
1297
1338
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
@@ -1302,8 +1343,8 @@
|
|
|
1302
1343
|
* @param [idPrefix='root'] - The prefix to use for the id
|
|
1303
1344
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1304
1345
|
* @returns - The `IdSchema` object for the `schema`
|
|
1305
|
-
|
|
1306
|
-
toIdSchema(schema, id, formData, idPrefix, idSeparator) {
|
|
1346
|
+
*/;
|
|
1347
|
+
_proto.toIdSchema = function toIdSchema$1(schema, id, formData, idPrefix, idSeparator) {
|
|
1307
1348
|
if (idPrefix === void 0) {
|
|
1308
1349
|
idPrefix = "root";
|
|
1309
1350
|
}
|
|
@@ -1318,11 +1359,12 @@
|
|
|
1318
1359
|
* @param [name] - The base name for the schema
|
|
1319
1360
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1320
1361
|
* @returns - The `PathSchema` object for the `schema`
|
|
1321
|
-
|
|
1322
|
-
toPathSchema(schema, name, formData) {
|
|
1362
|
+
*/;
|
|
1363
|
+
_proto.toPathSchema = function toPathSchema$1(schema, name, formData) {
|
|
1323
1364
|
return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1365
|
+
};
|
|
1366
|
+
return SchemaUtils;
|
|
1367
|
+
}();
|
|
1326
1368
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
1327
1369
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
1328
1370
|
*
|
|
@@ -1342,17 +1384,17 @@
|
|
|
1342
1384
|
*/
|
|
1343
1385
|
function dataURItoBlob(dataURI) {
|
|
1344
1386
|
// Split metadata from data
|
|
1345
|
-
|
|
1387
|
+
var splitted = dataURI.split(",");
|
|
1346
1388
|
// Split params
|
|
1347
|
-
|
|
1389
|
+
var params = splitted[0].split(";");
|
|
1348
1390
|
// Get mime-type from params
|
|
1349
|
-
|
|
1391
|
+
var type = params[0].replace("data:", "");
|
|
1350
1392
|
// Filter the name property from params
|
|
1351
|
-
|
|
1393
|
+
var properties = params.filter(function (param) {
|
|
1352
1394
|
return param.split("=")[0] === "name";
|
|
1353
1395
|
});
|
|
1354
1396
|
// Look for the name and use unknown if no name property.
|
|
1355
|
-
|
|
1397
|
+
var name;
|
|
1356
1398
|
if (properties.length !== 1) {
|
|
1357
1399
|
name = "unknown";
|
|
1358
1400
|
} else {
|
|
@@ -1361,21 +1403,126 @@
|
|
|
1361
1403
|
name = properties[0].split("=")[1];
|
|
1362
1404
|
}
|
|
1363
1405
|
// Built the Uint8Array Blob parameter from the base64 string.
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
for (
|
|
1406
|
+
var binary = atob(splitted[1]);
|
|
1407
|
+
var array = [];
|
|
1408
|
+
for (var i = 0; i < binary.length; i++) {
|
|
1367
1409
|
array.push(binary.charCodeAt(i));
|
|
1368
1410
|
}
|
|
1369
1411
|
// Create the blob object
|
|
1370
|
-
|
|
1371
|
-
type
|
|
1412
|
+
var blob = new window.Blob([new Uint8Array(array)], {
|
|
1413
|
+
type: type
|
|
1372
1414
|
});
|
|
1373
1415
|
return {
|
|
1374
|
-
blob,
|
|
1375
|
-
name
|
|
1416
|
+
blob: blob,
|
|
1417
|
+
name: name
|
|
1376
1418
|
};
|
|
1377
1419
|
}
|
|
1378
1420
|
|
|
1421
|
+
/** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
|
|
1422
|
+
* designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
|
|
1423
|
+
* schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
|
|
1424
|
+
* get the result and/or reset all the errors back to an initial set and start again.
|
|
1425
|
+
*/
|
|
1426
|
+
var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
1427
|
+
/** The error schema being built
|
|
1428
|
+
*
|
|
1429
|
+
* @private
|
|
1430
|
+
*/
|
|
1431
|
+
|
|
1432
|
+
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1433
|
+
*
|
|
1434
|
+
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
1435
|
+
*/
|
|
1436
|
+
function ErrorSchemaBuilder(initialSchema) {
|
|
1437
|
+
this.errorSchema = {};
|
|
1438
|
+
this.resetAllErrors(initialSchema);
|
|
1439
|
+
}
|
|
1440
|
+
/** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
|
|
1441
|
+
*/
|
|
1442
|
+
var _proto = ErrorSchemaBuilder.prototype;
|
|
1443
|
+
/** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
|
|
1444
|
+
*
|
|
1445
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
1446
|
+
* @returns - The error block for the given `pathOfError` or the root if not provided
|
|
1447
|
+
* @private
|
|
1448
|
+
*/
|
|
1449
|
+
_proto.getOrCreateErrorBlock = function getOrCreateErrorBlock(pathOfError) {
|
|
1450
|
+
var hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1451
|
+
var errorBlock = hasPath ? get__default["default"](this.errorSchema, pathOfError) : this.errorSchema;
|
|
1452
|
+
if (!errorBlock && pathOfError) {
|
|
1453
|
+
errorBlock = {};
|
|
1454
|
+
set__default["default"](this.errorSchema, pathOfError, errorBlock);
|
|
1455
|
+
}
|
|
1456
|
+
return errorBlock;
|
|
1457
|
+
}
|
|
1458
|
+
/** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
|
|
1459
|
+
*
|
|
1460
|
+
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
1461
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1462
|
+
*/;
|
|
1463
|
+
_proto.resetAllErrors = function resetAllErrors(initialSchema) {
|
|
1464
|
+
this.errorSchema = initialSchema ? cloneDeep__default["default"](initialSchema) : {};
|
|
1465
|
+
return this;
|
|
1466
|
+
}
|
|
1467
|
+
/** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
|
|
1468
|
+
* the schema described by the `pathOfError`. For more information about how to specify the path see the
|
|
1469
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1470
|
+
*
|
|
1471
|
+
* @param errorOrList - The error or list of errors to add into the `ErrorSchema`
|
|
1472
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
1473
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1474
|
+
*/;
|
|
1475
|
+
_proto.addErrors = function addErrors(errorOrList, pathOfError) {
|
|
1476
|
+
var errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1477
|
+
var errorsList = get__default["default"](errorBlock, ERRORS_KEY);
|
|
1478
|
+
if (!Array.isArray(errorsList)) {
|
|
1479
|
+
errorsList = [];
|
|
1480
|
+
errorBlock[ERRORS_KEY] = errorsList;
|
|
1481
|
+
}
|
|
1482
|
+
if (Array.isArray(errorOrList)) {
|
|
1483
|
+
var _errorsList;
|
|
1484
|
+
(_errorsList = errorsList).push.apply(_errorsList, errorOrList);
|
|
1485
|
+
} else {
|
|
1486
|
+
errorsList.push(errorOrList);
|
|
1487
|
+
}
|
|
1488
|
+
return this;
|
|
1489
|
+
}
|
|
1490
|
+
/** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
|
|
1491
|
+
* within the schema described by the `pathOfError`. For more information about how to specify the path see the
|
|
1492
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1493
|
+
*
|
|
1494
|
+
* @param errorOrList - The error or list of errors to set into the `ErrorSchema`
|
|
1495
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
|
|
1496
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1497
|
+
*/;
|
|
1498
|
+
_proto.setErrors = function setErrors(errorOrList, pathOfError) {
|
|
1499
|
+
var errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1500
|
+
// Effectively clone the array being given to prevent accidental outside manipulation of the given list
|
|
1501
|
+
var listToAdd = Array.isArray(errorOrList) ? [].concat(errorOrList) : [errorOrList];
|
|
1502
|
+
set__default["default"](errorBlock, ERRORS_KEY, listToAdd);
|
|
1503
|
+
return this;
|
|
1504
|
+
}
|
|
1505
|
+
/** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
|
|
1506
|
+
* the `pathOfError`. For more information about how to specify the path see the
|
|
1507
|
+
* [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
|
|
1508
|
+
*
|
|
1509
|
+
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
|
|
1510
|
+
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
1511
|
+
*/;
|
|
1512
|
+
_proto.clearErrors = function clearErrors(pathOfError) {
|
|
1513
|
+
var errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1514
|
+
set__default["default"](errorBlock, ERRORS_KEY, []);
|
|
1515
|
+
return this;
|
|
1516
|
+
};
|
|
1517
|
+
_createClass(ErrorSchemaBuilder, [{
|
|
1518
|
+
key: "ErrorSchema",
|
|
1519
|
+
get: function get() {
|
|
1520
|
+
return this.errorSchema;
|
|
1521
|
+
}
|
|
1522
|
+
}]);
|
|
1523
|
+
return ErrorSchemaBuilder;
|
|
1524
|
+
}();
|
|
1525
|
+
|
|
1379
1526
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
1380
1527
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
1381
1528
|
*
|
|
@@ -1383,7 +1530,7 @@
|
|
|
1383
1530
|
* @returns - A range specification from the schema
|
|
1384
1531
|
*/
|
|
1385
1532
|
function rangeSpec(schema) {
|
|
1386
|
-
|
|
1533
|
+
var spec = {};
|
|
1387
1534
|
if (schema.multipleOf) {
|
|
1388
1535
|
spec.step = schema.multipleOf;
|
|
1389
1536
|
}
|
|
@@ -1411,10 +1558,9 @@
|
|
|
1411
1558
|
if (autoDefaultStepAny === void 0) {
|
|
1412
1559
|
autoDefaultStepAny = true;
|
|
1413
1560
|
}
|
|
1414
|
-
|
|
1415
|
-
type: defaultType || "text"
|
|
1416
|
-
|
|
1417
|
-
};
|
|
1561
|
+
var inputProps = _extends({
|
|
1562
|
+
type: defaultType || "text"
|
|
1563
|
+
}, rangeSpec(schema));
|
|
1418
1564
|
// If options.inputType is set use that as the input type
|
|
1419
1565
|
if (options.inputType) {
|
|
1420
1566
|
inputProps.type = options.inputType;
|
|
@@ -1445,7 +1591,7 @@
|
|
|
1445
1591
|
|
|
1446
1592
|
/** The default submit button options, exported for testing purposes
|
|
1447
1593
|
*/
|
|
1448
|
-
|
|
1594
|
+
var DEFAULT_OPTIONS = {
|
|
1449
1595
|
props: {
|
|
1450
1596
|
disabled: false
|
|
1451
1597
|
},
|
|
@@ -1461,13 +1607,10 @@
|
|
|
1461
1607
|
if (uiSchema === void 0) {
|
|
1462
1608
|
uiSchema = {};
|
|
1463
1609
|
}
|
|
1464
|
-
|
|
1610
|
+
var uiOptions = getUiOptions(uiSchema);
|
|
1465
1611
|
if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
|
|
1466
|
-
|
|
1467
|
-
return {
|
|
1468
|
-
...DEFAULT_OPTIONS,
|
|
1469
|
-
...options
|
|
1470
|
-
};
|
|
1612
|
+
var options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
|
|
1613
|
+
return _extends({}, DEFAULT_OPTIONS, options);
|
|
1471
1614
|
}
|
|
1472
1615
|
return DEFAULT_OPTIONS;
|
|
1473
1616
|
}
|
|
@@ -1484,9 +1627,7 @@
|
|
|
1484
1627
|
if (uiOptions === void 0) {
|
|
1485
1628
|
uiOptions = {};
|
|
1486
1629
|
}
|
|
1487
|
-
|
|
1488
|
-
templates
|
|
1489
|
-
} = registry;
|
|
1630
|
+
var templates = registry.templates;
|
|
1490
1631
|
if (name === "ButtonTemplates") {
|
|
1491
1632
|
return templates[name];
|
|
1492
1633
|
}
|
|
@@ -1497,10 +1638,11 @@
|
|
|
1497
1638
|
);
|
|
1498
1639
|
}
|
|
1499
1640
|
|
|
1641
|
+
var _excluded = ["options"];
|
|
1500
1642
|
/** The map of schema types to widget type to widget name
|
|
1501
1643
|
*/
|
|
1502
|
-
|
|
1503
|
-
boolean: {
|
|
1644
|
+
var widgetMap = {
|
|
1645
|
+
"boolean": {
|
|
1504
1646
|
checkbox: "CheckboxWidget",
|
|
1505
1647
|
radio: "RadioWidget",
|
|
1506
1648
|
select: "SelectWidget",
|
|
@@ -1558,22 +1700,16 @@
|
|
|
1558
1700
|
* @returns - The wrapper widget
|
|
1559
1701
|
*/
|
|
1560
1702
|
function mergeWidgetOptions(AWidget) {
|
|
1561
|
-
|
|
1703
|
+
var MergedWidget = get__default["default"](AWidget, "MergedWidget");
|
|
1562
1704
|
// cache return value as property of widget for proper react reconciliation
|
|
1563
1705
|
if (!MergedWidget) {
|
|
1564
|
-
|
|
1565
|
-
MergedWidget = _ref
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
options: {
|
|
1572
|
-
...defaultOptions,
|
|
1573
|
-
...options
|
|
1574
|
-
},
|
|
1575
|
-
...props
|
|
1576
|
-
});
|
|
1706
|
+
var defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
1707
|
+
MergedWidget = function MergedWidget(_ref) {
|
|
1708
|
+
var options = _ref.options,
|
|
1709
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1710
|
+
return /*#__PURE__*/React__default["default"].createElement(AWidget, _extends({
|
|
1711
|
+
options: _extends({}, defaultOptions, options)
|
|
1712
|
+
}, props));
|
|
1577
1713
|
};
|
|
1578
1714
|
set__default["default"](AWidget, "MergedWidget", MergedWidget);
|
|
1579
1715
|
}
|
|
@@ -1594,27 +1730,27 @@
|
|
|
1594
1730
|
if (registeredWidgets === void 0) {
|
|
1595
1731
|
registeredWidgets = {};
|
|
1596
1732
|
}
|
|
1597
|
-
|
|
1733
|
+
var type = getSchemaType(schema);
|
|
1598
1734
|
if (typeof widget === "function" || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/React__default["default"].createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
|
|
1599
1735
|
return mergeWidgetOptions(widget);
|
|
1600
1736
|
}
|
|
1601
1737
|
if (typeof widget !== "string") {
|
|
1602
|
-
throw new Error(
|
|
1738
|
+
throw new Error("Unsupported widget definition: " + typeof widget);
|
|
1603
1739
|
}
|
|
1604
1740
|
if (widget in registeredWidgets) {
|
|
1605
|
-
|
|
1741
|
+
var registeredWidget = registeredWidgets[widget];
|
|
1606
1742
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
1607
1743
|
}
|
|
1608
1744
|
if (typeof type === "string") {
|
|
1609
1745
|
if (!(type in widgetMap)) {
|
|
1610
|
-
throw new Error(
|
|
1746
|
+
throw new Error("No widget for type '" + type + "'");
|
|
1611
1747
|
}
|
|
1612
1748
|
if (widget in widgetMap[type]) {
|
|
1613
|
-
|
|
1614
|
-
return getWidget(schema,
|
|
1749
|
+
var _registeredWidget = registeredWidgets[widgetMap[type][widget]];
|
|
1750
|
+
return getWidget(schema, _registeredWidget, registeredWidgets);
|
|
1615
1751
|
}
|
|
1616
1752
|
}
|
|
1617
|
-
throw new Error(
|
|
1753
|
+
throw new Error("No widget '" + widget + "' for type '" + type + "'");
|
|
1618
1754
|
}
|
|
1619
1755
|
|
|
1620
1756
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|
|
@@ -1633,7 +1769,7 @@
|
|
|
1633
1769
|
getWidget(schema, widget, registeredWidgets);
|
|
1634
1770
|
return true;
|
|
1635
1771
|
} catch (e) {
|
|
1636
|
-
|
|
1772
|
+
var err = e;
|
|
1637
1773
|
if (err.message && (err.message.startsWith("No widget") || err.message.startsWith("Unsupported widget"))) {
|
|
1638
1774
|
return false;
|
|
1639
1775
|
}
|
|
@@ -1658,11 +1794,11 @@
|
|
|
1658
1794
|
* @throws - Error when the schema does not have a constant value
|
|
1659
1795
|
*/
|
|
1660
1796
|
function toConstant(schema) {
|
|
1661
|
-
if (ENUM_KEY in schema && Array.isArray(schema
|
|
1662
|
-
return schema
|
|
1797
|
+
if (ENUM_KEY in schema && Array.isArray(schema["enum"]) && schema["enum"].length === 1) {
|
|
1798
|
+
return schema["enum"][0];
|
|
1663
1799
|
}
|
|
1664
1800
|
if (CONST_KEY in schema) {
|
|
1665
|
-
return schema
|
|
1801
|
+
return schema["const"];
|
|
1666
1802
|
}
|
|
1667
1803
|
throw new Error("schema cannot be inferred as a constant");
|
|
1668
1804
|
}
|
|
@@ -1678,28 +1814,28 @@
|
|
|
1678
1814
|
function optionsList(schema) {
|
|
1679
1815
|
// enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
|
|
1680
1816
|
// Cast the type to include enumNames so the feature still works.
|
|
1681
|
-
|
|
1817
|
+
var schemaWithEnumNames = schema;
|
|
1682
1818
|
if (schemaWithEnumNames.enumNames && "development" !== "production") {
|
|
1683
1819
|
console.warn("The enumNames property is deprecated and may be removed in a future major release.");
|
|
1684
1820
|
}
|
|
1685
|
-
if (schema
|
|
1686
|
-
return schema
|
|
1687
|
-
|
|
1821
|
+
if (schema["enum"]) {
|
|
1822
|
+
return schema["enum"].map(function (value, i) {
|
|
1823
|
+
var label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
|
|
1688
1824
|
return {
|
|
1689
|
-
label,
|
|
1690
|
-
value
|
|
1825
|
+
label: label,
|
|
1826
|
+
value: value
|
|
1691
1827
|
};
|
|
1692
1828
|
});
|
|
1693
1829
|
}
|
|
1694
|
-
|
|
1695
|
-
return altSchemas && altSchemas.map(aSchemaDef
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1830
|
+
var altSchemas = schema.oneOf || schema.anyOf;
|
|
1831
|
+
return altSchemas && altSchemas.map(function (aSchemaDef) {
|
|
1832
|
+
var aSchema = aSchemaDef;
|
|
1833
|
+
var value = toConstant(aSchema);
|
|
1834
|
+
var label = aSchema.title || String(value);
|
|
1699
1835
|
return {
|
|
1700
1836
|
schema: aSchema,
|
|
1701
|
-
label,
|
|
1702
|
-
value
|
|
1837
|
+
label: label,
|
|
1838
|
+
value: value
|
|
1703
1839
|
};
|
|
1704
1840
|
});
|
|
1705
1841
|
}
|
|
@@ -1718,27 +1854,35 @@
|
|
|
1718
1854
|
if (!Array.isArray(order)) {
|
|
1719
1855
|
return properties;
|
|
1720
1856
|
}
|
|
1721
|
-
|
|
1722
|
-
prev
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1857
|
+
var arrayToHash = function arrayToHash(arr) {
|
|
1858
|
+
return arr.reduce(function (prev, curr) {
|
|
1859
|
+
prev[curr] = true;
|
|
1860
|
+
return prev;
|
|
1861
|
+
}, {});
|
|
1862
|
+
};
|
|
1863
|
+
var errorPropList = function errorPropList(arr) {
|
|
1864
|
+
return arr.length > 1 ? "properties '" + arr.join("', '") + "'" : "property '" + arr[0] + "'";
|
|
1865
|
+
};
|
|
1866
|
+
var propertyHash = arrayToHash(properties);
|
|
1867
|
+
var orderFiltered = order.filter(function (prop) {
|
|
1868
|
+
return prop === "*" || propertyHash[prop];
|
|
1869
|
+
});
|
|
1870
|
+
var orderHash = arrayToHash(orderFiltered);
|
|
1871
|
+
var rest = properties.filter(function (prop) {
|
|
1872
|
+
return !orderHash[prop];
|
|
1873
|
+
});
|
|
1874
|
+
var restIndex = orderFiltered.indexOf("*");
|
|
1731
1875
|
if (restIndex === -1) {
|
|
1732
1876
|
if (rest.length) {
|
|
1733
|
-
throw new Error(
|
|
1877
|
+
throw new Error("uiSchema order list does not contain " + errorPropList(rest));
|
|
1734
1878
|
}
|
|
1735
1879
|
return orderFiltered;
|
|
1736
1880
|
}
|
|
1737
1881
|
if (restIndex !== orderFiltered.lastIndexOf("*")) {
|
|
1738
1882
|
throw new Error("uiSchema order list contains more than one wildcard item");
|
|
1739
1883
|
}
|
|
1740
|
-
|
|
1741
|
-
complete.splice(restIndex, 1
|
|
1884
|
+
var complete = [].concat(orderFiltered);
|
|
1885
|
+
complete.splice.apply(complete, [restIndex, 1].concat(rest));
|
|
1742
1886
|
return complete;
|
|
1743
1887
|
}
|
|
1744
1888
|
|
|
@@ -1749,7 +1893,7 @@
|
|
|
1749
1893
|
* @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
|
|
1750
1894
|
*/
|
|
1751
1895
|
function pad(num, width) {
|
|
1752
|
-
|
|
1896
|
+
var s = String(num);
|
|
1753
1897
|
while (s.length < width) {
|
|
1754
1898
|
s = "0" + s;
|
|
1755
1899
|
}
|
|
@@ -1777,7 +1921,7 @@
|
|
|
1777
1921
|
second: includeTime ? -1 : 0
|
|
1778
1922
|
};
|
|
1779
1923
|
}
|
|
1780
|
-
|
|
1924
|
+
var date = new Date(dateString);
|
|
1781
1925
|
if (Number.isNaN(date.getTime())) {
|
|
1782
1926
|
throw new Error("Unable to parse date " + dateString);
|
|
1783
1927
|
}
|
|
@@ -1791,7 +1935,7 @@
|
|
|
1791
1935
|
};
|
|
1792
1936
|
}
|
|
1793
1937
|
|
|
1794
|
-
|
|
1938
|
+
var nums = /*#__PURE__*/new Set(["number", "integer"]);
|
|
1795
1939
|
/** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
|
|
1796
1940
|
* values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
|
|
1797
1941
|
* an empty string, then the `emptyValue` from the `options` is returned, falling back to undefined.
|
|
@@ -1802,11 +1946,9 @@
|
|
|
1802
1946
|
* @returns - The `value` converted to the proper type
|
|
1803
1947
|
*/
|
|
1804
1948
|
function processSelectValue(schema, value, options) {
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
items
|
|
1809
|
-
} = schema;
|
|
1949
|
+
var schemaEnum = schema["enum"],
|
|
1950
|
+
type = schema.type,
|
|
1951
|
+
items = schema.items;
|
|
1810
1952
|
if (value === "") {
|
|
1811
1953
|
return options && options.emptyValue !== undefined ? options.emptyValue : undefined;
|
|
1812
1954
|
}
|
|
@@ -1822,10 +1964,14 @@
|
|
|
1822
1964
|
// If type is undefined, but an enum is present, try and infer the type from
|
|
1823
1965
|
// the enum values
|
|
1824
1966
|
if (Array.isArray(schemaEnum)) {
|
|
1825
|
-
if (schemaEnum.every(
|
|
1967
|
+
if (schemaEnum.every(function (x) {
|
|
1968
|
+
return nums.has(guessType(x));
|
|
1969
|
+
})) {
|
|
1826
1970
|
return asNumber(value);
|
|
1827
1971
|
}
|
|
1828
|
-
if (schemaEnum.every(
|
|
1972
|
+
if (schemaEnum.every(function (x) {
|
|
1973
|
+
return guessType(x) === "boolean";
|
|
1974
|
+
})) {
|
|
1829
1975
|
return value === "true";
|
|
1830
1976
|
}
|
|
1831
1977
|
}
|
|
@@ -1843,11 +1989,11 @@
|
|
|
1843
1989
|
*/
|
|
1844
1990
|
function schemaRequiresTrueValue(schema) {
|
|
1845
1991
|
// Check if const is a truthy value
|
|
1846
|
-
if (schema
|
|
1992
|
+
if (schema["const"]) {
|
|
1847
1993
|
return true;
|
|
1848
1994
|
}
|
|
1849
1995
|
// Check if an enum has a single value of true
|
|
1850
|
-
if (schema
|
|
1996
|
+
if (schema["enum"] && schema["enum"].length === 1 && schema["enum"][0] === true) {
|
|
1851
1997
|
return true;
|
|
1852
1998
|
}
|
|
1853
1999
|
// If anyOf has a single value, evaluate the subschema
|
|
@@ -1860,7 +2006,9 @@
|
|
|
1860
2006
|
}
|
|
1861
2007
|
// Evaluate each subschema in allOf, to see if one of them requires a true value
|
|
1862
2008
|
if (schema.allOf) {
|
|
1863
|
-
|
|
2009
|
+
var schemaSome = function schemaSome(subSchema) {
|
|
2010
|
+
return schemaRequiresTrueValue(subSchema);
|
|
2011
|
+
};
|
|
1864
2012
|
return schema.allOf.some(schemaSome);
|
|
1865
2013
|
}
|
|
1866
2014
|
return false;
|
|
@@ -1875,10 +2023,8 @@
|
|
|
1875
2023
|
* @returns - True if the component should be re-rendered, false otherwise
|
|
1876
2024
|
*/
|
|
1877
2025
|
function shouldRender(component, nextProps, nextState) {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
state
|
|
1881
|
-
} = component;
|
|
2026
|
+
var props = component.props,
|
|
2027
|
+
state = component.state;
|
|
1882
2028
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
1883
2029
|
}
|
|
1884
2030
|
|
|
@@ -1893,16 +2039,17 @@
|
|
|
1893
2039
|
if (time === void 0) {
|
|
1894
2040
|
time = true;
|
|
1895
2041
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
hour = 0,
|
|
1901
|
-
minute =
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2042
|
+
var year = dateObject.year,
|
|
2043
|
+
month = dateObject.month,
|
|
2044
|
+
day = dateObject.day,
|
|
2045
|
+
_dateObject$hour = dateObject.hour,
|
|
2046
|
+
hour = _dateObject$hour === void 0 ? 0 : _dateObject$hour,
|
|
2047
|
+
_dateObject$minute = dateObject.minute,
|
|
2048
|
+
minute = _dateObject$minute === void 0 ? 0 : _dateObject$minute,
|
|
2049
|
+
_dateObject$second = dateObject.second,
|
|
2050
|
+
second = _dateObject$second === void 0 ? 0 : _dateObject$second;
|
|
2051
|
+
var utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
|
|
2052
|
+
var datetime = new Date(utcTime).toJSON();
|
|
1906
2053
|
return time ? datetime : datetime.slice(0, 10);
|
|
1907
2054
|
}
|
|
1908
2055
|
|
|
@@ -1920,15 +2067,15 @@
|
|
|
1920
2067
|
// > should be a _valid local date and time string_ (not GMT)
|
|
1921
2068
|
// Note - date constructor passed local ISO-8601 does not correctly
|
|
1922
2069
|
// change time to UTC in node pre-8
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
return
|
|
2070
|
+
var date = new Date(jsonDate);
|
|
2071
|
+
var yyyy = pad(date.getFullYear(), 4);
|
|
2072
|
+
var MM = pad(date.getMonth() + 1, 2);
|
|
2073
|
+
var dd = pad(date.getDate(), 2);
|
|
2074
|
+
var hh = pad(date.getHours(), 2);
|
|
2075
|
+
var mm = pad(date.getMinutes(), 2);
|
|
2076
|
+
var ss = pad(date.getSeconds(), 2);
|
|
2077
|
+
var SSS = pad(date.getMilliseconds(), 3);
|
|
2078
|
+
return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
|
|
1932
2079
|
}
|
|
1933
2080
|
|
|
1934
2081
|
exports.ADDITIONAL_PROPERTIES_KEY = ADDITIONAL_PROPERTIES_KEY;
|
|
@@ -1941,6 +2088,7 @@
|
|
|
1941
2088
|
exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
|
|
1942
2089
|
exports.ENUM_KEY = ENUM_KEY;
|
|
1943
2090
|
exports.ERRORS_KEY = ERRORS_KEY;
|
|
2091
|
+
exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
|
|
1944
2092
|
exports.ID_KEY = ID_KEY;
|
|
1945
2093
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
1946
2094
|
exports.NAME_KEY = NAME_KEY;
|