@rjsf/utils 5.10.0 → 5.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/utils.cjs.development.js +775 -971
- 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 +774 -970
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +778 -974
- 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 +8 -8
|
@@ -14,6 +14,7 @@ var isString = require('lodash/isString');
|
|
|
14
14
|
var reduce = require('lodash/reduce');
|
|
15
15
|
var times = require('lodash/times');
|
|
16
16
|
var set = require('lodash/set');
|
|
17
|
+
var forEach = require('lodash/forEach');
|
|
17
18
|
var mergeAllOf = require('json-schema-merge-allof');
|
|
18
19
|
var union = require('lodash/union');
|
|
19
20
|
var isEqual = require('lodash/isEqual');
|
|
@@ -23,7 +24,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
23
24
|
var react = require('react');
|
|
24
25
|
var ReactIs = require('react-is');
|
|
25
26
|
var toPath = require('lodash/toPath');
|
|
26
|
-
var forEach = require('lodash/forEach');
|
|
27
27
|
|
|
28
28
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
29
29
|
|
|
@@ -39,13 +39,13 @@ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
|
|
|
39
39
|
var reduce__default = /*#__PURE__*/_interopDefaultLegacy(reduce);
|
|
40
40
|
var times__default = /*#__PURE__*/_interopDefaultLegacy(times);
|
|
41
41
|
var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
|
|
42
|
+
var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
|
|
42
43
|
var mergeAllOf__default = /*#__PURE__*/_interopDefaultLegacy(mergeAllOf);
|
|
43
44
|
var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
|
|
44
45
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
45
46
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
46
47
|
var ReactIs__default = /*#__PURE__*/_interopDefaultLegacy(ReactIs);
|
|
47
48
|
var toPath__default = /*#__PURE__*/_interopDefaultLegacy(toPath);
|
|
48
|
-
var forEach__default = /*#__PURE__*/_interopDefaultLegacy(forEach);
|
|
49
49
|
|
|
50
50
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
51
51
|
* the type `object` but is NOT null, an array or a File.
|
|
@@ -107,103 +107,42 @@ function asNumber(value) {
|
|
|
107
107
|
// specific precision or number of significant digits)
|
|
108
108
|
return value;
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const n = Number(value);
|
|
111
|
+
const valid = typeof n === 'number' && !Number.isNaN(n);
|
|
112
112
|
return valid ? n : value;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
function _defineProperties(target, props) {
|
|
116
|
-
for (var i = 0; i < props.length; i++) {
|
|
117
|
-
var descriptor = props[i];
|
|
118
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
119
|
-
descriptor.configurable = true;
|
|
120
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
121
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
125
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
126
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
127
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
128
|
-
writable: false
|
|
129
|
-
});
|
|
130
|
-
return Constructor;
|
|
131
|
-
}
|
|
132
|
-
function _extends() {
|
|
133
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
134
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
135
|
-
var source = arguments[i];
|
|
136
|
-
for (var key in source) {
|
|
137
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
138
|
-
target[key] = source[key];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return target;
|
|
143
|
-
};
|
|
144
|
-
return _extends.apply(this, arguments);
|
|
145
|
-
}
|
|
146
|
-
function _objectDestructuringEmpty(obj) {
|
|
147
|
-
if (obj == null) throw new TypeError("Cannot destructure " + obj);
|
|
148
|
-
}
|
|
149
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
150
|
-
if (source == null) return {};
|
|
151
|
-
var target = {};
|
|
152
|
-
var sourceKeys = Object.keys(source);
|
|
153
|
-
var key, i;
|
|
154
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
155
|
-
key = sourceKeys[i];
|
|
156
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
157
|
-
target[key] = source[key];
|
|
158
|
-
}
|
|
159
|
-
return target;
|
|
160
|
-
}
|
|
161
|
-
function _toPrimitive(input, hint) {
|
|
162
|
-
if (typeof input !== "object" || input === null) return input;
|
|
163
|
-
var prim = input[Symbol.toPrimitive];
|
|
164
|
-
if (prim !== undefined) {
|
|
165
|
-
var res = prim.call(input, hint || "default");
|
|
166
|
-
if (typeof res !== "object") return res;
|
|
167
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
168
|
-
}
|
|
169
|
-
return (hint === "string" ? String : Number)(input);
|
|
170
|
-
}
|
|
171
|
-
function _toPropertyKey(arg) {
|
|
172
|
-
var key = _toPrimitive(arg, "string");
|
|
173
|
-
return typeof key === "symbol" ? key : String(key);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
115
|
/** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
|
|
177
116
|
* utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
|
|
178
117
|
* `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
|
|
179
118
|
* utility.
|
|
180
119
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
120
|
+
const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
|
|
121
|
+
const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
|
|
122
|
+
const ALL_OF_KEY = 'allOf';
|
|
123
|
+
const ANY_OF_KEY = 'anyOf';
|
|
124
|
+
const CONST_KEY = 'const';
|
|
125
|
+
const DEFAULT_KEY = 'default';
|
|
126
|
+
const DEFINITIONS_KEY = 'definitions';
|
|
127
|
+
const DEPENDENCIES_KEY = 'dependencies';
|
|
128
|
+
const ENUM_KEY = 'enum';
|
|
129
|
+
const ERRORS_KEY = '__errors';
|
|
130
|
+
const ID_KEY = '$id';
|
|
131
|
+
const IF_KEY = 'if';
|
|
132
|
+
const ITEMS_KEY = 'items';
|
|
133
|
+
const JUNK_OPTION_ID = '_$junk_option_schema_id$_';
|
|
134
|
+
const NAME_KEY = '$name';
|
|
135
|
+
const ONE_OF_KEY = 'oneOf';
|
|
136
|
+
const PROPERTIES_KEY = 'properties';
|
|
137
|
+
const REQUIRED_KEY = 'required';
|
|
138
|
+
const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
139
|
+
const REF_KEY = '$ref';
|
|
140
|
+
const RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
|
|
141
|
+
const ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
|
|
142
|
+
const UI_FIELD_KEY = 'ui:field';
|
|
143
|
+
const UI_WIDGET_KEY = 'ui:widget';
|
|
144
|
+
const UI_OPTIONS_KEY = 'ui:options';
|
|
145
|
+
const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
|
|
207
146
|
|
|
208
147
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
209
148
|
* stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
|
|
@@ -212,27 +151,26 @@ var UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
|
|
|
212
151
|
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
213
152
|
* @returns - An object containing all the `ui:xxx` options with the `ui:` stripped off along with all `globalOptions`
|
|
214
153
|
*/
|
|
215
|
-
function getUiOptions(uiSchema, globalOptions) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
if (globalOptions === void 0) {
|
|
220
|
-
globalOptions = {};
|
|
221
|
-
}
|
|
222
|
-
return Object.keys(uiSchema).filter(function (key) {
|
|
223
|
-
return key.indexOf('ui:') === 0;
|
|
224
|
-
}).reduce(function (options, key) {
|
|
225
|
-
var _extends2;
|
|
226
|
-
var value = uiSchema[key];
|
|
154
|
+
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
155
|
+
return Object.keys(uiSchema).filter(key => key.indexOf('ui:') === 0).reduce((options, key) => {
|
|
156
|
+
const value = uiSchema[key];
|
|
227
157
|
if (key === UI_WIDGET_KEY && isObject(value)) {
|
|
228
158
|
console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
|
|
229
159
|
return options;
|
|
230
160
|
}
|
|
231
161
|
if (key === UI_OPTIONS_KEY && isObject(value)) {
|
|
232
|
-
return
|
|
162
|
+
return {
|
|
163
|
+
...options,
|
|
164
|
+
...value
|
|
165
|
+
};
|
|
233
166
|
}
|
|
234
|
-
return
|
|
235
|
-
|
|
167
|
+
return {
|
|
168
|
+
...options,
|
|
169
|
+
[key.substring(3)]: value
|
|
170
|
+
};
|
|
171
|
+
}, {
|
|
172
|
+
...globalOptions
|
|
173
|
+
});
|
|
236
174
|
}
|
|
237
175
|
|
|
238
176
|
/** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
|
|
@@ -244,16 +182,13 @@ function getUiOptions(uiSchema, globalOptions) {
|
|
|
244
182
|
* @param [formData] - The formData for the field
|
|
245
183
|
* @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
|
|
246
184
|
*/
|
|
247
|
-
function canExpand(schema, uiSchema, formData) {
|
|
248
|
-
if (uiSchema === void 0) {
|
|
249
|
-
uiSchema = {};
|
|
250
|
-
}
|
|
185
|
+
function canExpand(schema, uiSchema = {}, formData) {
|
|
251
186
|
if (!schema.additionalProperties) {
|
|
252
187
|
return false;
|
|
253
188
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
189
|
+
const {
|
|
190
|
+
expandable = true
|
|
191
|
+
} = getUiOptions(uiSchema);
|
|
257
192
|
if (expandable === false) {
|
|
258
193
|
return expandable;
|
|
259
194
|
}
|
|
@@ -271,21 +206,30 @@ function canExpand(schema, uiSchema, formData) {
|
|
|
271
206
|
* @returns - A `FormValidation` object based on the `formData` structure
|
|
272
207
|
*/
|
|
273
208
|
function createErrorHandler(formData) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
209
|
+
const handler = {
|
|
210
|
+
// We store the list of errors for this node in a property named __errors
|
|
211
|
+
// to avoid name collision with a possible sub schema field named
|
|
212
|
+
// 'errors' (see `utils.toErrorSchema`).
|
|
213
|
+
[ERRORS_KEY]: [],
|
|
214
|
+
addError(message) {
|
|
215
|
+
this[ERRORS_KEY].push(message);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
278
218
|
if (Array.isArray(formData)) {
|
|
279
|
-
return formData.reduce(
|
|
280
|
-
|
|
281
|
-
|
|
219
|
+
return formData.reduce((acc, value, key) => {
|
|
220
|
+
return {
|
|
221
|
+
...acc,
|
|
222
|
+
[key]: createErrorHandler(value)
|
|
223
|
+
};
|
|
282
224
|
}, handler);
|
|
283
225
|
}
|
|
284
226
|
if (isPlainObject__default["default"](formData)) {
|
|
285
|
-
|
|
286
|
-
return Object.keys(formObject).reduce(
|
|
287
|
-
|
|
288
|
-
|
|
227
|
+
const formObject = formData;
|
|
228
|
+
return Object.keys(formObject).reduce((acc, key) => {
|
|
229
|
+
return {
|
|
230
|
+
...acc,
|
|
231
|
+
[key]: createErrorHandler(formObject[key])
|
|
232
|
+
};
|
|
289
233
|
}, handler);
|
|
290
234
|
}
|
|
291
235
|
return handler;
|
|
@@ -299,7 +243,7 @@ function createErrorHandler(formData) {
|
|
|
299
243
|
* @returns - True if the `a` and `b` are deeply equal, false otherwise
|
|
300
244
|
*/
|
|
301
245
|
function deepEquals(a, b) {
|
|
302
|
-
return isEqualWith__default["default"](a, b,
|
|
246
|
+
return isEqualWith__default["default"](a, b, (obj, other) => {
|
|
303
247
|
if (typeof obj === 'function' && typeof other === 'function') {
|
|
304
248
|
// Assume all functions are equivalent
|
|
305
249
|
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
@@ -318,8 +262,8 @@ function deepEquals(a, b) {
|
|
|
318
262
|
* value from `object[key]`
|
|
319
263
|
*/
|
|
320
264
|
function splitKeyElementFromObject(key, object) {
|
|
321
|
-
|
|
322
|
-
|
|
265
|
+
const value = object[key];
|
|
266
|
+
const remaining = omit__default["default"](object, [key]);
|
|
323
267
|
return [remaining, value];
|
|
324
268
|
}
|
|
325
269
|
/** Given the name of a `$ref` from within a schema, using the `rootSchema`, look up and return the sub-schema using the
|
|
@@ -331,28 +275,26 @@ function splitKeyElementFromObject(key, object) {
|
|
|
331
275
|
* @returns - The sub-schema within the `rootSchema` which matches the `$ref` if it exists
|
|
332
276
|
* @throws - Error indicating that no schema for that reference exists
|
|
333
277
|
*/
|
|
334
|
-
function findSchemaDefinition($ref, rootSchema) {
|
|
335
|
-
|
|
336
|
-
rootSchema = {};
|
|
337
|
-
}
|
|
338
|
-
var ref = $ref || '';
|
|
278
|
+
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
279
|
+
let ref = $ref || '';
|
|
339
280
|
if (ref.startsWith('#')) {
|
|
340
281
|
// Decode URI fragment representation.
|
|
341
282
|
ref = decodeURIComponent(ref.substring(1));
|
|
342
283
|
} else {
|
|
343
|
-
throw new Error(
|
|
284
|
+
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
344
285
|
}
|
|
345
|
-
|
|
286
|
+
const current = jsonpointer__default["default"].get(rootSchema, ref);
|
|
346
287
|
if (current === undefined) {
|
|
347
|
-
throw new Error(
|
|
288
|
+
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
348
289
|
}
|
|
349
290
|
if (current[REF_KEY]) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
theRef = _splitKeyElementFromO[1];
|
|
353
|
-
var subSchema = findSchemaDefinition(theRef, rootSchema);
|
|
291
|
+
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
292
|
+
const subSchema = findSchemaDefinition(theRef, rootSchema);
|
|
354
293
|
if (Object.keys(remaining).length > 0) {
|
|
355
|
-
return
|
|
294
|
+
return {
|
|
295
|
+
...remaining,
|
|
296
|
+
...subSchema
|
|
297
|
+
};
|
|
356
298
|
}
|
|
357
299
|
return subSchema;
|
|
358
300
|
}
|
|
@@ -377,12 +319,12 @@ function getMatchingOption(validator, formData, options, rootSchema, discriminat
|
|
|
377
319
|
if (formData === undefined) {
|
|
378
320
|
return 0;
|
|
379
321
|
}
|
|
380
|
-
for (
|
|
381
|
-
|
|
322
|
+
for (let i = 0; i < options.length; i++) {
|
|
323
|
+
const option = options[i];
|
|
382
324
|
// If we have a discriminator field, then we will use this to make the determination
|
|
383
325
|
if (discriminatorField && has__default["default"](option, [PROPERTIES_KEY, discriminatorField])) {
|
|
384
|
-
|
|
385
|
-
|
|
326
|
+
const value = get__default["default"](formData, discriminatorField);
|
|
327
|
+
const discriminator = get__default["default"](option, [PROPERTIES_KEY, discriminatorField], {});
|
|
386
328
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
387
329
|
return i;
|
|
388
330
|
}
|
|
@@ -397,18 +339,18 @@ function getMatchingOption(validator, formData, options, rootSchema, discriminat
|
|
|
397
339
|
//
|
|
398
340
|
// Create an "anyOf" schema that requires at least one of the keys in the
|
|
399
341
|
// "properties" object
|
|
400
|
-
|
|
401
|
-
anyOf: Object.keys(option[PROPERTIES_KEY]).map(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
405
|
-
})
|
|
342
|
+
const requiresAnyOf = {
|
|
343
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map(key => ({
|
|
344
|
+
required: [key]
|
|
345
|
+
}))
|
|
406
346
|
};
|
|
407
|
-
|
|
347
|
+
let augmentedSchema;
|
|
408
348
|
// If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
|
|
409
349
|
if (option.anyOf) {
|
|
410
350
|
// Create a shallow clone of the option
|
|
411
|
-
|
|
351
|
+
const {
|
|
352
|
+
...shallowClone
|
|
353
|
+
} = option;
|
|
412
354
|
if (!shallowClone.allOf) {
|
|
413
355
|
shallowClone.allOf = [];
|
|
414
356
|
} else {
|
|
@@ -455,12 +397,12 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
455
397
|
* @returns - The `discriminator.propertyName` if it exists in the schema, otherwise `undefined`
|
|
456
398
|
*/
|
|
457
399
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
458
|
-
|
|
459
|
-
|
|
400
|
+
let discriminator;
|
|
401
|
+
const maybeString = get__default["default"](schema, 'discriminator.propertyName', undefined);
|
|
460
402
|
if (isString__default["default"](maybeString)) {
|
|
461
403
|
discriminator = maybeString;
|
|
462
404
|
} else if (maybeString !== undefined) {
|
|
463
|
-
console.warn(
|
|
405
|
+
console.warn(`Expecting discriminator to be a string, got "${typeof maybeString}" instead`);
|
|
464
406
|
}
|
|
465
407
|
return discriminator;
|
|
466
408
|
}
|
|
@@ -506,20 +448,20 @@ function guessType(value) {
|
|
|
506
448
|
* @returns - The type of the schema
|
|
507
449
|
*/
|
|
508
450
|
function getSchemaType(schema) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
451
|
+
let {
|
|
452
|
+
type
|
|
453
|
+
} = schema;
|
|
454
|
+
if (!type && schema.const) {
|
|
455
|
+
return guessType(schema.const);
|
|
512
456
|
}
|
|
513
|
-
if (!type && schema
|
|
457
|
+
if (!type && schema.enum) {
|
|
514
458
|
return 'string';
|
|
515
459
|
}
|
|
516
460
|
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
517
461
|
return 'object';
|
|
518
462
|
}
|
|
519
463
|
if (Array.isArray(type) && type.length === 2 && type.includes('null')) {
|
|
520
|
-
type = type.find(
|
|
521
|
-
return type !== 'null';
|
|
522
|
-
});
|
|
464
|
+
type = type.find(type => type !== 'null');
|
|
523
465
|
}
|
|
524
466
|
return type;
|
|
525
467
|
}
|
|
@@ -533,9 +475,9 @@ function getSchemaType(schema) {
|
|
|
533
475
|
* @returns - The merged schema object
|
|
534
476
|
*/
|
|
535
477
|
function mergeSchemas(obj1, obj2) {
|
|
536
|
-
|
|
537
|
-
return Object.keys(obj2).reduce(
|
|
538
|
-
|
|
478
|
+
const acc = Object.assign({}, obj1); // Prevent mutation of source object.
|
|
479
|
+
return Object.keys(obj2).reduce((acc, key) => {
|
|
480
|
+
const left = obj1 ? obj1[key] : {},
|
|
539
481
|
right = obj2[key];
|
|
540
482
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
541
483
|
acc[key] = mergeSchemas(left, right);
|
|
@@ -549,12 +491,6 @@ function mergeSchemas(obj1, obj2) {
|
|
|
549
491
|
}, acc);
|
|
550
492
|
}
|
|
551
493
|
|
|
552
|
-
var _excluded$2 = ["if", "then", "else"],
|
|
553
|
-
_excluded2$1 = ["$ref"],
|
|
554
|
-
_excluded3 = ["allOf"],
|
|
555
|
-
_excluded4 = ["oneOf", "anyOf"],
|
|
556
|
-
_excluded5 = ["dependencies"],
|
|
557
|
-
_excluded6 = ["oneOf"];
|
|
558
494
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
559
495
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
560
496
|
* potentially recursive resolution.
|
|
@@ -565,10 +501,7 @@ var _excluded$2 = ["if", "then", "else"],
|
|
|
565
501
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
566
502
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
567
503
|
*/
|
|
568
|
-
function retrieveSchema(validator, schema, rootSchema, rawFormData) {
|
|
569
|
-
if (rootSchema === void 0) {
|
|
570
|
-
rootSchema = {};
|
|
571
|
-
}
|
|
504
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
572
505
|
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
573
506
|
}
|
|
574
507
|
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
@@ -584,13 +517,15 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
|
|
|
584
517
|
* @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
|
|
585
518
|
*/
|
|
586
519
|
function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
520
|
+
const {
|
|
521
|
+
if: expression,
|
|
522
|
+
then,
|
|
523
|
+
else: otherwise,
|
|
524
|
+
...resolvedSchemaLessConditional
|
|
525
|
+
} = schema;
|
|
526
|
+
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
527
|
+
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
528
|
+
let schemas = [];
|
|
594
529
|
if (expandAllBranches) {
|
|
595
530
|
if (then && typeof then !== 'boolean') {
|
|
596
531
|
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches));
|
|
@@ -599,19 +534,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
599
534
|
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches));
|
|
600
535
|
}
|
|
601
536
|
} else {
|
|
602
|
-
|
|
537
|
+
const conditionalSchema = conditionValue ? then : otherwise;
|
|
603
538
|
if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
|
|
604
539
|
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches));
|
|
605
540
|
}
|
|
606
541
|
}
|
|
607
542
|
if (schemas.length) {
|
|
608
|
-
resolvedSchemas = schemas.map(
|
|
609
|
-
return mergeSchemas(resolvedSchemaLessConditional, s);
|
|
610
|
-
});
|
|
543
|
+
resolvedSchemas = schemas.map(s => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
611
544
|
}
|
|
612
|
-
return resolvedSchemas.flatMap(
|
|
613
|
-
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
614
|
-
});
|
|
545
|
+
return resolvedSchemas.flatMap(s => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches));
|
|
615
546
|
}
|
|
616
547
|
/** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
|
|
617
548
|
* `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
|
|
@@ -628,19 +559,13 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, form
|
|
|
628
559
|
* @returns - The list of all permutations of schemas for a set of `xxxOf`s
|
|
629
560
|
*/
|
|
630
561
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
631
|
-
|
|
562
|
+
const allPermutations = listOfLists.reduce((permutations, list) => {
|
|
632
563
|
// When there are more than one set of schemas for a row, duplicate the set of permutations and add in the values
|
|
633
564
|
if (list.length > 1) {
|
|
634
|
-
return list.flatMap(
|
|
635
|
-
return times__default["default"](permutations.length, function (i) {
|
|
636
|
-
return [].concat(permutations[i]).concat(element);
|
|
637
|
-
});
|
|
638
|
-
});
|
|
565
|
+
return list.flatMap(element => times__default["default"](permutations.length, i => [...permutations[i]].concat(element)));
|
|
639
566
|
}
|
|
640
567
|
// Otherwise just push in the single value into the current set of permutations
|
|
641
|
-
permutations.forEach(
|
|
642
|
-
return permutation.push(list[0]);
|
|
643
|
-
});
|
|
568
|
+
permutations.forEach(permutation => permutation.push(list[0]));
|
|
644
569
|
return permutations;
|
|
645
570
|
}, [[]] // Start with an empty list
|
|
646
571
|
);
|
|
@@ -664,21 +589,18 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formDat
|
|
|
664
589
|
return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
|
|
665
590
|
}
|
|
666
591
|
if (DEPENDENCIES_KEY in schema) {
|
|
667
|
-
|
|
668
|
-
return resolvedSchemas.flatMap(
|
|
592
|
+
const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
|
|
593
|
+
return resolvedSchemas.flatMap(s => {
|
|
669
594
|
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
670
595
|
});
|
|
671
596
|
}
|
|
672
597
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
allOf: permutation
|
|
680
|
-
});
|
|
681
|
-
});
|
|
598
|
+
const allOfSchemaElements = schema.allOf.map(allOfSubschema => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches));
|
|
599
|
+
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
600
|
+
return allPermutations.map(permutation => ({
|
|
601
|
+
...schema,
|
|
602
|
+
allOf: permutation
|
|
603
|
+
}));
|
|
682
604
|
}
|
|
683
605
|
// No $ref or dependencies or allOf attribute was found, returning the original schema.
|
|
684
606
|
return [schema];
|
|
@@ -696,12 +618,48 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, formDat
|
|
|
696
618
|
*/
|
|
697
619
|
function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
698
620
|
// Drop the $ref property of the source schema.
|
|
699
|
-
|
|
700
|
-
|
|
621
|
+
const {
|
|
622
|
+
$ref,
|
|
623
|
+
...localSchema
|
|
624
|
+
} = schema;
|
|
701
625
|
// Retrieve the referenced schema definition.
|
|
702
|
-
|
|
626
|
+
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
703
627
|
// Update referenced schema definition with local schema properties.
|
|
704
|
-
return retrieveSchemaInternal(validator,
|
|
628
|
+
return retrieveSchemaInternal(validator, {
|
|
629
|
+
...refSchema,
|
|
630
|
+
...localSchema
|
|
631
|
+
}, rootSchema, formData, expandAllBranches);
|
|
632
|
+
}
|
|
633
|
+
/** Resolves all references within a schema's properties and array items.
|
|
634
|
+
*
|
|
635
|
+
* @param schema - The schema for which resolving all references is desired
|
|
636
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
637
|
+
* @returns - given schema will all references resolved
|
|
638
|
+
*/
|
|
639
|
+
function resolveAllReferences(schema, rootSchema) {
|
|
640
|
+
let resolvedSchema = schema;
|
|
641
|
+
// resolve top level ref
|
|
642
|
+
if (REF_KEY in resolvedSchema) {
|
|
643
|
+
const {
|
|
644
|
+
$ref,
|
|
645
|
+
...localSchema
|
|
646
|
+
} = resolvedSchema;
|
|
647
|
+
// Retrieve the referenced schema definition.
|
|
648
|
+
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
649
|
+
resolvedSchema = {
|
|
650
|
+
...refSchema,
|
|
651
|
+
...localSchema
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (PROPERTIES_KEY in resolvedSchema) {
|
|
655
|
+
forEach__default["default"](resolvedSchema[PROPERTIES_KEY], (value, key) => {
|
|
656
|
+
resolvedSchema[PROPERTIES_KEY][key] = resolveAllReferences(value, rootSchema);
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== 'boolean') {
|
|
660
|
+
resolvedSchema.items = resolveAllReferences(resolvedSchema.items, rootSchema);
|
|
661
|
+
}
|
|
662
|
+
return resolvedSchema;
|
|
705
663
|
}
|
|
706
664
|
/** Creates new 'properties' items for each key in the `formData`
|
|
707
665
|
*
|
|
@@ -713,28 +671,34 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, form
|
|
|
713
671
|
*/
|
|
714
672
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
715
673
|
// Clone the schema so that we don't ruin the consumer's original
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
674
|
+
const schema = {
|
|
675
|
+
...theSchema,
|
|
676
|
+
properties: {
|
|
677
|
+
...theSchema.properties
|
|
678
|
+
}
|
|
679
|
+
};
|
|
719
680
|
// make sure formData is an object
|
|
720
|
-
|
|
721
|
-
Object.keys(formData).forEach(
|
|
681
|
+
const formData = aFormData && isObject(aFormData) ? aFormData : {};
|
|
682
|
+
Object.keys(formData).forEach(key => {
|
|
722
683
|
if (key in schema.properties) {
|
|
723
684
|
// No need to stub, our schema already has the property
|
|
724
685
|
return;
|
|
725
686
|
}
|
|
726
|
-
|
|
687
|
+
let additionalProperties = {};
|
|
727
688
|
if (typeof schema.additionalProperties !== 'boolean') {
|
|
728
689
|
if (REF_KEY in schema.additionalProperties) {
|
|
729
690
|
additionalProperties = retrieveSchema(validator, {
|
|
730
691
|
$ref: get__default["default"](schema.additionalProperties, [REF_KEY])
|
|
731
692
|
}, rootSchema, formData);
|
|
732
693
|
} else if ('type' in schema.additionalProperties) {
|
|
733
|
-
additionalProperties =
|
|
694
|
+
additionalProperties = {
|
|
695
|
+
...schema.additionalProperties
|
|
696
|
+
};
|
|
734
697
|
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
735
|
-
additionalProperties =
|
|
736
|
-
type: 'object'
|
|
737
|
-
|
|
698
|
+
additionalProperties = {
|
|
699
|
+
type: 'object',
|
|
700
|
+
...schema.additionalProperties
|
|
701
|
+
};
|
|
738
702
|
} else {
|
|
739
703
|
additionalProperties = {
|
|
740
704
|
type: guessType(get__default["default"](formData, [key]))
|
|
@@ -766,36 +730,35 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
766
730
|
* @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
|
|
767
731
|
* resolved. Multiple schemas may be returned if `expandAllBranches` is true.
|
|
768
732
|
*/
|
|
769
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches) {
|
|
770
|
-
if (expandAllBranches === void 0) {
|
|
771
|
-
expandAllBranches = false;
|
|
772
|
-
}
|
|
733
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
773
734
|
if (!isObject(schema)) {
|
|
774
735
|
return [{}];
|
|
775
736
|
}
|
|
776
|
-
|
|
777
|
-
return resolvedSchemas.flatMap(
|
|
778
|
-
|
|
737
|
+
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
|
|
738
|
+
return resolvedSchemas.flatMap(s => {
|
|
739
|
+
let resolvedSchema = s;
|
|
779
740
|
if (IF_KEY in resolvedSchema) {
|
|
780
741
|
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
|
|
781
742
|
}
|
|
782
743
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
744
|
+
// resolve allOf schemas
|
|
745
|
+
if (expandAllBranches) {
|
|
746
|
+
return [...resolvedSchema.allOf];
|
|
747
|
+
}
|
|
783
748
|
try {
|
|
784
749
|
resolvedSchema = mergeAllOf__default["default"](resolvedSchema, {
|
|
785
750
|
deep: false
|
|
786
751
|
});
|
|
787
752
|
} catch (e) {
|
|
788
753
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
789
|
-
|
|
790
|
-
allOf
|
|
791
|
-
resolvedSchemaWithoutAllOf
|
|
792
|
-
|
|
793
|
-
return [resolvedSchemaWithoutAllOf].concat(allOf);
|
|
794
|
-
}
|
|
754
|
+
const {
|
|
755
|
+
allOf,
|
|
756
|
+
...resolvedSchemaWithoutAllOf
|
|
757
|
+
} = resolvedSchema;
|
|
795
758
|
return resolvedSchemaWithoutAllOf;
|
|
796
759
|
}
|
|
797
760
|
}
|
|
798
|
-
|
|
761
|
+
const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
799
762
|
if (hasAdditionalProperties) {
|
|
800
763
|
return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
|
|
801
764
|
}
|
|
@@ -815,11 +778,12 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
815
778
|
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
816
779
|
*/
|
|
817
780
|
function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
oneOf
|
|
821
|
-
anyOf
|
|
822
|
-
remaining
|
|
781
|
+
let anyOrOneOf;
|
|
782
|
+
const {
|
|
783
|
+
oneOf,
|
|
784
|
+
anyOf,
|
|
785
|
+
...remaining
|
|
786
|
+
} = schema;
|
|
823
787
|
if (Array.isArray(oneOf)) {
|
|
824
788
|
anyOrOneOf = oneOf;
|
|
825
789
|
} else if (Array.isArray(anyOf)) {
|
|
@@ -827,23 +791,17 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
827
791
|
}
|
|
828
792
|
if (anyOrOneOf) {
|
|
829
793
|
// Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
anyOrOneOf = anyOrOneOf.map(
|
|
833
|
-
|
|
834
|
-
// For this ref situation, don't expand all branches and just pick the first/only schema result
|
|
835
|
-
return resolveReference(validator, s, rootSchema, false, formData)[0];
|
|
836
|
-
}
|
|
837
|
-
return s;
|
|
794
|
+
const formData = rawFormData === undefined && expandAllBranches ? {} : rawFormData;
|
|
795
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
796
|
+
anyOrOneOf = anyOrOneOf.map(s => {
|
|
797
|
+
return resolveAllReferences(s, rootSchema);
|
|
838
798
|
});
|
|
839
799
|
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
840
|
-
|
|
800
|
+
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
841
801
|
if (expandAllBranches) {
|
|
842
|
-
return anyOrOneOf.map(
|
|
843
|
-
return _extends({}, remaining, item);
|
|
844
|
-
});
|
|
802
|
+
return anyOrOneOf.map(item => mergeSchemas(remaining, item));
|
|
845
803
|
}
|
|
846
|
-
schema =
|
|
804
|
+
schema = mergeSchemas(remaining, anyOrOneOf[option]);
|
|
847
805
|
}
|
|
848
806
|
return [schema];
|
|
849
807
|
}
|
|
@@ -860,12 +818,12 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
860
818
|
*/
|
|
861
819
|
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
862
820
|
// Drop the dependencies from the source schema.
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
821
|
+
const {
|
|
822
|
+
dependencies,
|
|
823
|
+
...remainingSchema
|
|
824
|
+
} = schema;
|
|
825
|
+
const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
|
|
826
|
+
return resolvedSchemas.flatMap(resolvedSchema => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData));
|
|
869
827
|
}
|
|
870
828
|
/** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
|
|
871
829
|
* `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
|
|
@@ -880,35 +838,24 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, f
|
|
|
880
838
|
* @returns - The schema with the `dependencies` resolved into it
|
|
881
839
|
*/
|
|
882
840
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
883
|
-
|
|
841
|
+
let schemas = [resolvedSchema];
|
|
884
842
|
// Process dependencies updating the local schema properties as appropriate.
|
|
885
|
-
|
|
843
|
+
for (const dependencyKey in dependencies) {
|
|
886
844
|
// Skip this dependency if its trigger property is not present.
|
|
887
845
|
if (!expandAllBranches && get__default["default"](formData, [dependencyKey]) === undefined) {
|
|
888
|
-
|
|
846
|
+
continue;
|
|
889
847
|
}
|
|
890
848
|
// Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
|
|
891
849
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
892
|
-
|
|
850
|
+
continue;
|
|
893
851
|
}
|
|
894
|
-
|
|
895
|
-
remainingDependencies = _splitKeyElementFromO[0],
|
|
896
|
-
dependencyValue = _splitKeyElementFromO[1];
|
|
852
|
+
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
|
|
897
853
|
if (Array.isArray(dependencyValue)) {
|
|
898
854
|
schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
|
|
899
855
|
} else if (isObject(dependencyValue)) {
|
|
900
856
|
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData);
|
|
901
857
|
}
|
|
902
|
-
return
|
|
903
|
-
v: schemas.flatMap(function (schema) {
|
|
904
|
-
return processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData);
|
|
905
|
-
})
|
|
906
|
-
};
|
|
907
|
-
};
|
|
908
|
-
for (var dependencyKey in dependencies) {
|
|
909
|
-
var _ret = _loop();
|
|
910
|
-
if (_ret === "continue") continue;
|
|
911
|
-
if (typeof _ret === "object") return _ret.v;
|
|
858
|
+
return schemas.flatMap(schema => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData));
|
|
912
859
|
}
|
|
913
860
|
return schemas;
|
|
914
861
|
}
|
|
@@ -922,10 +869,11 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
922
869
|
if (!additionallyRequired) {
|
|
923
870
|
return schema;
|
|
924
871
|
}
|
|
925
|
-
|
|
926
|
-
return
|
|
872
|
+
const required = Array.isArray(schema.required) ? Array.from(new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
873
|
+
return {
|
|
874
|
+
...schema,
|
|
927
875
|
required: required
|
|
928
|
-
}
|
|
876
|
+
};
|
|
929
877
|
}
|
|
930
878
|
/** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
|
|
931
879
|
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `withExactlyOneSubschema()` helper calls.
|
|
@@ -941,26 +889,26 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
941
889
|
* @returns - The list of schemas with the dependent schema resolved into them
|
|
942
890
|
*/
|
|
943
891
|
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
944
|
-
|
|
945
|
-
return dependentSchemas.flatMap(
|
|
946
|
-
|
|
947
|
-
|
|
892
|
+
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
|
|
893
|
+
return dependentSchemas.flatMap(dependent => {
|
|
894
|
+
const {
|
|
895
|
+
oneOf,
|
|
896
|
+
...dependentSchema
|
|
897
|
+
} = dependent;
|
|
948
898
|
schema = mergeSchemas(schema, dependentSchema);
|
|
949
899
|
// Since it does not contain oneOf, we return the original schema.
|
|
950
900
|
if (oneOf === undefined) {
|
|
951
901
|
return schema;
|
|
952
902
|
}
|
|
953
903
|
// Resolve $refs inside oneOf.
|
|
954
|
-
|
|
904
|
+
const resolvedOneOfs = oneOf.map(subschema => {
|
|
955
905
|
if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
|
|
956
906
|
return [subschema];
|
|
957
907
|
}
|
|
958
908
|
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
959
909
|
});
|
|
960
|
-
|
|
961
|
-
return allPermutations.flatMap(
|
|
962
|
-
return withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData);
|
|
963
|
-
});
|
|
910
|
+
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
911
|
+
return allPermutations.flatMap(resolvedOneOf => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData));
|
|
964
912
|
});
|
|
965
913
|
}
|
|
966
914
|
/** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
|
|
@@ -978,16 +926,19 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
978
926
|
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
979
927
|
*/
|
|
980
928
|
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
981
|
-
|
|
929
|
+
const validSubschemas = oneOf.filter(subschema => {
|
|
982
930
|
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
983
931
|
return false;
|
|
984
932
|
}
|
|
985
|
-
|
|
933
|
+
const {
|
|
934
|
+
[dependencyKey]: conditionPropertySchema
|
|
935
|
+
} = subschema.properties;
|
|
986
936
|
if (conditionPropertySchema) {
|
|
987
|
-
|
|
988
|
-
var conditionSchema = {
|
|
937
|
+
const conditionSchema = {
|
|
989
938
|
type: 'object',
|
|
990
|
-
properties:
|
|
939
|
+
properties: {
|
|
940
|
+
[dependencyKey]: conditionPropertySchema
|
|
941
|
+
}
|
|
991
942
|
};
|
|
992
943
|
return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
|
|
993
944
|
}
|
|
@@ -997,24 +948,22 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
997
948
|
console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
|
|
998
949
|
return [schema];
|
|
999
950
|
}
|
|
1000
|
-
return validSubschemas.flatMap(
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
951
|
+
return validSubschemas.flatMap(s => {
|
|
952
|
+
const subschema = s;
|
|
953
|
+
const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
|
|
954
|
+
const dependentSchema = {
|
|
955
|
+
...subschema,
|
|
1005
956
|
properties: dependentSubschema
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
return schemas.map(
|
|
1009
|
-
return mergeSchemas(schema, s);
|
|
1010
|
-
});
|
|
957
|
+
};
|
|
958
|
+
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches);
|
|
959
|
+
return schemas.map(s => mergeSchemas(schema, s));
|
|
1011
960
|
});
|
|
1012
961
|
}
|
|
1013
962
|
|
|
1014
963
|
/** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
|
|
1015
964
|
* the first item
|
|
1016
965
|
*/
|
|
1017
|
-
|
|
966
|
+
const JUNK_OPTION = {
|
|
1018
967
|
type: 'object',
|
|
1019
968
|
$id: JUNK_OPTION_ID,
|
|
1020
969
|
properties: {
|
|
@@ -1043,41 +992,38 @@ var JUNK_OPTION = {
|
|
|
1043
992
|
* @param formData - The form data associated with the schema, used to calculate the score
|
|
1044
993
|
* @returns - The score a schema against the formData
|
|
1045
994
|
*/
|
|
1046
|
-
function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
1047
|
-
|
|
1048
|
-
formData = {};
|
|
1049
|
-
}
|
|
1050
|
-
var totalScore = 0;
|
|
995
|
+
function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
996
|
+
let totalScore = 0;
|
|
1051
997
|
if (schema) {
|
|
1052
998
|
if (isObject__default["default"](schema.properties)) {
|
|
1053
|
-
totalScore += reduce__default["default"](schema.properties,
|
|
1054
|
-
|
|
999
|
+
totalScore += reduce__default["default"](schema.properties, (score, value, key) => {
|
|
1000
|
+
const formValue = get__default["default"](formData, key);
|
|
1055
1001
|
if (typeof value === 'boolean') {
|
|
1056
1002
|
return score;
|
|
1057
1003
|
}
|
|
1058
1004
|
if (has__default["default"](value, REF_KEY)) {
|
|
1059
|
-
|
|
1005
|
+
const newSchema = retrieveSchema(validator, value, rootSchema, formValue);
|
|
1060
1006
|
return score + calculateIndexScore(validator, rootSchema, newSchema, formValue || {});
|
|
1061
1007
|
}
|
|
1062
1008
|
if ((has__default["default"](value, ONE_OF_KEY) || has__default["default"](value, ANY_OF_KEY)) && formValue) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value,
|
|
1009
|
+
const key = has__default["default"](value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
1010
|
+
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
1011
|
+
return score + getClosestMatchingOption(validator, rootSchema, formValue, get__default["default"](value, key), -1, discriminator);
|
|
1066
1012
|
}
|
|
1067
1013
|
if (value.type === 'object') {
|
|
1068
1014
|
return score + calculateIndexScore(validator, rootSchema, value, formValue || {});
|
|
1069
1015
|
}
|
|
1070
1016
|
if (value.type === guessType(formValue)) {
|
|
1071
1017
|
// If the types match, then we bump the score by one
|
|
1072
|
-
|
|
1073
|
-
if (value
|
|
1018
|
+
let newScore = score + 1;
|
|
1019
|
+
if (value.default) {
|
|
1074
1020
|
// If the schema contains a readonly default value score the value that matches the default higher and
|
|
1075
1021
|
// any non-matching value lower
|
|
1076
|
-
newScore += formValue === value
|
|
1077
|
-
} else if (value
|
|
1022
|
+
newScore += formValue === value.default ? 1 : -1;
|
|
1023
|
+
} else if (value.const) {
|
|
1078
1024
|
// If the schema contains a const value score the value that matches the default higher and
|
|
1079
1025
|
// any non-matching value lower
|
|
1080
|
-
newScore += formValue === value
|
|
1026
|
+
newScore += formValue === value.const ? 1 : -1;
|
|
1081
1027
|
}
|
|
1082
1028
|
// TODO eventually, deal with enums/arrays
|
|
1083
1029
|
return newScore;
|
|
@@ -1112,21 +1058,15 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
1112
1058
|
* determine which option is selected
|
|
1113
1059
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
1114
1060
|
*/
|
|
1115
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption, discriminatorField) {
|
|
1116
|
-
if (selectedOption === void 0) {
|
|
1117
|
-
selectedOption = -1;
|
|
1118
|
-
}
|
|
1061
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1119
1062
|
// First resolve any refs in the options
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
return retrieveSchema(validator, option, rootSchema, formData);
|
|
1123
|
-
}
|
|
1124
|
-
return option;
|
|
1063
|
+
const resolvedOptions = options.map(option => {
|
|
1064
|
+
return resolveAllReferences(option, rootSchema);
|
|
1125
1065
|
});
|
|
1126
1066
|
// Reduce the array of options down to a list of the indexes that are considered matching options
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1067
|
+
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
1068
|
+
const testOptions = [JUNK_OPTION, option];
|
|
1069
|
+
const match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
1130
1070
|
// The match is the real option, so add its index to list of valid indexes
|
|
1131
1071
|
if (match === 1) {
|
|
1132
1072
|
validList.push(index);
|
|
@@ -1139,29 +1079,30 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1139
1079
|
}
|
|
1140
1080
|
if (!allValidIndexes.length) {
|
|
1141
1081
|
// No indexes were valid, so we'll score all the options, add all the indexes
|
|
1142
|
-
times__default["default"](resolvedOptions.length,
|
|
1143
|
-
return allValidIndexes.push(i);
|
|
1144
|
-
});
|
|
1082
|
+
times__default["default"](resolvedOptions.length, i => allValidIndexes.push(i));
|
|
1145
1083
|
}
|
|
1146
|
-
|
|
1084
|
+
const scoreCount = new Set();
|
|
1147
1085
|
// Score all the options in the list of valid indexes and return the index with the best score
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1086
|
+
const {
|
|
1087
|
+
bestIndex
|
|
1088
|
+
} = allValidIndexes.reduce((scoreData, index) => {
|
|
1089
|
+
const {
|
|
1090
|
+
bestScore
|
|
1091
|
+
} = scoreData;
|
|
1092
|
+
const option = resolvedOptions[index];
|
|
1093
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1094
|
+
scoreCount.add(score);
|
|
1095
|
+
if (score > bestScore) {
|
|
1096
|
+
return {
|
|
1097
|
+
bestIndex: index,
|
|
1098
|
+
bestScore: score
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
return scoreData;
|
|
1102
|
+
}, {
|
|
1103
|
+
bestIndex: selectedOption,
|
|
1104
|
+
bestScore: 0
|
|
1105
|
+
});
|
|
1165
1106
|
// if all scores are the same go with selectedOption
|
|
1166
1107
|
if (scoreCount.size === 1 && selectedOption >= 0) {
|
|
1167
1108
|
return selectedOption;
|
|
@@ -1176,9 +1117,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1176
1117
|
* @returns - True if there are fixed items in the schema, false otherwise
|
|
1177
1118
|
*/
|
|
1178
1119
|
function isFixedItems(schema) {
|
|
1179
|
-
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(
|
|
1180
|
-
return isObject(item);
|
|
1181
|
-
});
|
|
1120
|
+
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every(item => isObject(item));
|
|
1182
1121
|
}
|
|
1183
1122
|
|
|
1184
1123
|
/** Merges the `defaults` object of type `T` into the `formData` of type `T`
|
|
@@ -1197,13 +1136,10 @@ function isFixedItems(schema) {
|
|
|
1197
1136
|
* @param [mergeExtraArrayDefaults=false] - If true, any additional default array entries are appended onto the formData
|
|
1198
1137
|
* @returns - The resulting merged form data with defaults
|
|
1199
1138
|
*/
|
|
1200
|
-
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults) {
|
|
1201
|
-
if (mergeExtraArrayDefaults === void 0) {
|
|
1202
|
-
mergeExtraArrayDefaults = false;
|
|
1203
|
-
}
|
|
1139
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
1204
1140
|
if (Array.isArray(formData)) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1141
|
+
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
1142
|
+
const mapped = formData.map((value, idx) => {
|
|
1207
1143
|
if (defaultsArray[idx]) {
|
|
1208
1144
|
return mergeDefaultsWithFormData(defaultsArray[idx], value, mergeExtraArrayDefaults);
|
|
1209
1145
|
}
|
|
@@ -1211,13 +1147,13 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults)
|
|
|
1211
1147
|
});
|
|
1212
1148
|
// Merge any extra defaults when mergeExtraArrayDefaults is true
|
|
1213
1149
|
if (mergeExtraArrayDefaults && mapped.length < defaultsArray.length) {
|
|
1214
|
-
mapped.push
|
|
1150
|
+
mapped.push(...defaultsArray.slice(mapped.length));
|
|
1215
1151
|
}
|
|
1216
1152
|
return mapped;
|
|
1217
1153
|
}
|
|
1218
1154
|
if (isObject(formData)) {
|
|
1219
|
-
|
|
1220
|
-
return Object.keys(formData).reduce(
|
|
1155
|
+
const acc = Object.assign({}, defaults); // Prevent mutation of source object.
|
|
1156
|
+
return Object.keys(formData).reduce((acc, key) => {
|
|
1221
1157
|
acc[key] = mergeDefaultsWithFormData(defaults ? get__default["default"](defaults, key) : {}, get__default["default"](formData, key), mergeExtraArrayDefaults);
|
|
1222
1158
|
return acc;
|
|
1223
1159
|
}, acc);
|
|
@@ -1234,19 +1170,16 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults)
|
|
|
1234
1170
|
* NOTE: Uses shallow comparison for the duplicate checking.
|
|
1235
1171
|
* @returns - A new object that is the merge of the two given objects
|
|
1236
1172
|
*/
|
|
1237
|
-
function mergeObjects(obj1, obj2, concatArrays) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
}
|
|
1241
|
-
return Object.keys(obj2).reduce(function (acc, key) {
|
|
1242
|
-
var left = obj1 ? obj1[key] : {},
|
|
1173
|
+
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
1174
|
+
return Object.keys(obj2).reduce((acc, key) => {
|
|
1175
|
+
const left = obj1 ? obj1[key] : {},
|
|
1243
1176
|
right = obj2[key];
|
|
1244
1177
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
1245
1178
|
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1246
1179
|
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1247
|
-
|
|
1180
|
+
let toMerge = right;
|
|
1248
1181
|
if (concatArrays === 'preventDuplicates') {
|
|
1249
|
-
toMerge = right.reduce(
|
|
1182
|
+
toMerge = right.reduce((result, value) => {
|
|
1250
1183
|
if (!left.includes(value)) {
|
|
1251
1184
|
result.push(value);
|
|
1252
1185
|
}
|
|
@@ -1268,7 +1201,7 @@ function mergeObjects(obj1, obj2, concatArrays) {
|
|
|
1268
1201
|
* @returns - True if the `schema` has a single constant value, false otherwise
|
|
1269
1202
|
*/
|
|
1270
1203
|
function isConstant(schema) {
|
|
1271
|
-
return Array.isArray(schema
|
|
1204
|
+
return Array.isArray(schema.enum) && schema.enum.length === 1 || CONST_KEY in schema;
|
|
1272
1205
|
}
|
|
1273
1206
|
|
|
1274
1207
|
/** Checks to see if the `schema` combination represents a select
|
|
@@ -1278,19 +1211,14 @@ function isConstant(schema) {
|
|
|
1278
1211
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1279
1212
|
* @returns - True if schema contains a select, otherwise false
|
|
1280
1213
|
*/
|
|
1281
|
-
function isSelect(validator, theSchema, rootSchema) {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
var schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
|
|
1286
|
-
var altSchemas = schema.oneOf || schema.anyOf;
|
|
1287
|
-
if (Array.isArray(schema["enum"])) {
|
|
1214
|
+
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
1215
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, undefined);
|
|
1216
|
+
const altSchemas = schema.oneOf || schema.anyOf;
|
|
1217
|
+
if (Array.isArray(schema.enum)) {
|
|
1288
1218
|
return true;
|
|
1289
1219
|
}
|
|
1290
1220
|
if (Array.isArray(altSchemas)) {
|
|
1291
|
-
return altSchemas.every(
|
|
1292
|
-
return typeof altSchemas !== 'boolean' && isConstant(altSchemas);
|
|
1293
|
-
});
|
|
1221
|
+
return altSchemas.every(altSchemas => typeof altSchemas !== 'boolean' && isConstant(altSchemas));
|
|
1294
1222
|
}
|
|
1295
1223
|
return false;
|
|
1296
1224
|
}
|
|
@@ -1309,8 +1237,6 @@ function isMultiSelect(validator, schema, rootSchema) {
|
|
|
1309
1237
|
return isSelect(validator, schema.items, rootSchema);
|
|
1310
1238
|
}
|
|
1311
1239
|
|
|
1312
|
-
var _excluded$1 = ["oneOf"],
|
|
1313
|
-
_excluded2 = ["anyOf"];
|
|
1314
1240
|
/** Enum that indicates how `schema.additionalItems` should be handled by the `getInnerSchemaForArrayItem()` function.
|
|
1315
1241
|
*/
|
|
1316
1242
|
var AdditionalItemsHandling;
|
|
@@ -1334,16 +1260,10 @@ var AdditionalItemsHandling;
|
|
|
1334
1260
|
* @param [idx=-1] - Index, if non-negative, will be used to return the idx-th element in a `schema.items` array
|
|
1335
1261
|
* @returns - The best fit schema object from the `schema` given the `additionalItems` and `idx` modifiers
|
|
1336
1262
|
*/
|
|
1337
|
-
function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
|
|
1338
|
-
if (additionalItems === void 0) {
|
|
1339
|
-
additionalItems = AdditionalItemsHandling.Ignore;
|
|
1340
|
-
}
|
|
1341
|
-
if (idx === void 0) {
|
|
1342
|
-
idx = -1;
|
|
1343
|
-
}
|
|
1263
|
+
function getInnerSchemaForArrayItem(schema, additionalItems = AdditionalItemsHandling.Ignore, idx = -1) {
|
|
1344
1264
|
if (idx >= 0) {
|
|
1345
1265
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
1346
|
-
|
|
1266
|
+
const item = schema.items[idx];
|
|
1347
1267
|
if (typeof item !== 'boolean') {
|
|
1348
1268
|
return item;
|
|
1349
1269
|
}
|
|
@@ -1375,23 +1295,17 @@ function getInnerSchemaForArrayItem(schema, additionalItems, idx) {
|
|
|
1375
1295
|
* @param experimental_defaultFormStateBehavior - Optional configuration object, if provided, allows users to override
|
|
1376
1296
|
* default form state behavior
|
|
1377
1297
|
*/
|
|
1378
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields, experimental_defaultFormStateBehavior) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
if (experimental_defaultFormStateBehavior === void 0) {
|
|
1383
|
-
experimental_defaultFormStateBehavior = {};
|
|
1384
|
-
}
|
|
1385
|
-
var _experimental_default = experimental_defaultFormStateBehavior,
|
|
1386
|
-
_experimental_default2 = _experimental_default.emptyObjectFields,
|
|
1387
|
-
emptyObjectFields = _experimental_default2 === void 0 ? 'populateAllDefaults' : _experimental_default2;
|
|
1298
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1299
|
+
const {
|
|
1300
|
+
emptyObjectFields = 'populateAllDefaults'
|
|
1301
|
+
} = experimental_defaultFormStateBehavior;
|
|
1388
1302
|
if (includeUndefinedValues) {
|
|
1389
1303
|
obj[key] = computedDefault;
|
|
1390
1304
|
} else if (emptyObjectFields !== 'skipDefaults') {
|
|
1391
1305
|
if (isObject(computedDefault)) {
|
|
1392
1306
|
// If isParentRequired is undefined, then we are at the root level of the schema so defer to the requiredness of
|
|
1393
1307
|
// the field key itself in the `requiredField` list
|
|
1394
|
-
|
|
1308
|
+
const isSelfOrParentRequired = isParentRequired === undefined ? requiredFields.includes(key) : isParentRequired;
|
|
1395
1309
|
// Store computedDefault if it's a non-empty object(e.g. not {}) and satisfies certain conditions
|
|
1396
1310
|
// Condition 1: If computedDefault is not empty or if the key is a required field
|
|
1397
1311
|
// Condition 2: If the parent object is required or emptyObjectFields is not 'populateRequiredDefaults'
|
|
@@ -1424,100 +1338,98 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1424
1338
|
* @param [props.required] - Optional flag, if true, indicates this schema was required in the parent schema.
|
|
1425
1339
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1426
1340
|
*/
|
|
1427
|
-
function computeDefaults(validator, rawSchema,
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
experimental_defaultFormStateBehavior = _ref$experimental_def === void 0 ? undefined : _ref$experimental_def,
|
|
1439
|
-
required = _ref.required;
|
|
1440
|
-
var formData = isObject(rawFormData) ? rawFormData : {};
|
|
1441
|
-
var schema = isObject(rawSchema) ? rawSchema : {};
|
|
1341
|
+
function computeDefaults(validator, rawSchema, {
|
|
1342
|
+
parentDefaults,
|
|
1343
|
+
rawFormData,
|
|
1344
|
+
rootSchema = {},
|
|
1345
|
+
includeUndefinedValues = false,
|
|
1346
|
+
_recurseList = [],
|
|
1347
|
+
experimental_defaultFormStateBehavior = undefined,
|
|
1348
|
+
required
|
|
1349
|
+
} = {}) {
|
|
1350
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1351
|
+
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1442
1352
|
// Compute the defaults recursively: give highest priority to deepest nodes.
|
|
1443
|
-
|
|
1353
|
+
let defaults = parentDefaults;
|
|
1444
1354
|
// If we get a new schema, then we need to recompute defaults again for the new schema found.
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
if (isObject(defaults) && isObject(schema
|
|
1355
|
+
let schemaToCompute = null;
|
|
1356
|
+
let updatedRecurseList = _recurseList;
|
|
1357
|
+
if (isObject(defaults) && isObject(schema.default)) {
|
|
1448
1358
|
// For object defaults, only override parent defaults that are defined in
|
|
1449
1359
|
// schema.default.
|
|
1450
|
-
defaults = mergeObjects(defaults, schema
|
|
1360
|
+
defaults = mergeObjects(defaults, schema.default);
|
|
1451
1361
|
} else if (DEFAULT_KEY in schema) {
|
|
1452
|
-
defaults = schema
|
|
1362
|
+
defaults = schema.default;
|
|
1453
1363
|
} else if (REF_KEY in schema) {
|
|
1454
|
-
|
|
1364
|
+
const refName = schema[REF_KEY];
|
|
1455
1365
|
// Use referenced schema defaults for this node.
|
|
1456
1366
|
if (!_recurseList.includes(refName)) {
|
|
1457
1367
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1458
1368
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1459
1369
|
}
|
|
1460
1370
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1461
|
-
|
|
1371
|
+
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData);
|
|
1462
1372
|
schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies
|
|
1463
1373
|
} else if (isFixedItems(schema)) {
|
|
1464
|
-
defaults = schema.items.map(
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
});
|
|
1474
|
-
});
|
|
1374
|
+
defaults = schema.items.map((itemSchema, idx) => computeDefaults(validator, itemSchema, {
|
|
1375
|
+
rootSchema,
|
|
1376
|
+
includeUndefinedValues,
|
|
1377
|
+
_recurseList,
|
|
1378
|
+
experimental_defaultFormStateBehavior,
|
|
1379
|
+
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,
|
|
1380
|
+
rawFormData: formData,
|
|
1381
|
+
required
|
|
1382
|
+
}));
|
|
1475
1383
|
} else if (ONE_OF_KEY in schema) {
|
|
1476
|
-
|
|
1477
|
-
|
|
1384
|
+
const {
|
|
1385
|
+
oneOf,
|
|
1386
|
+
...remaining
|
|
1387
|
+
} = schema;
|
|
1478
1388
|
if (oneOf.length === 0) {
|
|
1479
1389
|
return undefined;
|
|
1480
1390
|
}
|
|
1481
|
-
|
|
1391
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1482
1392
|
schemaToCompute = oneOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, oneOf, 0, discriminator)];
|
|
1483
|
-
schemaToCompute =
|
|
1393
|
+
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1484
1394
|
} else if (ANY_OF_KEY in schema) {
|
|
1485
|
-
|
|
1486
|
-
|
|
1395
|
+
const {
|
|
1396
|
+
anyOf,
|
|
1397
|
+
...remaining
|
|
1398
|
+
} = schema;
|
|
1487
1399
|
if (anyOf.length === 0) {
|
|
1488
1400
|
return undefined;
|
|
1489
1401
|
}
|
|
1490
|
-
|
|
1491
|
-
schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, anyOf, 0,
|
|
1492
|
-
schemaToCompute =
|
|
1402
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1403
|
+
schemaToCompute = anyOf[getClosestMatchingOption(validator, rootSchema, isEmpty__default["default"](formData) ? undefined : formData, anyOf, 0, discriminator)];
|
|
1404
|
+
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1493
1405
|
}
|
|
1494
1406
|
if (schemaToCompute) {
|
|
1495
1407
|
return computeDefaults(validator, schemaToCompute, {
|
|
1496
|
-
rootSchema
|
|
1497
|
-
includeUndefinedValues
|
|
1408
|
+
rootSchema,
|
|
1409
|
+
includeUndefinedValues,
|
|
1498
1410
|
_recurseList: updatedRecurseList,
|
|
1499
|
-
experimental_defaultFormStateBehavior
|
|
1411
|
+
experimental_defaultFormStateBehavior,
|
|
1500
1412
|
parentDefaults: defaults,
|
|
1501
1413
|
rawFormData: formData,
|
|
1502
|
-
required
|
|
1414
|
+
required
|
|
1503
1415
|
});
|
|
1504
1416
|
}
|
|
1505
1417
|
// No defaults defined for this node, fallback to generic typed ones.
|
|
1506
1418
|
if (defaults === undefined) {
|
|
1507
|
-
defaults = schema
|
|
1419
|
+
defaults = schema.default;
|
|
1508
1420
|
}
|
|
1509
1421
|
switch (getSchemaType(schema)) {
|
|
1510
1422
|
// We need to recurse for object schema inner default values.
|
|
1511
1423
|
case 'object':
|
|
1512
1424
|
{
|
|
1513
|
-
|
|
1425
|
+
const objectDefaults = Object.keys(schema.properties || {}).reduce((acc, key) => {
|
|
1514
1426
|
var _schema$required;
|
|
1515
1427
|
// Compute the defaults for this node, with the parent defaults we might
|
|
1516
1428
|
// have from a previous run: defaults[key].
|
|
1517
|
-
|
|
1518
|
-
rootSchema
|
|
1519
|
-
_recurseList
|
|
1520
|
-
experimental_defaultFormStateBehavior
|
|
1429
|
+
const computedDefault = computeDefaults(validator, get__default["default"](schema, [PROPERTIES_KEY, key]), {
|
|
1430
|
+
rootSchema,
|
|
1431
|
+
_recurseList,
|
|
1432
|
+
experimental_defaultFormStateBehavior,
|
|
1521
1433
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1522
1434
|
parentDefaults: get__default["default"](defaults, [key]),
|
|
1523
1435
|
rawFormData: get__default["default"](formData, [key]),
|
|
@@ -1528,31 +1440,25 @@ function computeDefaults(validator, rawSchema, _temp) {
|
|
|
1528
1440
|
}, {});
|
|
1529
1441
|
if (schema.additionalProperties) {
|
|
1530
1442
|
// as per spec additionalProperties may be either schema or boolean
|
|
1531
|
-
|
|
1532
|
-
|
|
1443
|
+
const additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
|
|
1444
|
+
const keys = new Set();
|
|
1533
1445
|
if (isObject(defaults)) {
|
|
1534
|
-
Object.keys(defaults).filter(
|
|
1535
|
-
return !schema.properties || !schema.properties[key];
|
|
1536
|
-
}).forEach(function (key) {
|
|
1537
|
-
return keys.add(key);
|
|
1538
|
-
});
|
|
1446
|
+
Object.keys(defaults).filter(key => !schema.properties || !schema.properties[key]).forEach(key => keys.add(key));
|
|
1539
1447
|
}
|
|
1540
|
-
|
|
1448
|
+
let formDataRequired;
|
|
1541
1449
|
if (isObject(formData)) {
|
|
1542
1450
|
formDataRequired = [];
|
|
1543
|
-
Object.keys(formData).filter(
|
|
1544
|
-
return !schema.properties || !schema.properties[key];
|
|
1545
|
-
}).forEach(function (key) {
|
|
1451
|
+
Object.keys(formData).filter(key => !schema.properties || !schema.properties[key]).forEach(key => {
|
|
1546
1452
|
keys.add(key);
|
|
1547
1453
|
formDataRequired.push(key);
|
|
1548
1454
|
});
|
|
1549
1455
|
}
|
|
1550
|
-
keys.forEach(
|
|
1456
|
+
keys.forEach(key => {
|
|
1551
1457
|
var _schema$required2;
|
|
1552
|
-
|
|
1553
|
-
rootSchema
|
|
1554
|
-
_recurseList
|
|
1555
|
-
experimental_defaultFormStateBehavior
|
|
1458
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1459
|
+
rootSchema,
|
|
1460
|
+
_recurseList,
|
|
1461
|
+
experimental_defaultFormStateBehavior,
|
|
1556
1462
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1557
1463
|
parentDefaults: get__default["default"](defaults, [key]),
|
|
1558
1464
|
rawFormData: get__default["default"](formData, [key]),
|
|
@@ -1566,54 +1472,54 @@ function computeDefaults(validator, rawSchema, _temp) {
|
|
|
1566
1472
|
}
|
|
1567
1473
|
case 'array':
|
|
1568
1474
|
{
|
|
1569
|
-
var
|
|
1475
|
+
var _experimental_default;
|
|
1570
1476
|
// Inject defaults into existing array defaults
|
|
1571
1477
|
if (Array.isArray(defaults)) {
|
|
1572
|
-
defaults = defaults.map(
|
|
1573
|
-
|
|
1478
|
+
defaults = defaults.map((item, idx) => {
|
|
1479
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
|
|
1574
1480
|
return computeDefaults(validator, schemaItem, {
|
|
1575
|
-
rootSchema
|
|
1576
|
-
_recurseList
|
|
1577
|
-
experimental_defaultFormStateBehavior
|
|
1481
|
+
rootSchema,
|
|
1482
|
+
_recurseList,
|
|
1483
|
+
experimental_defaultFormStateBehavior,
|
|
1578
1484
|
parentDefaults: item,
|
|
1579
|
-
required
|
|
1485
|
+
required
|
|
1580
1486
|
});
|
|
1581
1487
|
});
|
|
1582
1488
|
}
|
|
1583
1489
|
// Deeply inject defaults into already existing form data
|
|
1584
1490
|
if (Array.isArray(rawFormData)) {
|
|
1585
|
-
|
|
1586
|
-
defaults = rawFormData.map(
|
|
1491
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1492
|
+
defaults = rawFormData.map((item, idx) => {
|
|
1587
1493
|
return computeDefaults(validator, schemaItem, {
|
|
1588
|
-
rootSchema
|
|
1589
|
-
_recurseList
|
|
1590
|
-
experimental_defaultFormStateBehavior
|
|
1494
|
+
rootSchema,
|
|
1495
|
+
_recurseList,
|
|
1496
|
+
experimental_defaultFormStateBehavior,
|
|
1591
1497
|
rawFormData: item,
|
|
1592
1498
|
parentDefaults: get__default["default"](defaults, [idx]),
|
|
1593
|
-
required
|
|
1499
|
+
required
|
|
1594
1500
|
});
|
|
1595
1501
|
});
|
|
1596
1502
|
}
|
|
1597
|
-
|
|
1503
|
+
const ignoreMinItemsFlagSet = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : (_experimental_default = experimental_defaultFormStateBehavior.arrayMinItems) === null || _experimental_default === void 0 ? void 0 : _experimental_default.populate) === 'requiredOnly';
|
|
1598
1504
|
if (ignoreMinItemsFlagSet && !required) {
|
|
1599
1505
|
// If no form data exists or defaults are set leave the field empty/non-existent, otherwise
|
|
1600
1506
|
// return form data/defaults
|
|
1601
1507
|
return defaults ? defaults : undefined;
|
|
1602
1508
|
}
|
|
1603
|
-
|
|
1509
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1604
1510
|
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1605
1511
|
return defaults ? defaults : [];
|
|
1606
1512
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1513
|
+
const defaultEntries = defaults || [];
|
|
1514
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
|
|
1515
|
+
const fillerDefault = fillerSchema.default;
|
|
1610
1516
|
// Calculate filler entries for remaining items (minItems - existing raw data/defaults)
|
|
1611
|
-
|
|
1517
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, {
|
|
1612
1518
|
parentDefaults: fillerDefault,
|
|
1613
|
-
rootSchema
|
|
1614
|
-
_recurseList
|
|
1615
|
-
experimental_defaultFormStateBehavior
|
|
1616
|
-
required
|
|
1519
|
+
rootSchema,
|
|
1520
|
+
_recurseList,
|
|
1521
|
+
experimental_defaultFormStateBehavior,
|
|
1522
|
+
required
|
|
1617
1523
|
}));
|
|
1618
1524
|
// then fill up the rest with either the item default or empty, up to minItems
|
|
1619
1525
|
return defaultEntries.concat(fillerEntries);
|
|
@@ -1634,26 +1540,24 @@ function computeDefaults(validator, rawSchema, _temp) {
|
|
|
1634
1540
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
1635
1541
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1636
1542
|
*/
|
|
1637
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues, experimental_defaultFormStateBehavior) {
|
|
1638
|
-
if (includeUndefinedValues === void 0) {
|
|
1639
|
-
includeUndefinedValues = false;
|
|
1640
|
-
}
|
|
1543
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1641
1544
|
if (!isObject(theSchema)) {
|
|
1642
1545
|
throw new Error('Invalid schema: ' + theSchema);
|
|
1643
1546
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
rootSchema
|
|
1647
|
-
includeUndefinedValues
|
|
1648
|
-
experimental_defaultFormStateBehavior
|
|
1547
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1548
|
+
const defaults = computeDefaults(validator, schema, {
|
|
1549
|
+
rootSchema,
|
|
1550
|
+
includeUndefinedValues,
|
|
1551
|
+
experimental_defaultFormStateBehavior,
|
|
1649
1552
|
rawFormData: formData
|
|
1650
1553
|
});
|
|
1651
1554
|
if (formData === undefined || formData === null || typeof formData === 'number' && isNaN(formData)) {
|
|
1652
1555
|
// No form data? Use schema defaults.
|
|
1653
1556
|
return defaults;
|
|
1654
1557
|
}
|
|
1655
|
-
|
|
1656
|
-
mergeExtraDefaults
|
|
1558
|
+
const {
|
|
1559
|
+
mergeExtraDefaults
|
|
1560
|
+
} = (experimental_defaultFormStateBehavior === null || experimental_defaultFormStateBehavior === void 0 ? void 0 : experimental_defaultFormStateBehavior.arrayMinItems) || {};
|
|
1657
1561
|
if (isObject(formData)) {
|
|
1658
1562
|
return mergeDefaultsWithFormData(defaults, formData, mergeExtraDefaults);
|
|
1659
1563
|
}
|
|
@@ -1668,10 +1572,7 @@ function getDefaultFormState(validator, theSchema, formData, rootSchema, include
|
|
|
1668
1572
|
* @param uiSchema - The UI Schema from which to detect if it is customized
|
|
1669
1573
|
* @returns - True if the `uiSchema` describes a custom widget, false otherwise
|
|
1670
1574
|
*/
|
|
1671
|
-
function isCustomWidget(uiSchema) {
|
|
1672
|
-
if (uiSchema === void 0) {
|
|
1673
|
-
uiSchema = {};
|
|
1674
|
-
}
|
|
1575
|
+
function isCustomWidget(uiSchema = {}) {
|
|
1675
1576
|
return (
|
|
1676
1577
|
// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
|
|
1677
1578
|
// https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
|
|
@@ -1687,15 +1588,12 @@ function isCustomWidget(uiSchema) {
|
|
|
1687
1588
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1688
1589
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1689
1590
|
*/
|
|
1690
|
-
function isFilesArray(validator, schema, uiSchema, rootSchema) {
|
|
1691
|
-
if (uiSchema === void 0) {
|
|
1692
|
-
uiSchema = {};
|
|
1693
|
-
}
|
|
1591
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1694
1592
|
if (uiSchema[UI_WIDGET_KEY] === 'files') {
|
|
1695
1593
|
return true;
|
|
1696
1594
|
}
|
|
1697
1595
|
if (schema.items) {
|
|
1698
|
-
|
|
1596
|
+
const itemsSchema = retrieveSchema(validator, schema.items, rootSchema);
|
|
1699
1597
|
return itemsSchema.type === 'string' && itemsSchema.format === 'data-url';
|
|
1700
1598
|
}
|
|
1701
1599
|
return false;
|
|
@@ -1711,15 +1609,13 @@ function isFilesArray(validator, schema, uiSchema, rootSchema) {
|
|
|
1711
1609
|
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
1712
1610
|
* @returns - True if the label should be displayed or false if it should not
|
|
1713
1611
|
*/
|
|
1714
|
-
function getDisplayLabel(validator, schema, uiSchema, rootSchema, globalOptions) {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
var displayLabel = !!label;
|
|
1722
|
-
var schemaType = getSchemaType(schema);
|
|
1612
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1613
|
+
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1614
|
+
const {
|
|
1615
|
+
label = true
|
|
1616
|
+
} = uiOptions;
|
|
1617
|
+
let displayLabel = !!label;
|
|
1618
|
+
const schemaType = getSchemaType(schema);
|
|
1723
1619
|
if (schemaType === 'array') {
|
|
1724
1620
|
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1725
1621
|
}
|
|
@@ -1751,21 +1647,23 @@ function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
|
1751
1647
|
if (!additionalErrorSchema) {
|
|
1752
1648
|
return validationData;
|
|
1753
1649
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1650
|
+
const {
|
|
1651
|
+
errors: oldErrors,
|
|
1652
|
+
errorSchema: oldErrorSchema
|
|
1653
|
+
} = validationData;
|
|
1654
|
+
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1655
|
+
let errorSchema = additionalErrorSchema;
|
|
1758
1656
|
if (!isEmpty__default["default"](oldErrorSchema)) {
|
|
1759
1657
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1760
|
-
errors = [].concat(
|
|
1658
|
+
errors = [...oldErrors].concat(errors);
|
|
1761
1659
|
}
|
|
1762
1660
|
return {
|
|
1763
|
-
errorSchema
|
|
1764
|
-
errors
|
|
1661
|
+
errorSchema,
|
|
1662
|
+
errors
|
|
1765
1663
|
};
|
|
1766
1664
|
}
|
|
1767
1665
|
|
|
1768
|
-
|
|
1666
|
+
const NO_VALUE = /*#__PURE__*/Symbol('no Value');
|
|
1769
1667
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
1770
1668
|
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
1771
1669
|
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
@@ -1813,31 +1711,28 @@ var NO_VALUE = /*#__PURE__*/Symbol('no Value');
|
|
|
1813
1711
|
* @returns - The new form data, with all the fields uniquely associated with the old schema set
|
|
1814
1712
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1815
1713
|
*/
|
|
1816
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data) {
|
|
1817
|
-
if (data === void 0) {
|
|
1818
|
-
data = {};
|
|
1819
|
-
}
|
|
1714
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1820
1715
|
// By default, we will clear the form data
|
|
1821
|
-
|
|
1716
|
+
let newFormData;
|
|
1822
1717
|
// If the new schema is of type object and that object contains a list of properties
|
|
1823
1718
|
if (has__default["default"](newSchema, PROPERTIES_KEY)) {
|
|
1824
1719
|
// Create an object containing root-level keys in the old schema, setting each key to undefined to remove the data
|
|
1825
|
-
|
|
1720
|
+
const removeOldSchemaData = {};
|
|
1826
1721
|
if (has__default["default"](oldSchema, PROPERTIES_KEY)) {
|
|
1827
|
-
|
|
1828
|
-
Object.keys(properties).forEach(
|
|
1722
|
+
const properties = get__default["default"](oldSchema, PROPERTIES_KEY, {});
|
|
1723
|
+
Object.keys(properties).forEach(key => {
|
|
1829
1724
|
if (has__default["default"](data, key)) {
|
|
1830
1725
|
removeOldSchemaData[key] = undefined;
|
|
1831
1726
|
}
|
|
1832
1727
|
});
|
|
1833
1728
|
}
|
|
1834
|
-
|
|
1729
|
+
const keys = Object.keys(get__default["default"](newSchema, PROPERTIES_KEY, {}));
|
|
1835
1730
|
// Create a place to store nested data that will be a side-effect of the filter
|
|
1836
|
-
|
|
1837
|
-
keys.forEach(
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1731
|
+
const nestedData = {};
|
|
1732
|
+
keys.forEach(key => {
|
|
1733
|
+
const formValue = get__default["default"](data, key);
|
|
1734
|
+
let oldKeyedSchema = get__default["default"](oldSchema, [PROPERTIES_KEY, key], {});
|
|
1735
|
+
let newKeyedSchema = get__default["default"](newSchema, [PROPERTIES_KEY, key], {});
|
|
1841
1736
|
// Resolve the refs if they exist
|
|
1842
1737
|
if (has__default["default"](oldKeyedSchema, REF_KEY)) {
|
|
1843
1738
|
oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
|
|
@@ -1846,8 +1741,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1846
1741
|
newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
|
|
1847
1742
|
}
|
|
1848
1743
|
// Now get types and see if they are the same
|
|
1849
|
-
|
|
1850
|
-
|
|
1744
|
+
const oldSchemaTypeForKey = get__default["default"](oldKeyedSchema, 'type');
|
|
1745
|
+
const newSchemaTypeForKey = get__default["default"](newKeyedSchema, 'type');
|
|
1851
1746
|
// Check if the old option has the same key with the same type
|
|
1852
1747
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1853
1748
|
if (has__default["default"](removeOldSchemaData, key)) {
|
|
@@ -1857,7 +1752,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1857
1752
|
// If it is an object, we'll recurse and store the resulting sanitized data for the key
|
|
1858
1753
|
if (newSchemaTypeForKey === 'object' || newSchemaTypeForKey === 'array' && Array.isArray(formValue)) {
|
|
1859
1754
|
// SIDE-EFFECT: process the new schema type of object recursively to save iterations
|
|
1860
|
-
|
|
1755
|
+
const itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
|
|
1861
1756
|
if (itemData !== undefined || newSchemaTypeForKey === 'array') {
|
|
1862
1757
|
// only put undefined values for the array type and not the object type
|
|
1863
1758
|
nestedData[key] = itemData;
|
|
@@ -1866,8 +1761,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1866
1761
|
// Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
|
|
1867
1762
|
// with the new default or const. This allows the case where two schemas differ that only by the default/const
|
|
1868
1763
|
// value to be properly selected
|
|
1869
|
-
|
|
1870
|
-
|
|
1764
|
+
const newOptionDefault = get__default["default"](newKeyedSchema, 'default', NO_VALUE);
|
|
1765
|
+
const oldOptionDefault = get__default["default"](oldKeyedSchema, 'default', NO_VALUE);
|
|
1871
1766
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1872
1767
|
if (oldOptionDefault === formValue) {
|
|
1873
1768
|
// If the old default matches the formValue, we'll update the new value to match the new default
|
|
@@ -1877,8 +1772,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1877
1772
|
removeOldSchemaData[key] = undefined;
|
|
1878
1773
|
}
|
|
1879
1774
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1775
|
+
const newOptionConst = get__default["default"](newKeyedSchema, 'const', NO_VALUE);
|
|
1776
|
+
const oldOptionConst = get__default["default"](oldKeyedSchema, 'const', NO_VALUE);
|
|
1882
1777
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1883
1778
|
// Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
|
|
1884
1779
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
|
|
@@ -1886,11 +1781,15 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1886
1781
|
}
|
|
1887
1782
|
}
|
|
1888
1783
|
});
|
|
1889
|
-
newFormData =
|
|
1784
|
+
newFormData = {
|
|
1785
|
+
...data,
|
|
1786
|
+
...removeOldSchemaData,
|
|
1787
|
+
...nestedData
|
|
1788
|
+
};
|
|
1890
1789
|
// First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
|
|
1891
1790
|
} else if (get__default["default"](oldSchema, 'type') === 'array' && get__default["default"](newSchema, 'type') === 'array' && Array.isArray(data)) {
|
|
1892
|
-
|
|
1893
|
-
|
|
1791
|
+
let oldSchemaItems = get__default["default"](oldSchema, 'items');
|
|
1792
|
+
let newSchemaItems = get__default["default"](newSchema, 'items');
|
|
1894
1793
|
// If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
|
|
1895
1794
|
// Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
|
|
1896
1795
|
if (typeof oldSchemaItems === 'object' && typeof newSchemaItems === 'object' && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
@@ -1901,14 +1800,14 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1901
1800
|
newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
|
|
1902
1801
|
}
|
|
1903
1802
|
// Now get types and see if they are the same
|
|
1904
|
-
|
|
1905
|
-
|
|
1803
|
+
const oldSchemaType = get__default["default"](oldSchemaItems, 'type');
|
|
1804
|
+
const newSchemaType = get__default["default"](newSchemaItems, 'type');
|
|
1906
1805
|
// Check if the old option has the same key with the same type
|
|
1907
1806
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1908
|
-
|
|
1807
|
+
const maxItems = get__default["default"](newSchema, 'maxItems', -1);
|
|
1909
1808
|
if (newSchemaType === 'object') {
|
|
1910
|
-
newFormData = data.reduce(
|
|
1911
|
-
|
|
1809
|
+
newFormData = data.reduce((newValue, aValue) => {
|
|
1810
|
+
const itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
|
|
1912
1811
|
if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1913
1812
|
newValue.push(itemValue);
|
|
1914
1813
|
}
|
|
@@ -1941,15 +1840,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1941
1840
|
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
1942
1841
|
* @returns - The `IdSchema` object for the `schema`
|
|
1943
1842
|
*/
|
|
1944
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList) {
|
|
1945
|
-
if (_recurseList === void 0) {
|
|
1946
|
-
_recurseList = [];
|
|
1947
|
-
}
|
|
1843
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1948
1844
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
return isEqual__default["default"](item, _schema);
|
|
1952
|
-
});
|
|
1845
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1846
|
+
const sameSchemaIndex = _recurseList.findIndex(item => isEqual__default["default"](item, _schema));
|
|
1953
1847
|
if (sameSchemaIndex === -1) {
|
|
1954
1848
|
return toIdSchemaInternal(validator, _schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList.concat(_schema));
|
|
1955
1849
|
}
|
|
@@ -1957,14 +1851,14 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1957
1851
|
if (ITEMS_KEY in schema && !get__default["default"](schema, [ITEMS_KEY, REF_KEY])) {
|
|
1958
1852
|
return toIdSchemaInternal(validator, get__default["default"](schema, ITEMS_KEY), idPrefix, idSeparator, id, rootSchema, formData, _recurseList);
|
|
1959
1853
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
$id
|
|
1854
|
+
const $id = id || idPrefix;
|
|
1855
|
+
const idSchema = {
|
|
1856
|
+
$id
|
|
1963
1857
|
};
|
|
1964
1858
|
if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
|
|
1965
|
-
for (
|
|
1966
|
-
|
|
1967
|
-
|
|
1859
|
+
for (const name in schema.properties) {
|
|
1860
|
+
const field = get__default["default"](schema, [PROPERTIES_KEY, name]);
|
|
1861
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1968
1862
|
idSchema[name] = toIdSchemaInternal(validator, isObject(field) ? field : {}, idPrefix, idSeparator, fieldId, rootSchema,
|
|
1969
1863
|
// It's possible that formData is not an object -- this can happen if an
|
|
1970
1864
|
// array item has just been added, but not populated with data yet
|
|
@@ -1984,13 +1878,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1984
1878
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1985
1879
|
* @returns - The `IdSchema` object for the `schema`
|
|
1986
1880
|
*/
|
|
1987
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
|
|
1988
|
-
if (idPrefix === void 0) {
|
|
1989
|
-
idPrefix = 'root';
|
|
1990
|
-
}
|
|
1991
|
-
if (idSeparator === void 0) {
|
|
1992
|
-
idSeparator = '_';
|
|
1993
|
-
}
|
|
1881
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = 'root', idSeparator = '_') {
|
|
1994
1882
|
return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData);
|
|
1995
1883
|
}
|
|
1996
1884
|
|
|
@@ -2005,39 +1893,38 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSep
|
|
|
2005
1893
|
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
2006
1894
|
* @returns - The `PathSchema` object for the `schema`
|
|
2007
1895
|
*/
|
|
2008
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList) {
|
|
2009
|
-
var _pathSchema;
|
|
2010
|
-
if (_recurseList === void 0) {
|
|
2011
|
-
_recurseList = [];
|
|
2012
|
-
}
|
|
1896
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
2013
1897
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
return isEqual__default["default"](item, _schema);
|
|
2017
|
-
});
|
|
1898
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1899
|
+
const sameSchemaIndex = _recurseList.findIndex(item => isEqual__default["default"](item, _schema));
|
|
2018
1900
|
if (sameSchemaIndex === -1) {
|
|
2019
1901
|
return toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList.concat(_schema));
|
|
2020
1902
|
}
|
|
2021
1903
|
}
|
|
2022
|
-
|
|
1904
|
+
let pathSchema = {
|
|
1905
|
+
[NAME_KEY]: name.replace(/^\./, '')
|
|
1906
|
+
};
|
|
2023
1907
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
pathSchema =
|
|
1908
|
+
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1909
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1910
|
+
const index = getClosestMatchingOption(validator, rootSchema, formData, xxxOf, 0, discriminator);
|
|
1911
|
+
const _schema = xxxOf[index];
|
|
1912
|
+
pathSchema = {
|
|
1913
|
+
...pathSchema,
|
|
1914
|
+
...toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList)
|
|
1915
|
+
};
|
|
2029
1916
|
}
|
|
2030
1917
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2031
1918
|
set__default["default"](pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
|
|
2032
1919
|
}
|
|
2033
1920
|
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
2034
|
-
formData.forEach(
|
|
2035
|
-
pathSchema[i] = toPathSchemaInternal(validator, schema.items, name
|
|
1921
|
+
formData.forEach((element, i) => {
|
|
1922
|
+
pathSchema[i] = toPathSchemaInternal(validator, schema.items, `${name}.${i}`, rootSchema, element, _recurseList);
|
|
2036
1923
|
});
|
|
2037
1924
|
} else if (PROPERTIES_KEY in schema) {
|
|
2038
|
-
for (
|
|
2039
|
-
|
|
2040
|
-
pathSchema[property] = toPathSchemaInternal(validator, field, name
|
|
1925
|
+
for (const property in schema.properties) {
|
|
1926
|
+
const field = get__default["default"](schema, [PROPERTIES_KEY, property]);
|
|
1927
|
+
pathSchema[property] = toPathSchemaInternal(validator, field, `${name}.${property}`, rootSchema,
|
|
2041
1928
|
// It's possible that formData is not an object -- this can happen if an
|
|
2042
1929
|
// array item has just been added, but not populated with data yet
|
|
2043
1930
|
get__default["default"](formData, [property]), _recurseList);
|
|
@@ -2054,10 +1941,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2054
1941
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
2055
1942
|
* @returns - The `PathSchema` object for the `schema`
|
|
2056
1943
|
*/
|
|
2057
|
-
function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
2058
|
-
if (name === void 0) {
|
|
2059
|
-
name = '';
|
|
2060
|
-
}
|
|
1944
|
+
function toPathSchema(validator, schema, name = '', rootSchema, formData) {
|
|
2061
1945
|
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2062
1946
|
}
|
|
2063
1947
|
|
|
@@ -2066,14 +1950,14 @@ function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
|
2066
1950
|
* Since these generally do not change across a `Form`, this allows for providing a simplified set of APIs to the
|
|
2067
1951
|
* `@rjsf/core` components and the various themes as well. This class implements the `SchemaUtilsType` interface.
|
|
2068
1952
|
*/
|
|
2069
|
-
|
|
1953
|
+
class SchemaUtils {
|
|
2070
1954
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2071
1955
|
*
|
|
2072
1956
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
2073
1957
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
2074
1958
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2075
1959
|
*/
|
|
2076
|
-
|
|
1960
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2077
1961
|
this.rootSchema = void 0;
|
|
2078
1962
|
this.validator = void 0;
|
|
2079
1963
|
this.experimental_defaultFormStateBehavior = void 0;
|
|
@@ -2085,8 +1969,7 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2085
1969
|
*
|
|
2086
1970
|
* @returns - The `ValidatorType`
|
|
2087
1971
|
*/
|
|
2088
|
-
|
|
2089
|
-
_proto.getValidator = function getValidator() {
|
|
1972
|
+
getValidator() {
|
|
2090
1973
|
return this.validator;
|
|
2091
1974
|
}
|
|
2092
1975
|
/** Determines whether either the `validator` and `rootSchema` differ from the ones associated with this instance of
|
|
@@ -2097,11 +1980,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2097
1980
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
2098
1981
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2099
1982
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
if (experimental_defaultFormStateBehavior === void 0) {
|
|
2103
|
-
experimental_defaultFormStateBehavior = {};
|
|
2104
|
-
}
|
|
1983
|
+
*/
|
|
1984
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2105
1985
|
if (!validator || !rootSchema) {
|
|
2106
1986
|
return false;
|
|
2107
1987
|
}
|
|
@@ -2116,11 +1996,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2116
1996
|
* If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
|
|
2117
1997
|
* object properties.
|
|
2118
1998
|
* @returns - The resulting `formData` with all the defaults provided
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
if (includeUndefinedValues === void 0) {
|
|
2122
|
-
includeUndefinedValues = false;
|
|
2123
|
-
}
|
|
1999
|
+
*/
|
|
2000
|
+
getDefaultFormState(schema, formData, includeUndefinedValues = false) {
|
|
2124
2001
|
return getDefaultFormState(this.validator, schema, formData, this.rootSchema, includeUndefinedValues, this.experimental_defaultFormStateBehavior);
|
|
2125
2002
|
}
|
|
2126
2003
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -2130,8 +2007,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2130
2007
|
* @param [uiSchema] - The UI schema from which to derive potentially displayable information
|
|
2131
2008
|
* @param [globalOptions={}] - The optional Global UI Schema from which to get any fallback `xxx` options
|
|
2132
2009
|
* @returns - True if the label should be displayed or false if it should not
|
|
2133
|
-
|
|
2134
|
-
|
|
2010
|
+
*/
|
|
2011
|
+
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
2135
2012
|
return getDisplayLabel(this.validator, schema, uiSchema, this.rootSchema, globalOptions);
|
|
2136
2013
|
}
|
|
2137
2014
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
@@ -2146,8 +2023,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2146
2023
|
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
2147
2024
|
* determine which option is selected
|
|
2148
2025
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
2149
|
-
|
|
2150
|
-
|
|
2026
|
+
*/
|
|
2027
|
+
getClosestMatchingOption(formData, options, selectedOption, discriminatorField) {
|
|
2151
2028
|
return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption, discriminatorField);
|
|
2152
2029
|
}
|
|
2153
2030
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -2158,8 +2035,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2158
2035
|
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
2159
2036
|
* determine which option is selected
|
|
2160
2037
|
* @returns - The firstindex of the matched option or 0 if none is available
|
|
2161
|
-
|
|
2162
|
-
|
|
2038
|
+
*/
|
|
2039
|
+
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
2163
2040
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2164
2041
|
}
|
|
2165
2042
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
@@ -2171,8 +2048,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2171
2048
|
* determine which option is selected
|
|
2172
2049
|
* @returns - The index of the matched option or 0 if none is available
|
|
2173
2050
|
* @deprecated
|
|
2174
|
-
|
|
2175
|
-
|
|
2051
|
+
*/
|
|
2052
|
+
getMatchingOption(formData, options, discriminatorField) {
|
|
2176
2053
|
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2177
2054
|
}
|
|
2178
2055
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
@@ -2180,24 +2057,24 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2180
2057
|
* @param schema - The schema for which check for array of files flag is desired
|
|
2181
2058
|
* @param [uiSchema] - The UI schema from which to check the widget
|
|
2182
2059
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
2183
|
-
|
|
2184
|
-
|
|
2060
|
+
*/
|
|
2061
|
+
isFilesArray(schema, uiSchema) {
|
|
2185
2062
|
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2186
2063
|
}
|
|
2187
2064
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
2188
2065
|
*
|
|
2189
2066
|
* @param schema - The schema for which check for a multi-select flag is desired
|
|
2190
2067
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
2191
|
-
|
|
2192
|
-
|
|
2068
|
+
*/
|
|
2069
|
+
isMultiSelect(schema) {
|
|
2193
2070
|
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2194
2071
|
}
|
|
2195
2072
|
/** Checks to see if the `schema` combination represents a select
|
|
2196
2073
|
*
|
|
2197
2074
|
* @param schema - The schema for which check for a select flag is desired
|
|
2198
2075
|
* @returns - True if schema contains a select, otherwise false
|
|
2199
|
-
|
|
2200
|
-
|
|
2076
|
+
*/
|
|
2077
|
+
isSelect(schema) {
|
|
2201
2078
|
return isSelect(this.validator, schema, this.rootSchema);
|
|
2202
2079
|
}
|
|
2203
2080
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
@@ -2210,8 +2087,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2210
2087
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
2211
2088
|
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
2212
2089
|
* removed in the next major release.
|
|
2213
|
-
|
|
2214
|
-
|
|
2090
|
+
*/
|
|
2091
|
+
mergeValidationData(validationData, additionalErrorSchema) {
|
|
2215
2092
|
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
2216
2093
|
}
|
|
2217
2094
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
@@ -2221,8 +2098,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2221
2098
|
* @param schema - The schema for which retrieving a schema is desired
|
|
2222
2099
|
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
2223
2100
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
2224
|
-
|
|
2225
|
-
|
|
2101
|
+
*/
|
|
2102
|
+
retrieveSchema(schema, rawFormData) {
|
|
2226
2103
|
return retrieveSchema(this.validator, schema, this.rootSchema, rawFormData);
|
|
2227
2104
|
}
|
|
2228
2105
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
@@ -2235,8 +2112,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2235
2112
|
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
|
|
2236
2113
|
* @returns - The new form data, with all the fields uniquely associated with the old schema set
|
|
2237
2114
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
2238
|
-
|
|
2239
|
-
|
|
2115
|
+
*/
|
|
2116
|
+
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
2240
2117
|
return sanitizeDataForNewSchema(this.validator, this.rootSchema, newSchema, oldSchema, data);
|
|
2241
2118
|
}
|
|
2242
2119
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
@@ -2247,14 +2124,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2247
2124
|
* @param [idPrefix='root'] - The prefix to use for the id
|
|
2248
2125
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
2249
2126
|
* @returns - The `IdSchema` object for the `schema`
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
if (idPrefix === void 0) {
|
|
2253
|
-
idPrefix = 'root';
|
|
2254
|
-
}
|
|
2255
|
-
if (idSeparator === void 0) {
|
|
2256
|
-
idSeparator = '_';
|
|
2257
|
-
}
|
|
2127
|
+
*/
|
|
2128
|
+
toIdSchema(schema, id, formData, idPrefix = 'root', idSeparator = '_') {
|
|
2258
2129
|
return toIdSchema(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator);
|
|
2259
2130
|
}
|
|
2260
2131
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
@@ -2263,12 +2134,11 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2263
2134
|
* @param [name] - The base name for the schema
|
|
2264
2135
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
2265
2136
|
* @returns - The `PathSchema` object for the `schema`
|
|
2266
|
-
|
|
2267
|
-
|
|
2137
|
+
*/
|
|
2138
|
+
toPathSchema(schema, name, formData) {
|
|
2268
2139
|
return toPathSchema(this.validator, schema, name, this.rootSchema, formData);
|
|
2269
|
-
}
|
|
2270
|
-
|
|
2271
|
-
}();
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2272
2142
|
/** Creates a `SchemaUtilsType` interface that is based around the given `validator` and `rootSchema` parameters. The
|
|
2273
2143
|
* resulting interface implementation will forward the `validator` and `rootSchema` to all the wrapped APIs.
|
|
2274
2144
|
*
|
|
@@ -2277,10 +2147,7 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
2277
2147
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2278
2148
|
* @returns - An implementation of a `SchemaUtilsType` interface
|
|
2279
2149
|
*/
|
|
2280
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2281
|
-
if (experimental_defaultFormStateBehavior === void 0) {
|
|
2282
|
-
experimental_defaultFormStateBehavior = {};
|
|
2283
|
-
}
|
|
2150
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2284
2151
|
return new SchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior);
|
|
2285
2152
|
}
|
|
2286
2153
|
|
|
@@ -2292,17 +2159,17 @@ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateB
|
|
|
2292
2159
|
*/
|
|
2293
2160
|
function dataURItoBlob(dataURI) {
|
|
2294
2161
|
// Split metadata from data
|
|
2295
|
-
|
|
2162
|
+
const splitted = dataURI.split(',');
|
|
2296
2163
|
// Split params
|
|
2297
|
-
|
|
2164
|
+
const params = splitted[0].split(';');
|
|
2298
2165
|
// Get mime-type from params
|
|
2299
|
-
|
|
2166
|
+
const type = params[0].replace('data:', '');
|
|
2300
2167
|
// Filter the name property from params
|
|
2301
|
-
|
|
2168
|
+
const properties = params.filter(param => {
|
|
2302
2169
|
return param.split('=')[0] === 'name';
|
|
2303
2170
|
});
|
|
2304
2171
|
// Look for the name and use unknown if no name property.
|
|
2305
|
-
|
|
2172
|
+
let name;
|
|
2306
2173
|
if (properties.length !== 1) {
|
|
2307
2174
|
name = 'unknown';
|
|
2308
2175
|
} else {
|
|
@@ -2312,18 +2179,18 @@ function dataURItoBlob(dataURI) {
|
|
|
2312
2179
|
}
|
|
2313
2180
|
// Built the Uint8Array Blob parameter from the base64 string.
|
|
2314
2181
|
try {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
for (
|
|
2182
|
+
const binary = atob(splitted[1]);
|
|
2183
|
+
const array = [];
|
|
2184
|
+
for (let i = 0; i < binary.length; i++) {
|
|
2318
2185
|
array.push(binary.charCodeAt(i));
|
|
2319
2186
|
}
|
|
2320
2187
|
// Create the blob object
|
|
2321
|
-
|
|
2322
|
-
type
|
|
2188
|
+
const blob = new window.Blob([new Uint8Array(array)], {
|
|
2189
|
+
type
|
|
2323
2190
|
});
|
|
2324
2191
|
return {
|
|
2325
|
-
blob
|
|
2326
|
-
name
|
|
2192
|
+
blob,
|
|
2193
|
+
name
|
|
2327
2194
|
};
|
|
2328
2195
|
} catch (error) {
|
|
2329
2196
|
return {
|
|
@@ -2345,13 +2212,11 @@ function dataURItoBlob(dataURI) {
|
|
|
2345
2212
|
* @returns - The updated string with any replacement specifiers replaced
|
|
2346
2213
|
*/
|
|
2347
2214
|
function replaceStringParameters(inputString, params) {
|
|
2348
|
-
|
|
2215
|
+
let output = inputString;
|
|
2349
2216
|
if (Array.isArray(params)) {
|
|
2350
|
-
|
|
2351
|
-
params.forEach(
|
|
2352
|
-
|
|
2353
|
-
return part === "%" + (index + 1);
|
|
2354
|
-
});
|
|
2217
|
+
const parts = output.split(/(%\d)/);
|
|
2218
|
+
params.forEach((param, index) => {
|
|
2219
|
+
const partIndex = parts.findIndex(part => part === `%${index + 1}`);
|
|
2355
2220
|
if (partIndex >= 0) {
|
|
2356
2221
|
parts[partIndex] = param;
|
|
2357
2222
|
}
|
|
@@ -2384,20 +2249,13 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
2384
2249
|
* @returns - The single or list of values specified by the single or list of indexes if they are valid. Otherwise,
|
|
2385
2250
|
* `emptyValue` or an empty list.
|
|
2386
2251
|
*/
|
|
2387
|
-
function enumOptionsValueForIndex(valueIndex, allEnumOptions, emptyValue) {
|
|
2388
|
-
if (allEnumOptions === void 0) {
|
|
2389
|
-
allEnumOptions = [];
|
|
2390
|
-
}
|
|
2252
|
+
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
2391
2253
|
if (Array.isArray(valueIndex)) {
|
|
2392
|
-
return valueIndex.map(
|
|
2393
|
-
return enumOptionsValueForIndex(index, allEnumOptions);
|
|
2394
|
-
}).filter(function (val) {
|
|
2395
|
-
return val;
|
|
2396
|
-
});
|
|
2254
|
+
return valueIndex.map(index => enumOptionsValueForIndex(index, allEnumOptions)).filter(val => val);
|
|
2397
2255
|
}
|
|
2398
2256
|
// So Number(null) and Number('') both return 0, so use emptyValue for those two values
|
|
2399
|
-
|
|
2400
|
-
|
|
2257
|
+
const index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
|
|
2258
|
+
const option = allEnumOptions[index];
|
|
2401
2259
|
return option ? option.value : emptyValue;
|
|
2402
2260
|
}
|
|
2403
2261
|
|
|
@@ -2413,15 +2271,10 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions, emptyValue) {
|
|
|
2413
2271
|
* unless `selected` is a single value. In that case, if the `valueIndex` value matches `selected`, returns
|
|
2414
2272
|
* undefined, otherwise `selected`.
|
|
2415
2273
|
*/
|
|
2416
|
-
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions) {
|
|
2417
|
-
|
|
2418
|
-
allEnumOptions = [];
|
|
2419
|
-
}
|
|
2420
|
-
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2274
|
+
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2275
|
+
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2421
2276
|
if (Array.isArray(selected)) {
|
|
2422
|
-
return selected.filter(
|
|
2423
|
-
return !isEqual__default["default"](v, value);
|
|
2424
|
-
});
|
|
2277
|
+
return selected.filter(v => !isEqual__default["default"](v, value));
|
|
2425
2278
|
}
|
|
2426
2279
|
return isEqual__default["default"](value, selected) ? undefined : selected;
|
|
2427
2280
|
}
|
|
@@ -2434,9 +2287,7 @@ function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions) {
|
|
|
2434
2287
|
*/
|
|
2435
2288
|
function enumOptionsIsSelected(value, selected) {
|
|
2436
2289
|
if (Array.isArray(selected)) {
|
|
2437
|
-
return selected.some(
|
|
2438
|
-
return isEqual__default["default"](sel, value);
|
|
2439
|
-
});
|
|
2290
|
+
return selected.some(sel => isEqual__default["default"](sel, value));
|
|
2440
2291
|
}
|
|
2441
2292
|
return isEqual__default["default"](selected, value);
|
|
2442
2293
|
}
|
|
@@ -2452,18 +2303,8 @@ function enumOptionsIsSelected(value, selected) {
|
|
|
2452
2303
|
* @returns - A single string index for the first `value` in `allEnumOptions`, if not `multiple`. Otherwise, the list
|
|
2453
2304
|
* of indexes for (each of) the value(s) in `value`.
|
|
2454
2305
|
*/
|
|
2455
|
-
function enumOptionsIndexForValue(value, allEnumOptions, multiple) {
|
|
2456
|
-
|
|
2457
|
-
allEnumOptions = [];
|
|
2458
|
-
}
|
|
2459
|
-
if (multiple === void 0) {
|
|
2460
|
-
multiple = false;
|
|
2461
|
-
}
|
|
2462
|
-
var selectedIndexes = allEnumOptions.map(function (opt, index) {
|
|
2463
|
-
return enumOptionsIsSelected(opt.value, value) ? String(index) : undefined;
|
|
2464
|
-
}).filter(function (opt) {
|
|
2465
|
-
return typeof opt !== 'undefined';
|
|
2466
|
-
});
|
|
2306
|
+
function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false) {
|
|
2307
|
+
const selectedIndexes = allEnumOptions.map((opt, index) => enumOptionsIsSelected(opt.value, value) ? String(index) : undefined).filter(opt => typeof opt !== 'undefined');
|
|
2467
2308
|
if (!multiple) {
|
|
2468
2309
|
return selectedIndexes[0];
|
|
2469
2310
|
}
|
|
@@ -2478,25 +2319,17 @@ function enumOptionsIndexForValue(value, allEnumOptions, multiple) {
|
|
|
2478
2319
|
* @param [allEnumOptions=[]] - The list of all the known enumOptions
|
|
2479
2320
|
* @returns - The updated list of selected enum values with enum value at the `valueIndex` added to it
|
|
2480
2321
|
*/
|
|
2481
|
-
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions) {
|
|
2482
|
-
|
|
2483
|
-
allEnumOptions = [];
|
|
2484
|
-
}
|
|
2485
|
-
var value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2322
|
+
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2323
|
+
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2486
2324
|
if (!lodash.isNil(value)) {
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
return val;
|
|
2493
|
-
});
|
|
2494
|
-
var updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
2325
|
+
const index = allEnumOptions.findIndex(opt => value === opt.value);
|
|
2326
|
+
const all = allEnumOptions.map(({
|
|
2327
|
+
value: val
|
|
2328
|
+
}) => val);
|
|
2329
|
+
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
2495
2330
|
// As inserting values at predefined index positions doesn't work with empty
|
|
2496
2331
|
// arrays, we need to reorder the updated selection to match the initial order
|
|
2497
|
-
return updated.sort(
|
|
2498
|
-
return Number(all.indexOf(a) > all.indexOf(b));
|
|
2499
|
-
});
|
|
2332
|
+
return updated.sort((a, b) => Number(all.indexOf(a) > all.indexOf(b)));
|
|
2500
2333
|
}
|
|
2501
2334
|
return selected;
|
|
2502
2335
|
}
|
|
@@ -2506,12 +2339,12 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions) {
|
|
|
2506
2339
|
* schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
|
|
2507
2340
|
* get the result and/or reset all the errors back to an initial set and start again.
|
|
2508
2341
|
*/
|
|
2509
|
-
|
|
2342
|
+
class ErrorSchemaBuilder {
|
|
2510
2343
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
2511
2344
|
*
|
|
2512
2345
|
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
2513
2346
|
*/
|
|
2514
|
-
|
|
2347
|
+
constructor(initialSchema) {
|
|
2515
2348
|
/** The error schema being built
|
|
2516
2349
|
*
|
|
2517
2350
|
* @private
|
|
@@ -2521,16 +2354,18 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2521
2354
|
}
|
|
2522
2355
|
/** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
|
|
2523
2356
|
*/
|
|
2524
|
-
|
|
2357
|
+
get ErrorSchema() {
|
|
2358
|
+
return this.errorSchema;
|
|
2359
|
+
}
|
|
2525
2360
|
/** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
|
|
2526
2361
|
*
|
|
2527
2362
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
2528
2363
|
* @returns - The error block for the given `pathOfError` or the root if not provided
|
|
2529
2364
|
* @private
|
|
2530
2365
|
*/
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2366
|
+
getOrCreateErrorBlock(pathOfError) {
|
|
2367
|
+
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === 'string';
|
|
2368
|
+
let errorBlock = hasPath ? get__default["default"](this.errorSchema, pathOfError) : this.errorSchema;
|
|
2534
2369
|
if (!errorBlock && pathOfError) {
|
|
2535
2370
|
errorBlock = {};
|
|
2536
2371
|
set__default["default"](this.errorSchema, pathOfError, errorBlock);
|
|
@@ -2541,8 +2376,8 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2541
2376
|
*
|
|
2542
2377
|
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
2543
2378
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
2544
|
-
|
|
2545
|
-
|
|
2379
|
+
*/
|
|
2380
|
+
resetAllErrors(initialSchema) {
|
|
2546
2381
|
this.errorSchema = initialSchema ? cloneDeep__default["default"](initialSchema) : {};
|
|
2547
2382
|
return this;
|
|
2548
2383
|
}
|
|
@@ -2553,17 +2388,16 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2553
2388
|
* @param errorOrList - The error or list of errors to add into the `ErrorSchema`
|
|
2554
2389
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
2555
2390
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2391
|
+
*/
|
|
2392
|
+
addErrors(errorOrList, pathOfError) {
|
|
2393
|
+
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2394
|
+
let errorsList = get__default["default"](errorBlock, ERRORS_KEY);
|
|
2560
2395
|
if (!Array.isArray(errorsList)) {
|
|
2561
2396
|
errorsList = [];
|
|
2562
2397
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
2563
2398
|
}
|
|
2564
2399
|
if (Array.isArray(errorOrList)) {
|
|
2565
|
-
|
|
2566
|
-
(_errorsList = errorsList).push.apply(_errorsList, errorOrList);
|
|
2400
|
+
errorsList.push(...errorOrList);
|
|
2567
2401
|
} else {
|
|
2568
2402
|
errorsList.push(errorOrList);
|
|
2569
2403
|
}
|
|
@@ -2576,11 +2410,11 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2576
2410
|
* @param errorOrList - The error or list of errors to set into the `ErrorSchema`
|
|
2577
2411
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
|
|
2578
2412
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2413
|
+
*/
|
|
2414
|
+
setErrors(errorOrList, pathOfError) {
|
|
2415
|
+
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2582
2416
|
// Effectively clone the array being given to prevent accidental outside manipulation of the given list
|
|
2583
|
-
|
|
2417
|
+
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2584
2418
|
set__default["default"](errorBlock, ERRORS_KEY, listToAdd);
|
|
2585
2419
|
return this;
|
|
2586
2420
|
}
|
|
@@ -2590,20 +2424,13 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2590
2424
|
*
|
|
2591
2425
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
|
|
2592
2426
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2427
|
+
*/
|
|
2428
|
+
clearErrors(pathOfError) {
|
|
2429
|
+
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
2596
2430
|
set__default["default"](errorBlock, ERRORS_KEY, []);
|
|
2597
2431
|
return this;
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2600
|
-
key: "ErrorSchema",
|
|
2601
|
-
get: function get() {
|
|
2602
|
-
return this.errorSchema;
|
|
2603
|
-
}
|
|
2604
|
-
}]);
|
|
2605
|
-
return ErrorSchemaBuilder;
|
|
2606
|
-
}();
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2607
2434
|
|
|
2608
2435
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
2609
2436
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
@@ -2612,7 +2439,7 @@ var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
|
2612
2439
|
* @returns - A range specification from the schema
|
|
2613
2440
|
*/
|
|
2614
2441
|
function rangeSpec(schema) {
|
|
2615
|
-
|
|
2442
|
+
const spec = {};
|
|
2616
2443
|
if (schema.multipleOf) {
|
|
2617
2444
|
spec.step = schema.multipleOf;
|
|
2618
2445
|
}
|
|
@@ -2633,16 +2460,11 @@ function rangeSpec(schema) {
|
|
|
2633
2460
|
* @param [autoDefaultStepAny=true] - Determines whether to auto-default step=any when the type is number and no step
|
|
2634
2461
|
* @returns - The extracted `InputPropsType` object
|
|
2635
2462
|
*/
|
|
2636
|
-
function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
autoDefaultStepAny = true;
|
|
2642
|
-
}
|
|
2643
|
-
var inputProps = _extends({
|
|
2644
|
-
type: defaultType || 'text'
|
|
2645
|
-
}, rangeSpec(schema));
|
|
2463
|
+
function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = true) {
|
|
2464
|
+
const inputProps = {
|
|
2465
|
+
type: defaultType || 'text',
|
|
2466
|
+
...rangeSpec(schema)
|
|
2467
|
+
};
|
|
2646
2468
|
// If options.inputType is set use that as the input type
|
|
2647
2469
|
if (options.inputType) {
|
|
2648
2470
|
inputProps.type = options.inputType;
|
|
@@ -2673,7 +2495,7 @@ function getInputProps(schema, defaultType, options, autoDefaultStepAny) {
|
|
|
2673
2495
|
|
|
2674
2496
|
/** The default submit button options, exported for testing purposes
|
|
2675
2497
|
*/
|
|
2676
|
-
|
|
2498
|
+
const DEFAULT_OPTIONS = {
|
|
2677
2499
|
props: {
|
|
2678
2500
|
disabled: false
|
|
2679
2501
|
},
|
|
@@ -2685,14 +2507,14 @@ var DEFAULT_OPTIONS = {
|
|
|
2685
2507
|
* @param [uiSchema={}] - the UI Schema from which to extract submit button props
|
|
2686
2508
|
* @returns - The merging of the `DEFAULT_OPTIONS` with any custom ones
|
|
2687
2509
|
*/
|
|
2688
|
-
function getSubmitButtonOptions(uiSchema) {
|
|
2689
|
-
|
|
2690
|
-
uiSchema = {};
|
|
2691
|
-
}
|
|
2692
|
-
var uiOptions = getUiOptions(uiSchema);
|
|
2510
|
+
function getSubmitButtonOptions(uiSchema = {}) {
|
|
2511
|
+
const uiOptions = getUiOptions(uiSchema);
|
|
2693
2512
|
if (uiOptions && uiOptions[SUBMIT_BTN_OPTIONS_KEY]) {
|
|
2694
|
-
|
|
2695
|
-
return
|
|
2513
|
+
const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
|
|
2514
|
+
return {
|
|
2515
|
+
...DEFAULT_OPTIONS,
|
|
2516
|
+
...options
|
|
2517
|
+
};
|
|
2696
2518
|
}
|
|
2697
2519
|
return DEFAULT_OPTIONS;
|
|
2698
2520
|
}
|
|
@@ -2705,11 +2527,10 @@ function getSubmitButtonOptions(uiSchema) {
|
|
|
2705
2527
|
* @param [uiOptions={}] - The `UIOptionsType` from which to read an alternate template
|
|
2706
2528
|
* @returns - The template from either the `uiSchema` or `registry` for the `name`
|
|
2707
2529
|
*/
|
|
2708
|
-
function getTemplate(name, registry, uiOptions) {
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
}
|
|
2712
|
-
var templates = registry.templates;
|
|
2530
|
+
function getTemplate(name, registry, uiOptions = {}) {
|
|
2531
|
+
const {
|
|
2532
|
+
templates
|
|
2533
|
+
} = registry;
|
|
2713
2534
|
if (name === 'ButtonTemplates') {
|
|
2714
2535
|
return templates[name];
|
|
2715
2536
|
}
|
|
@@ -2720,11 +2541,10 @@ function getTemplate(name, registry, uiOptions) {
|
|
|
2720
2541
|
);
|
|
2721
2542
|
}
|
|
2722
2543
|
|
|
2723
|
-
var _excluded = ["options"];
|
|
2724
2544
|
/** The map of schema types to widget type to widget name
|
|
2725
2545
|
*/
|
|
2726
|
-
|
|
2727
|
-
|
|
2546
|
+
const widgetMap = {
|
|
2547
|
+
boolean: {
|
|
2728
2548
|
checkbox: 'CheckboxWidget',
|
|
2729
2549
|
radio: 'RadioWidget',
|
|
2730
2550
|
select: 'SelectWidget',
|
|
@@ -2783,16 +2603,21 @@ var widgetMap = {
|
|
|
2783
2603
|
* @returns - The wrapper widget
|
|
2784
2604
|
*/
|
|
2785
2605
|
function mergeWidgetOptions(AWidget) {
|
|
2786
|
-
|
|
2606
|
+
let MergedWidget = get__default["default"](AWidget, 'MergedWidget');
|
|
2787
2607
|
// cache return value as property of widget for proper react reconciliation
|
|
2788
2608
|
if (!MergedWidget) {
|
|
2789
|
-
|
|
2790
|
-
MergedWidget =
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2609
|
+
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2610
|
+
MergedWidget = ({
|
|
2611
|
+
options,
|
|
2612
|
+
...props
|
|
2613
|
+
}) => {
|
|
2614
|
+
return jsxRuntime.jsx(AWidget, {
|
|
2615
|
+
options: {
|
|
2616
|
+
...defaultOptions,
|
|
2617
|
+
...options
|
|
2618
|
+
},
|
|
2619
|
+
...props
|
|
2620
|
+
});
|
|
2796
2621
|
};
|
|
2797
2622
|
set__default["default"](AWidget, 'MergedWidget', MergedWidget);
|
|
2798
2623
|
}
|
|
@@ -2809,31 +2634,28 @@ function mergeWidgetOptions(AWidget) {
|
|
|
2809
2634
|
* @returns - The `Widget` component to use
|
|
2810
2635
|
* @throws - An error if there is no `Widget` component that can be returned
|
|
2811
2636
|
*/
|
|
2812
|
-
function getWidget(schema, widget, registeredWidgets) {
|
|
2813
|
-
|
|
2814
|
-
registeredWidgets = {};
|
|
2815
|
-
}
|
|
2816
|
-
var type = getSchemaType(schema);
|
|
2637
|
+
function getWidget(schema, widget, registeredWidgets = {}) {
|
|
2638
|
+
const type = getSchemaType(schema);
|
|
2817
2639
|
if (typeof widget === 'function' || widget && ReactIs__default["default"].isForwardRef( /*#__PURE__*/react.createElement(widget)) || ReactIs__default["default"].isMemo(widget)) {
|
|
2818
2640
|
return mergeWidgetOptions(widget);
|
|
2819
2641
|
}
|
|
2820
2642
|
if (typeof widget !== 'string') {
|
|
2821
|
-
throw new Error(
|
|
2643
|
+
throw new Error(`Unsupported widget definition: ${typeof widget}`);
|
|
2822
2644
|
}
|
|
2823
2645
|
if (widget in registeredWidgets) {
|
|
2824
|
-
|
|
2646
|
+
const registeredWidget = registeredWidgets[widget];
|
|
2825
2647
|
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2826
2648
|
}
|
|
2827
2649
|
if (typeof type === 'string') {
|
|
2828
2650
|
if (!(type in widgetMap)) {
|
|
2829
|
-
throw new Error(
|
|
2651
|
+
throw new Error(`No widget for type '${type}'`);
|
|
2830
2652
|
}
|
|
2831
2653
|
if (widget in widgetMap[type]) {
|
|
2832
|
-
|
|
2833
|
-
return getWidget(schema,
|
|
2654
|
+
const registeredWidget = registeredWidgets[widgetMap[type][widget]];
|
|
2655
|
+
return getWidget(schema, registeredWidget, registeredWidgets);
|
|
2834
2656
|
}
|
|
2835
2657
|
}
|
|
2836
|
-
throw new Error(
|
|
2658
|
+
throw new Error(`No widget '${widget}' for type '${type}'`);
|
|
2837
2659
|
}
|
|
2838
2660
|
|
|
2839
2661
|
/** JS has no built-in hashing function, so rolling our own
|
|
@@ -2844,9 +2666,9 @@ function getWidget(schema, widget, registeredWidgets) {
|
|
|
2844
2666
|
* @returns - The resulting hash of the string in hex format
|
|
2845
2667
|
*/
|
|
2846
2668
|
function hashString(string) {
|
|
2847
|
-
|
|
2848
|
-
for (
|
|
2849
|
-
|
|
2669
|
+
let hash = 0;
|
|
2670
|
+
for (let i = 0; i < string.length; i += 1) {
|
|
2671
|
+
const chr = string.charCodeAt(i);
|
|
2850
2672
|
hash = (hash << 5) - hash + chr;
|
|
2851
2673
|
hash = hash & hash; // Convert to 32bit integer
|
|
2852
2674
|
}
|
|
@@ -2860,11 +2682,9 @@ function hashString(string) {
|
|
|
2860
2682
|
* @returns - The string obtained from the hash of the stringified schema
|
|
2861
2683
|
*/
|
|
2862
2684
|
function hashForSchema(schema) {
|
|
2863
|
-
|
|
2685
|
+
const allKeys = new Set();
|
|
2864
2686
|
// solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
|
|
2865
|
-
JSON.stringify(schema,
|
|
2866
|
-
return allKeys.add(key), value;
|
|
2867
|
-
});
|
|
2687
|
+
JSON.stringify(schema, (key, value) => (allKeys.add(key), value));
|
|
2868
2688
|
return hashString(JSON.stringify(schema, Array.from(allKeys).sort()));
|
|
2869
2689
|
}
|
|
2870
2690
|
|
|
@@ -2876,15 +2696,12 @@ function hashForSchema(schema) {
|
|
|
2876
2696
|
* @param [registeredWidgets={}] - A registry of widget name to `Widget` implementation
|
|
2877
2697
|
* @returns - True if the widget exists, false otherwise
|
|
2878
2698
|
*/
|
|
2879
|
-
function hasWidget(schema, widget, registeredWidgets) {
|
|
2880
|
-
if (registeredWidgets === void 0) {
|
|
2881
|
-
registeredWidgets = {};
|
|
2882
|
-
}
|
|
2699
|
+
function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
2883
2700
|
try {
|
|
2884
2701
|
getWidget(schema, widget, registeredWidgets);
|
|
2885
2702
|
return true;
|
|
2886
2703
|
} catch (e) {
|
|
2887
|
-
|
|
2704
|
+
const err = e;
|
|
2888
2705
|
if (err.message && (err.message.startsWith('No widget') || err.message.startsWith('Unsupported widget'))) {
|
|
2889
2706
|
return false;
|
|
2890
2707
|
}
|
|
@@ -2898,8 +2715,8 @@ function hasWidget(schema, widget, registeredWidgets) {
|
|
|
2898
2715
|
* @param suffix - The suffix to append to the id
|
|
2899
2716
|
*/
|
|
2900
2717
|
function idGenerator(id, suffix) {
|
|
2901
|
-
|
|
2902
|
-
return theId
|
|
2718
|
+
const theId = isString__default["default"](id) ? id : id[ID_KEY];
|
|
2719
|
+
return `${theId}__${suffix}`;
|
|
2903
2720
|
}
|
|
2904
2721
|
/** Return a consistent `id` for the field description element
|
|
2905
2722
|
*
|
|
@@ -2949,12 +2766,9 @@ function titleId(id) {
|
|
|
2949
2766
|
* @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
|
|
2950
2767
|
* @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
|
|
2951
2768
|
*/
|
|
2952
|
-
function ariaDescribedByIds(id, includeExamples) {
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
}
|
|
2956
|
-
var examples = includeExamples ? " " + examplesId(id) : '';
|
|
2957
|
-
return errorId(id) + " " + descriptionId(id) + " " + helpId(id) + examples;
|
|
2769
|
+
function ariaDescribedByIds(id, includeExamples = false) {
|
|
2770
|
+
const examples = includeExamples ? ` ${examplesId(id)}` : '';
|
|
2771
|
+
return `${errorId(id)} ${descriptionId(id)} ${helpId(id)}${examples}`;
|
|
2958
2772
|
}
|
|
2959
2773
|
/** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
|
|
2960
2774
|
*
|
|
@@ -2963,7 +2777,7 @@ function ariaDescribedByIds(id, includeExamples) {
|
|
|
2963
2777
|
* @returns - An id for the option index based on the parent `id`
|
|
2964
2778
|
*/
|
|
2965
2779
|
function optionId(id, optionIndex) {
|
|
2966
|
-
return id
|
|
2780
|
+
return `${id}-${optionIndex}`;
|
|
2967
2781
|
}
|
|
2968
2782
|
|
|
2969
2783
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2987,11 +2801,11 @@ function localToUTC(dateString) {
|
|
|
2987
2801
|
* @throws - Error when the schema does not have a constant value
|
|
2988
2802
|
*/
|
|
2989
2803
|
function toConstant(schema) {
|
|
2990
|
-
if (ENUM_KEY in schema && Array.isArray(schema
|
|
2991
|
-
return schema
|
|
2804
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
2805
|
+
return schema.enum[0];
|
|
2992
2806
|
}
|
|
2993
2807
|
if (CONST_KEY in schema) {
|
|
2994
|
-
return schema
|
|
2808
|
+
return schema.const;
|
|
2995
2809
|
}
|
|
2996
2810
|
throw new Error('schema cannot be inferred as a constant');
|
|
2997
2811
|
}
|
|
@@ -3007,28 +2821,28 @@ function toConstant(schema) {
|
|
|
3007
2821
|
function optionsList(schema) {
|
|
3008
2822
|
// enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
|
|
3009
2823
|
// Cast the type to include enumNames so the feature still works.
|
|
3010
|
-
|
|
2824
|
+
const schemaWithEnumNames = schema;
|
|
3011
2825
|
if (schemaWithEnumNames.enumNames && "development" !== 'production') {
|
|
3012
2826
|
console.warn('The enumNames property is deprecated and may be removed in a future major release.');
|
|
3013
2827
|
}
|
|
3014
|
-
if (schema
|
|
3015
|
-
return schema
|
|
3016
|
-
|
|
2828
|
+
if (schema.enum) {
|
|
2829
|
+
return schema.enum.map((value, i) => {
|
|
2830
|
+
const label = schemaWithEnumNames.enumNames && schemaWithEnumNames.enumNames[i] || String(value);
|
|
3017
2831
|
return {
|
|
3018
|
-
label
|
|
3019
|
-
value
|
|
2832
|
+
label,
|
|
2833
|
+
value
|
|
3020
2834
|
};
|
|
3021
2835
|
});
|
|
3022
2836
|
}
|
|
3023
|
-
|
|
3024
|
-
return altSchemas && altSchemas.map(
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
2837
|
+
const altSchemas = schema.oneOf || schema.anyOf;
|
|
2838
|
+
return altSchemas && altSchemas.map(aSchemaDef => {
|
|
2839
|
+
const aSchema = aSchemaDef;
|
|
2840
|
+
const value = toConstant(aSchema);
|
|
2841
|
+
const label = aSchema.title || String(value);
|
|
3028
2842
|
return {
|
|
3029
2843
|
schema: aSchema,
|
|
3030
|
-
label
|
|
3031
|
-
value
|
|
2844
|
+
label,
|
|
2845
|
+
value
|
|
3032
2846
|
};
|
|
3033
2847
|
});
|
|
3034
2848
|
}
|
|
@@ -3047,35 +2861,27 @@ function orderProperties(properties, order) {
|
|
|
3047
2861
|
if (!Array.isArray(order)) {
|
|
3048
2862
|
return properties;
|
|
3049
2863
|
}
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
var orderFiltered = order.filter(function (prop) {
|
|
3061
|
-
return prop === '*' || propertyHash[prop];
|
|
3062
|
-
});
|
|
3063
|
-
var orderHash = arrayToHash(orderFiltered);
|
|
3064
|
-
var rest = properties.filter(function (prop) {
|
|
3065
|
-
return !orderHash[prop];
|
|
3066
|
-
});
|
|
3067
|
-
var restIndex = orderFiltered.indexOf('*');
|
|
2864
|
+
const arrayToHash = arr => arr.reduce((prev, curr) => {
|
|
2865
|
+
prev[curr] = true;
|
|
2866
|
+
return prev;
|
|
2867
|
+
}, {});
|
|
2868
|
+
const errorPropList = arr => arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
|
|
2869
|
+
const propertyHash = arrayToHash(properties);
|
|
2870
|
+
const orderFiltered = order.filter(prop => prop === '*' || propertyHash[prop]);
|
|
2871
|
+
const orderHash = arrayToHash(orderFiltered);
|
|
2872
|
+
const rest = properties.filter(prop => !orderHash[prop]);
|
|
2873
|
+
const restIndex = orderFiltered.indexOf('*');
|
|
3068
2874
|
if (restIndex === -1) {
|
|
3069
2875
|
if (rest.length) {
|
|
3070
|
-
throw new Error(
|
|
2876
|
+
throw new Error(`uiSchema order list does not contain ${errorPropList(rest)}`);
|
|
3071
2877
|
}
|
|
3072
2878
|
return orderFiltered;
|
|
3073
2879
|
}
|
|
3074
2880
|
if (restIndex !== orderFiltered.lastIndexOf('*')) {
|
|
3075
2881
|
throw new Error('uiSchema order list contains more than one wildcard item');
|
|
3076
2882
|
}
|
|
3077
|
-
|
|
3078
|
-
complete.splice
|
|
2883
|
+
const complete = [...orderFiltered];
|
|
2884
|
+
complete.splice(restIndex, 1, ...rest);
|
|
3079
2885
|
return complete;
|
|
3080
2886
|
}
|
|
3081
2887
|
|
|
@@ -3086,7 +2892,7 @@ function orderProperties(properties, order) {
|
|
|
3086
2892
|
* @returns - The number converted to a string with leading zero padding if the number of digits is less than `width`
|
|
3087
2893
|
*/
|
|
3088
2894
|
function pad(num, width) {
|
|
3089
|
-
|
|
2895
|
+
let s = String(num);
|
|
3090
2896
|
while (s.length < width) {
|
|
3091
2897
|
s = '0' + s;
|
|
3092
2898
|
}
|
|
@@ -3100,10 +2906,7 @@ function pad(num, width) {
|
|
|
3100
2906
|
* @returns - The date string converted to a `DateObject`
|
|
3101
2907
|
* @throws - Error when the date cannot be parsed from the string
|
|
3102
2908
|
*/
|
|
3103
|
-
function parseDateString(dateString, includeTime) {
|
|
3104
|
-
if (includeTime === void 0) {
|
|
3105
|
-
includeTime = true;
|
|
3106
|
-
}
|
|
2909
|
+
function parseDateString(dateString, includeTime = true) {
|
|
3107
2910
|
if (!dateString) {
|
|
3108
2911
|
return {
|
|
3109
2912
|
year: -1,
|
|
@@ -3114,7 +2917,7 @@ function parseDateString(dateString, includeTime) {
|
|
|
3114
2917
|
second: includeTime ? -1 : 0
|
|
3115
2918
|
};
|
|
3116
2919
|
}
|
|
3117
|
-
|
|
2920
|
+
const date = new Date(dateString);
|
|
3118
2921
|
if (Number.isNaN(date.getTime())) {
|
|
3119
2922
|
throw new Error('Unable to parse date ' + dateString);
|
|
3120
2923
|
}
|
|
@@ -3139,11 +2942,11 @@ function parseDateString(dateString, includeTime) {
|
|
|
3139
2942
|
*/
|
|
3140
2943
|
function schemaRequiresTrueValue(schema) {
|
|
3141
2944
|
// Check if const is a truthy value
|
|
3142
|
-
if (schema
|
|
2945
|
+
if (schema.const) {
|
|
3143
2946
|
return true;
|
|
3144
2947
|
}
|
|
3145
2948
|
// Check if an enum has a single value of true
|
|
3146
|
-
if (schema
|
|
2949
|
+
if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
|
|
3147
2950
|
return true;
|
|
3148
2951
|
}
|
|
3149
2952
|
// If anyOf has a single value, evaluate the subschema
|
|
@@ -3156,9 +2959,7 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3156
2959
|
}
|
|
3157
2960
|
// Evaluate each subschema in allOf, to see if one of them requires a true value
|
|
3158
2961
|
if (schema.allOf) {
|
|
3159
|
-
|
|
3160
|
-
return schemaRequiresTrueValue(subSchema);
|
|
3161
|
-
};
|
|
2962
|
+
const schemaSome = subSchema => schemaRequiresTrueValue(subSchema);
|
|
3162
2963
|
return schema.allOf.some(schemaSome);
|
|
3163
2964
|
}
|
|
3164
2965
|
return false;
|
|
@@ -3173,8 +2974,10 @@ function schemaRequiresTrueValue(schema) {
|
|
|
3173
2974
|
* @returns - True if the component should be re-rendered, false otherwise
|
|
3174
2975
|
*/
|
|
3175
2976
|
function shouldRender(component, nextProps, nextState) {
|
|
3176
|
-
|
|
3177
|
-
|
|
2977
|
+
const {
|
|
2978
|
+
props,
|
|
2979
|
+
state
|
|
2980
|
+
} = component;
|
|
3178
2981
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
3179
2982
|
}
|
|
3180
2983
|
|
|
@@ -3185,21 +2988,17 @@ function shouldRender(component, nextProps, nextState) {
|
|
|
3185
2988
|
* @param [time=true] - Optional flag used to remove the time portion of the date string if false
|
|
3186
2989
|
* @returns - The UTC date string
|
|
3187
2990
|
*/
|
|
3188
|
-
function toDateString(dateObject, time) {
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
_dateObject$second = dateObject.second,
|
|
3200
|
-
second = _dateObject$second === void 0 ? 0 : _dateObject$second;
|
|
3201
|
-
var utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
|
|
3202
|
-
var datetime = new Date(utcTime).toJSON();
|
|
2991
|
+
function toDateString(dateObject, time = true) {
|
|
2992
|
+
const {
|
|
2993
|
+
year,
|
|
2994
|
+
month,
|
|
2995
|
+
day,
|
|
2996
|
+
hour = 0,
|
|
2997
|
+
minute = 0,
|
|
2998
|
+
second = 0
|
|
2999
|
+
} = dateObject;
|
|
3000
|
+
const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
|
|
3001
|
+
const datetime = new Date(utcTime).toJSON();
|
|
3203
3002
|
return time ? datetime : datetime.slice(0, 10);
|
|
3204
3003
|
}
|
|
3205
3004
|
|
|
@@ -3209,29 +3008,26 @@ function toDateString(dateObject, time) {
|
|
|
3209
3008
|
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
3210
3009
|
* @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
|
|
3211
3010
|
*/
|
|
3212
|
-
function toErrorList(errorSchema, fieldPath) {
|
|
3213
|
-
if (fieldPath === void 0) {
|
|
3214
|
-
fieldPath = [];
|
|
3215
|
-
}
|
|
3011
|
+
function toErrorList(errorSchema, fieldPath = []) {
|
|
3216
3012
|
if (!errorSchema) {
|
|
3217
3013
|
return [];
|
|
3218
3014
|
}
|
|
3219
|
-
|
|
3015
|
+
let errorList = [];
|
|
3220
3016
|
if (ERRORS_KEY in errorSchema) {
|
|
3221
|
-
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(
|
|
3222
|
-
|
|
3017
|
+
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(message => {
|
|
3018
|
+
const property = `.${fieldPath.join('.')}`;
|
|
3223
3019
|
return {
|
|
3224
|
-
property
|
|
3225
|
-
message
|
|
3226
|
-
stack: property
|
|
3020
|
+
property,
|
|
3021
|
+
message,
|
|
3022
|
+
stack: `${property} ${message}`
|
|
3227
3023
|
};
|
|
3228
3024
|
}));
|
|
3229
3025
|
}
|
|
3230
|
-
return Object.keys(errorSchema).reduce(
|
|
3026
|
+
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
3231
3027
|
if (key !== ERRORS_KEY) {
|
|
3232
|
-
|
|
3028
|
+
const childSchema = errorSchema[key];
|
|
3233
3029
|
if (isPlainObject__default["default"](childSchema)) {
|
|
3234
|
-
acc = acc.concat(toErrorList(childSchema, [
|
|
3030
|
+
acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
3235
3031
|
}
|
|
3236
3032
|
}
|
|
3237
3033
|
return acc;
|
|
@@ -3258,13 +3054,15 @@ function toErrorList(errorSchema, fieldPath) {
|
|
|
3258
3054
|
* @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
|
|
3259
3055
|
*/
|
|
3260
3056
|
function toErrorSchema(errors) {
|
|
3261
|
-
|
|
3057
|
+
const builder = new ErrorSchemaBuilder();
|
|
3262
3058
|
if (errors.length) {
|
|
3263
|
-
errors.forEach(
|
|
3264
|
-
|
|
3265
|
-
|
|
3059
|
+
errors.forEach(error => {
|
|
3060
|
+
const {
|
|
3061
|
+
property,
|
|
3062
|
+
message
|
|
3063
|
+
} = error;
|
|
3266
3064
|
// When the property is the root element, just use an empty array for the path
|
|
3267
|
-
|
|
3065
|
+
const path = property === '.' ? [] : toPath__default["default"](property);
|
|
3268
3066
|
// If the property is at the root (.level1) then toPath creates
|
|
3269
3067
|
// an empty array element at the first index. Remove it.
|
|
3270
3068
|
if (path.length > 0 && path[0] === '') {
|
|
@@ -3284,17 +3082,21 @@ function toErrorSchema(errors) {
|
|
|
3284
3082
|
* @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
|
|
3285
3083
|
*/
|
|
3286
3084
|
function unwrapErrorHandler(errorHandler) {
|
|
3287
|
-
return Object.keys(errorHandler).reduce(
|
|
3085
|
+
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
3288
3086
|
if (key === 'addError') {
|
|
3289
3087
|
return acc;
|
|
3290
3088
|
} else {
|
|
3291
|
-
|
|
3292
|
-
var childSchema = errorHandler[key];
|
|
3089
|
+
const childSchema = errorHandler[key];
|
|
3293
3090
|
if (isPlainObject__default["default"](childSchema)) {
|
|
3294
|
-
|
|
3295
|
-
|
|
3091
|
+
return {
|
|
3092
|
+
...acc,
|
|
3093
|
+
[key]: unwrapErrorHandler(childSchema)
|
|
3094
|
+
};
|
|
3296
3095
|
}
|
|
3297
|
-
return
|
|
3096
|
+
return {
|
|
3097
|
+
...acc,
|
|
3098
|
+
[key]: childSchema
|
|
3099
|
+
};
|
|
3298
3100
|
}
|
|
3299
3101
|
}, {});
|
|
3300
3102
|
}
|
|
@@ -3313,15 +3115,15 @@ function utcToLocal(jsonDate) {
|
|
|
3313
3115
|
// > should be a _valid local date and time string_ (not GMT)
|
|
3314
3116
|
// Note - date constructor passed local ISO-8601 does not correctly
|
|
3315
3117
|
// change time to UTC in node pre-8
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
return yyyy
|
|
3118
|
+
const date = new Date(jsonDate);
|
|
3119
|
+
const yyyy = pad(date.getFullYear(), 4);
|
|
3120
|
+
const MM = pad(date.getMonth() + 1, 2);
|
|
3121
|
+
const dd = pad(date.getDate(), 2);
|
|
3122
|
+
const hh = pad(date.getHours(), 2);
|
|
3123
|
+
const mm = pad(date.getMinutes(), 2);
|
|
3124
|
+
const ss = pad(date.getSeconds(), 2);
|
|
3125
|
+
const SSS = pad(date.getMilliseconds(), 3);
|
|
3126
|
+
return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
|
|
3325
3127
|
}
|
|
3326
3128
|
|
|
3327
3129
|
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
@@ -3337,17 +3139,19 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
3337
3139
|
if (!additionalErrorSchema) {
|
|
3338
3140
|
return validationData;
|
|
3339
3141
|
}
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3142
|
+
const {
|
|
3143
|
+
errors: oldErrors,
|
|
3144
|
+
errorSchema: oldErrorSchema
|
|
3145
|
+
} = validationData;
|
|
3146
|
+
let errors = toErrorList(additionalErrorSchema);
|
|
3147
|
+
let errorSchema = additionalErrorSchema;
|
|
3344
3148
|
if (!isEmpty__default["default"](oldErrorSchema)) {
|
|
3345
3149
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
3346
|
-
errors = [].concat(
|
|
3150
|
+
errors = [...oldErrors].concat(errors);
|
|
3347
3151
|
}
|
|
3348
3152
|
return {
|
|
3349
|
-
errorSchema
|
|
3350
|
-
errors
|
|
3153
|
+
errorSchema,
|
|
3154
|
+
errors
|
|
3351
3155
|
};
|
|
3352
3156
|
}
|
|
3353
3157
|
|
|
@@ -3357,9 +3161,9 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
3357
3161
|
* @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
3358
3162
|
*/
|
|
3359
3163
|
function withIdRefPrefixObject(node) {
|
|
3360
|
-
for (
|
|
3361
|
-
|
|
3362
|
-
|
|
3164
|
+
for (const key in node) {
|
|
3165
|
+
const realObj = node;
|
|
3166
|
+
const value = realObj[key];
|
|
3363
3167
|
if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
|
|
3364
3168
|
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
3365
3169
|
} else {
|
|
@@ -3374,7 +3178,7 @@ function withIdRefPrefixObject(node) {
|
|
|
3374
3178
|
* @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
3375
3179
|
*/
|
|
3376
3180
|
function withIdRefPrefixArray(node) {
|
|
3377
|
-
for (
|
|
3181
|
+
for (let i = 0; i < node.length; i++) {
|
|
3378
3182
|
node[i] = withIdRefPrefix(node[i]);
|
|
3379
3183
|
}
|
|
3380
3184
|
return node;
|
|
@@ -3386,11 +3190,13 @@ function withIdRefPrefixArray(node) {
|
|
|
3386
3190
|
* @returns - A copy of the `schemaNode` with updated `$ref`s
|
|
3387
3191
|
*/
|
|
3388
3192
|
function withIdRefPrefix(schemaNode) {
|
|
3389
|
-
if (schemaNode.constructor === Object) {
|
|
3390
|
-
return withIdRefPrefixObject(_extends({}, schemaNode));
|
|
3391
|
-
}
|
|
3392
3193
|
if (Array.isArray(schemaNode)) {
|
|
3393
|
-
return withIdRefPrefixArray([]
|
|
3194
|
+
return withIdRefPrefixArray([...schemaNode]);
|
|
3195
|
+
}
|
|
3196
|
+
if (isObject__default["default"](schemaNode)) {
|
|
3197
|
+
return withIdRefPrefixObject({
|
|
3198
|
+
...schemaNode
|
|
3199
|
+
});
|
|
3394
3200
|
}
|
|
3395
3201
|
return schemaNode;
|
|
3396
3202
|
}
|
|
@@ -3478,13 +3284,13 @@ exports.TranslatableString = void 0;
|
|
|
3478
3284
|
* the hashed value of the schema. NOTE: After hashing the schema, an $id with the hash value is added to the
|
|
3479
3285
|
* schema IF that schema doesn't already have an $id, prior to putting the schema into the map.
|
|
3480
3286
|
*/
|
|
3481
|
-
|
|
3287
|
+
class ParserValidator {
|
|
3482
3288
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
3483
3289
|
* first.
|
|
3484
3290
|
*
|
|
3485
3291
|
* @param rootSchema - The root schema against which this validator will be executed
|
|
3486
3292
|
*/
|
|
3487
|
-
|
|
3293
|
+
constructor(rootSchema) {
|
|
3488
3294
|
/** The rootSchema provided during construction of the class */
|
|
3489
3295
|
this.rootSchema = void 0;
|
|
3490
3296
|
/** The map of schemas encountered by the ParserValidator */
|
|
@@ -3499,23 +3305,24 @@ var ParserValidator = /*#__PURE__*/function () {
|
|
|
3499
3305
|
* @param schema - The schema which is to be added to the map
|
|
3500
3306
|
* @param hash - The hash value at which to map the schema
|
|
3501
3307
|
*/
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3308
|
+
addSchema(schema, hash) {
|
|
3309
|
+
const key = get__default["default"](schema, ID_KEY, hash);
|
|
3310
|
+
const identifiedSchema = {
|
|
3311
|
+
...schema,
|
|
3312
|
+
[ID_KEY]: key
|
|
3313
|
+
};
|
|
3314
|
+
const existing = this.schemaMap[key];
|
|
3508
3315
|
if (!existing) {
|
|
3509
3316
|
this.schemaMap[key] = identifiedSchema;
|
|
3510
3317
|
} else if (!isEqual__default["default"](existing, identifiedSchema)) {
|
|
3511
3318
|
console.error('existing schema:', JSON.stringify(existing, null, 2));
|
|
3512
3319
|
console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
|
|
3513
|
-
throw new Error(
|
|
3320
|
+
throw new Error(`Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`);
|
|
3514
3321
|
}
|
|
3515
3322
|
}
|
|
3516
3323
|
/** Returns the current `schemaMap` to the caller
|
|
3517
|
-
|
|
3518
|
-
|
|
3324
|
+
*/
|
|
3325
|
+
getSchemaMap() {
|
|
3519
3326
|
return this.schemaMap;
|
|
3520
3327
|
}
|
|
3521
3328
|
/** Implements the `ValidatorType` `isValid()` method to capture the `schema` in the `schemaMap`. Throws an error when
|
|
@@ -3525,8 +3332,8 @@ var ParserValidator = /*#__PURE__*/function () {
|
|
|
3525
3332
|
* @param _formData - The formData parameter that is ignored
|
|
3526
3333
|
* @param rootSchema - The root schema associated with the schema
|
|
3527
3334
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
3528
|
-
|
|
3529
|
-
|
|
3335
|
+
*/
|
|
3336
|
+
isValid(schema, _formData, rootSchema) {
|
|
3530
3337
|
if (!isEqual__default["default"](rootSchema, this.rootSchema)) {
|
|
3531
3338
|
throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
|
|
3532
3339
|
}
|
|
@@ -3537,16 +3344,16 @@ var ParserValidator = /*#__PURE__*/function () {
|
|
|
3537
3344
|
*
|
|
3538
3345
|
* @param _schema - The schema parameter that is ignored
|
|
3539
3346
|
* @param _formData - The formData parameter that is ignored
|
|
3540
|
-
|
|
3541
|
-
|
|
3347
|
+
*/
|
|
3348
|
+
rawValidation(_schema, _formData) {
|
|
3542
3349
|
throw new Error('Unexpectedly calling the `rawValidation()` method during schema parsing');
|
|
3543
3350
|
}
|
|
3544
3351
|
/** Implements the `ValidatorType` `toErrorList()` method to throw an error since it is never supposed to be called
|
|
3545
3352
|
*
|
|
3546
3353
|
* @param _errorSchema - The error schema parameter that is ignored
|
|
3547
3354
|
* @param _fieldPath - The field path parameter that is ignored
|
|
3548
|
-
|
|
3549
|
-
|
|
3355
|
+
*/
|
|
3356
|
+
toErrorList(_errorSchema, _fieldPath) {
|
|
3550
3357
|
throw new Error('Unexpectedly calling the `toErrorList()` method during schema parsing');
|
|
3551
3358
|
}
|
|
3552
3359
|
/** Implements the `ValidatorType` `validateFormData()` method to throw an error since it is never supposed to be
|
|
@@ -3557,12 +3364,11 @@ var ParserValidator = /*#__PURE__*/function () {
|
|
|
3557
3364
|
* @param _customValidate - The customValidate parameter that is ignored
|
|
3558
3365
|
* @param _transformErrors - The transformErrors parameter that is ignored
|
|
3559
3366
|
* @param _uiSchema - The uiSchema parameter that is ignored
|
|
3560
|
-
|
|
3561
|
-
|
|
3367
|
+
*/
|
|
3368
|
+
validateFormData(_formData, _schema, _customValidate, _transformErrors, _uiSchema) {
|
|
3562
3369
|
throw new Error('Unexpectedly calling the `validateFormData()` method during schema parsing');
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
}();
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3566
3372
|
|
|
3567
3373
|
/** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
|
|
3568
3374
|
* capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
|
|
@@ -3575,17 +3381,15 @@ var ParserValidator = /*#__PURE__*/function () {
|
|
|
3575
3381
|
* @param schema - The current schema element being parsed
|
|
3576
3382
|
*/
|
|
3577
3383
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
3578
|
-
|
|
3579
|
-
schemas.forEach(
|
|
3580
|
-
|
|
3581
|
-
return isEqual__default["default"](item, schema);
|
|
3582
|
-
});
|
|
3384
|
+
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true);
|
|
3385
|
+
schemas.forEach(schema => {
|
|
3386
|
+
const sameSchemaIndex = recurseList.findIndex(item => isEqual__default["default"](item, schema));
|
|
3583
3387
|
if (sameSchemaIndex === -1) {
|
|
3584
3388
|
recurseList.push(schema);
|
|
3585
|
-
|
|
3586
|
-
allOptions.forEach(
|
|
3389
|
+
const allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true);
|
|
3390
|
+
allOptions.forEach(s => {
|
|
3587
3391
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
3588
|
-
forEach__default["default"](schema[PROPERTIES_KEY],
|
|
3392
|
+
forEach__default["default"](schema[PROPERTIES_KEY], value => {
|
|
3589
3393
|
parseSchema(validator, recurseList, rootSchema, value);
|
|
3590
3394
|
});
|
|
3591
3395
|
}
|
|
@@ -3603,8 +3407,8 @@ function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
|
3603
3407
|
* @returns - The `SchemaMap` of all schemas that were parsed
|
|
3604
3408
|
*/
|
|
3605
3409
|
function schemaParser(rootSchema) {
|
|
3606
|
-
|
|
3607
|
-
|
|
3410
|
+
const validator = new ParserValidator(rootSchema);
|
|
3411
|
+
const recurseList = [];
|
|
3608
3412
|
parseSchema(validator, recurseList, rootSchema, rootSchema);
|
|
3609
3413
|
return validator.getSchemaMap();
|
|
3610
3414
|
}
|