@rjsf/utils 5.5.2 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +91 -10
- package/dist/utils.cjs.development.js +250 -21
- 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 +242 -22
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +252 -25
- 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 +6 -5
package/dist/utils.esm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import isPlainObject from 'lodash-es/isPlainObject';
|
|
1
2
|
import isEqualWith from 'lodash-es/isEqualWith';
|
|
2
3
|
import get from 'lodash-es/get';
|
|
3
4
|
import isEmpty from 'lodash-es/isEmpty';
|
|
@@ -16,6 +17,7 @@ import cloneDeep from 'lodash-es/cloneDeep';
|
|
|
16
17
|
import { jsx } from 'react/jsx-runtime';
|
|
17
18
|
import { createElement } from 'react';
|
|
18
19
|
import ReactIs from 'react-is';
|
|
20
|
+
import toPath from 'lodash-es/toPath';
|
|
19
21
|
|
|
20
22
|
/** Determines whether a `thing` is an object for the purposes of RSJF. In this case, `thing` is an object if it has
|
|
21
23
|
* the type `object` but is NOT null, an array or a File.
|
|
@@ -167,6 +169,7 @@ var REQUIRED_KEY = 'required';
|
|
|
167
169
|
var SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
168
170
|
var REF_KEY = '$ref';
|
|
169
171
|
var RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
|
|
172
|
+
var ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
|
|
170
173
|
var UI_FIELD_KEY = 'ui:field';
|
|
171
174
|
var UI_WIDGET_KEY = 'ui:widget';
|
|
172
175
|
var UI_OPTIONS_KEY = 'ui:options';
|
|
@@ -232,6 +235,32 @@ function canExpand(schema, uiSchema, formData) {
|
|
|
232
235
|
return true;
|
|
233
236
|
}
|
|
234
237
|
|
|
238
|
+
/** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
|
|
239
|
+
*
|
|
240
|
+
* @param formData - The form data around which the error handler is created
|
|
241
|
+
* @returns - A `FormValidation` object based on the `formData` structure
|
|
242
|
+
*/
|
|
243
|
+
function createErrorHandler(formData) {
|
|
244
|
+
var _handler;
|
|
245
|
+
var handler = (_handler = {}, _handler[ERRORS_KEY] = [], _handler.addError = function addError(message) {
|
|
246
|
+
this[ERRORS_KEY].push(message);
|
|
247
|
+
}, _handler);
|
|
248
|
+
if (Array.isArray(formData)) {
|
|
249
|
+
return formData.reduce(function (acc, value, key) {
|
|
250
|
+
var _extends2;
|
|
251
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[key] = createErrorHandler(value), _extends2));
|
|
252
|
+
}, handler);
|
|
253
|
+
}
|
|
254
|
+
if (isPlainObject(formData)) {
|
|
255
|
+
var formObject = formData;
|
|
256
|
+
return Object.keys(formObject).reduce(function (acc, key) {
|
|
257
|
+
var _extends3;
|
|
258
|
+
return _extends({}, acc, (_extends3 = {}, _extends3[key] = createErrorHandler(formObject[key]), _extends3));
|
|
259
|
+
}, handler);
|
|
260
|
+
}
|
|
261
|
+
return handler;
|
|
262
|
+
}
|
|
263
|
+
|
|
235
264
|
/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
|
|
236
265
|
* assumes all functions are equivalent.
|
|
237
266
|
*
|
|
@@ -307,10 +336,12 @@ function findSchemaDefinition($ref, rootSchema) {
|
|
|
307
336
|
* @param formData - The current formData, if any, used to figure out a match
|
|
308
337
|
* @param options - The list of options to find a matching options from
|
|
309
338
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
339
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
340
|
+
* determine which option is selected
|
|
310
341
|
* @returns - The index of the matched option or 0 if none is available
|
|
311
342
|
* @deprecated
|
|
312
343
|
*/
|
|
313
|
-
function getMatchingOption(validator, formData, options, rootSchema) {
|
|
344
|
+
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
314
345
|
// For performance, skip validating subschemas if formData is undefined. We just
|
|
315
346
|
// want to get the first option in that case.
|
|
316
347
|
if (formData === undefined) {
|
|
@@ -318,18 +349,26 @@ function getMatchingOption(validator, formData, options, rootSchema) {
|
|
|
318
349
|
}
|
|
319
350
|
for (var i = 0; i < options.length; i++) {
|
|
320
351
|
var option = options[i];
|
|
321
|
-
// If
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (option
|
|
352
|
+
// If we have a discriminator field, then we will use this to make the determination
|
|
353
|
+
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
354
|
+
var value = get(formData, discriminatorField);
|
|
355
|
+
var discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
356
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
357
|
+
return i;
|
|
358
|
+
}
|
|
359
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
360
|
+
// If the schema describes an object then we need to add slightly more
|
|
361
|
+
// strict matching to the schema, because unless the schema uses the
|
|
362
|
+
// "requires" keyword, an object will match the schema as long as it
|
|
363
|
+
// doesn't have matching keys with a conflicting type. To do this we use an
|
|
364
|
+
// "anyOf" with an array of requires. This augmentation expresses that the
|
|
365
|
+
// schema should match if any of the keys in the schema are present on the
|
|
366
|
+
// object and pass validation.
|
|
367
|
+
//
|
|
329
368
|
// Create an "anyOf" schema that requires at least one of the keys in the
|
|
330
369
|
// "properties" object
|
|
331
370
|
var requiresAnyOf = {
|
|
332
|
-
anyOf: Object.keys(option
|
|
371
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map(function (key) {
|
|
333
372
|
return {
|
|
334
373
|
required: [key]
|
|
335
374
|
};
|
|
@@ -371,10 +410,12 @@ function getMatchingOption(validator, formData, options, rootSchema) {
|
|
|
371
410
|
* @param formData - The current formData, if any, used to figure out a match
|
|
372
411
|
* @param options - The list of options to find a matching options from
|
|
373
412
|
* @param rootSchema - The root schema, used to primarily to look up `$ref`s
|
|
413
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
414
|
+
* determine which option is selected
|
|
374
415
|
* @returns - The index of the first matched option or 0 if none is available
|
|
375
416
|
*/
|
|
376
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema) {
|
|
377
|
-
return getMatchingOption(validator, formData, options, rootSchema);
|
|
417
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
418
|
+
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
378
419
|
}
|
|
379
420
|
|
|
380
421
|
/** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
|
|
@@ -850,16 +891,18 @@ function calculateIndexScore(validator, rootSchema, schema, formData) {
|
|
|
850
891
|
* @param formData - The form data associated with the schema
|
|
851
892
|
* @param options - The list of options that can be selected from
|
|
852
893
|
* @param [selectedOption=-1] - The index of the currently selected option, defaulted to -1 if not specified
|
|
894
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
895
|
+
* determine which option is selected
|
|
853
896
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
854
897
|
*/
|
|
855
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption) {
|
|
898
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption, discriminatorField) {
|
|
856
899
|
if (selectedOption === void 0) {
|
|
857
900
|
selectedOption = -1;
|
|
858
901
|
}
|
|
859
902
|
// Reduce the array of options down to a list of the indexes that are considered matching options
|
|
860
903
|
var allValidIndexes = options.reduce(function (validList, option, index) {
|
|
861
904
|
var testOptions = [JUNK_OPTION, option];
|
|
862
|
-
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema);
|
|
905
|
+
var match = getFirstMatchingOption(validator, formData, testOptions, rootSchema, discriminatorField);
|
|
863
906
|
// The match is the real option, so add its index to list of valid indexes
|
|
864
907
|
if (match === 1) {
|
|
865
908
|
validList.push(index);
|
|
@@ -1353,6 +1396,8 @@ function getDisplayLabel(validator, schema, uiSchema, rootSchema, globalOptions)
|
|
|
1353
1396
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1354
1397
|
* @param [additionalErrorSchema] - The additional set of errors in an `ErrorSchema`
|
|
1355
1398
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1399
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1400
|
+
* removed in the next major release.
|
|
1356
1401
|
*/
|
|
1357
1402
|
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1358
1403
|
if (!additionalErrorSchema) {
|
|
@@ -1568,7 +1613,7 @@ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSc
|
|
|
1568
1613
|
var idSchema = {
|
|
1569
1614
|
$id: $id
|
|
1570
1615
|
};
|
|
1571
|
-
if (schema
|
|
1616
|
+
if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
|
|
1572
1617
|
for (var name in schema.properties) {
|
|
1573
1618
|
var field = get(schema, [PROPERTIES_KEY, name]);
|
|
1574
1619
|
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
@@ -1746,31 +1791,37 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
1746
1791
|
* @param formData - The form data associated with the schema
|
|
1747
1792
|
* @param options - The list of options that can be selected from
|
|
1748
1793
|
* @param [selectedOption] - The index of the currently selected option, defaulted to -1 if not specified
|
|
1794
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1795
|
+
* determine which option is selected
|
|
1749
1796
|
* @returns - The index of the option that is the closest match to the `formData` or the `selectedOption` if no match
|
|
1750
1797
|
*/;
|
|
1751
|
-
_proto.getClosestMatchingOption = function getClosestMatchingOption$1(formData, options, selectedOption) {
|
|
1752
|
-
return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption);
|
|
1798
|
+
_proto.getClosestMatchingOption = function getClosestMatchingOption$1(formData, options, selectedOption, discriminatorField) {
|
|
1799
|
+
return getClosestMatchingOption(this.validator, this.rootSchema, formData, options, selectedOption, discriminatorField);
|
|
1753
1800
|
}
|
|
1754
1801
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
1755
1802
|
* Always returns the first option if there is nothing that matches.
|
|
1756
1803
|
*
|
|
1757
1804
|
* @param formData - The current formData, if any, used to figure out a match
|
|
1758
1805
|
* @param options - The list of options to find a matching options from
|
|
1806
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1807
|
+
* determine which option is selected
|
|
1759
1808
|
* @returns - The firstindex of the matched option or 0 if none is available
|
|
1760
1809
|
*/;
|
|
1761
|
-
_proto.getFirstMatchingOption = function getFirstMatchingOption$1(formData, options) {
|
|
1762
|
-
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema);
|
|
1810
|
+
_proto.getFirstMatchingOption = function getFirstMatchingOption$1(formData, options, discriminatorField) {
|
|
1811
|
+
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1763
1812
|
}
|
|
1764
1813
|
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data.
|
|
1765
1814
|
* Deprecated, use `getFirstMatchingOption()` instead.
|
|
1766
1815
|
*
|
|
1767
1816
|
* @param formData - The current formData, if any, onto which to provide any missing defaults
|
|
1768
1817
|
* @param options - The list of options to find a matching options from
|
|
1818
|
+
* @param [discriminatorField] - The optional name of the field within the options object whose value is used to
|
|
1819
|
+
* determine which option is selected
|
|
1769
1820
|
* @returns - The index of the matched option or 0 if none is available
|
|
1770
1821
|
* @deprecated
|
|
1771
1822
|
*/;
|
|
1772
|
-
_proto.getMatchingOption = function getMatchingOption$1(formData, options) {
|
|
1773
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema);
|
|
1823
|
+
_proto.getMatchingOption = function getMatchingOption$1(formData, options, discriminatorField) {
|
|
1824
|
+
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1774
1825
|
}
|
|
1775
1826
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1776
1827
|
*
|
|
@@ -1805,6 +1856,8 @@ var SchemaUtils = /*#__PURE__*/function () {
|
|
|
1805
1856
|
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1806
1857
|
* @param [additionalErrorSchema] - The additional set of errors
|
|
1807
1858
|
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1859
|
+
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1860
|
+
* removed in the next major release.
|
|
1808
1861
|
*/;
|
|
1809
1862
|
_proto.mergeValidationData = function mergeValidationData$1(validationData, additionalErrorSchema) {
|
|
1810
1863
|
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
@@ -2762,6 +2815,102 @@ function toDateString(dateObject, time) {
|
|
|
2762
2815
|
return time ? datetime : datetime.slice(0, 10);
|
|
2763
2816
|
}
|
|
2764
2817
|
|
|
2818
|
+
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
2819
|
+
*
|
|
2820
|
+
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
2821
|
+
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
2822
|
+
* @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
|
|
2823
|
+
*/
|
|
2824
|
+
function toErrorList(errorSchema, fieldPath) {
|
|
2825
|
+
if (fieldPath === void 0) {
|
|
2826
|
+
fieldPath = [];
|
|
2827
|
+
}
|
|
2828
|
+
if (!errorSchema) {
|
|
2829
|
+
return [];
|
|
2830
|
+
}
|
|
2831
|
+
var errorList = [];
|
|
2832
|
+
if (ERRORS_KEY in errorSchema) {
|
|
2833
|
+
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(function (message) {
|
|
2834
|
+
var property = "." + fieldPath.join('.');
|
|
2835
|
+
return {
|
|
2836
|
+
property: property,
|
|
2837
|
+
message: message,
|
|
2838
|
+
stack: property + " " + message
|
|
2839
|
+
};
|
|
2840
|
+
}));
|
|
2841
|
+
}
|
|
2842
|
+
return Object.keys(errorSchema).reduce(function (acc, key) {
|
|
2843
|
+
if (key !== ERRORS_KEY) {
|
|
2844
|
+
var childSchema = errorSchema[key];
|
|
2845
|
+
if (isPlainObject(childSchema)) {
|
|
2846
|
+
acc = acc.concat(toErrorList(childSchema, [].concat(fieldPath, [key])));
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
return acc;
|
|
2850
|
+
}, errorList);
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
/** Transforms a rjsf validation errors list:
|
|
2854
|
+
* [
|
|
2855
|
+
* {property: '.level1.level2[2].level3', message: 'err a'},
|
|
2856
|
+
* {property: '.level1.level2[2].level3', message: 'err b'},
|
|
2857
|
+
* {property: '.level1.level2[4].level3', message: 'err b'},
|
|
2858
|
+
* ]
|
|
2859
|
+
* Into an error tree:
|
|
2860
|
+
* {
|
|
2861
|
+
* level1: {
|
|
2862
|
+
* level2: {
|
|
2863
|
+
* 2: {level3: {errors: ['err a', 'err b']}},
|
|
2864
|
+
* 4: {level3: {errors: ['err b']}},
|
|
2865
|
+
* }
|
|
2866
|
+
* }
|
|
2867
|
+
* };
|
|
2868
|
+
*
|
|
2869
|
+
* @param errors - The list of RJSFValidationError objects
|
|
2870
|
+
* @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
|
|
2871
|
+
*/
|
|
2872
|
+
function toErrorSchema(errors) {
|
|
2873
|
+
var builder = new ErrorSchemaBuilder();
|
|
2874
|
+
if (errors.length) {
|
|
2875
|
+
errors.forEach(function (error) {
|
|
2876
|
+
var property = error.property,
|
|
2877
|
+
message = error.message;
|
|
2878
|
+
// When the property is the root element, just use an empty array for the path
|
|
2879
|
+
var path = property === '.' ? [] : toPath(property);
|
|
2880
|
+
// If the property is at the root (.level1) then toPath creates
|
|
2881
|
+
// an empty array element at the first index. Remove it.
|
|
2882
|
+
if (path.length > 0 && path[0] === '') {
|
|
2883
|
+
path.splice(0, 1);
|
|
2884
|
+
}
|
|
2885
|
+
if (message) {
|
|
2886
|
+
builder.addErrors(message, path);
|
|
2887
|
+
}
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
return builder.ErrorSchema;
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
|
|
2894
|
+
*
|
|
2895
|
+
* @param errorHandler - The `FormValidation` error handling structure
|
|
2896
|
+
* @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
|
|
2897
|
+
*/
|
|
2898
|
+
function unwrapErrorHandler(errorHandler) {
|
|
2899
|
+
return Object.keys(errorHandler).reduce(function (acc, key) {
|
|
2900
|
+
if (key === 'addError') {
|
|
2901
|
+
return acc;
|
|
2902
|
+
} else {
|
|
2903
|
+
var _extends3;
|
|
2904
|
+
var childSchema = errorHandler[key];
|
|
2905
|
+
if (isPlainObject(childSchema)) {
|
|
2906
|
+
var _extends2;
|
|
2907
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[key] = unwrapErrorHandler(childSchema), _extends2));
|
|
2908
|
+
}
|
|
2909
|
+
return _extends({}, acc, (_extends3 = {}, _extends3[key] = childSchema, _extends3));
|
|
2910
|
+
}
|
|
2911
|
+
}, {});
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2765
2914
|
/** Converts a UTC date string into a local Date format
|
|
2766
2915
|
*
|
|
2767
2916
|
* @param jsonDate - A UTC date string
|
|
@@ -2787,6 +2936,77 @@ function utcToLocal(jsonDate) {
|
|
|
2787
2936
|
return yyyy + "-" + MM + "-" + dd + "T" + hh + ":" + mm + ":" + ss + "." + SSS;
|
|
2788
2937
|
}
|
|
2789
2938
|
|
|
2939
|
+
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
|
|
2940
|
+
* two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
2941
|
+
* `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
|
|
2942
|
+
* `validationData` is returned.
|
|
2943
|
+
*
|
|
2944
|
+
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
2945
|
+
* @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
|
|
2946
|
+
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
2947
|
+
*/
|
|
2948
|
+
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2949
|
+
if (!additionalErrorSchema) {
|
|
2950
|
+
return validationData;
|
|
2951
|
+
}
|
|
2952
|
+
var oldErrors = validationData.errors,
|
|
2953
|
+
oldErrorSchema = validationData.errorSchema;
|
|
2954
|
+
var errors = toErrorList(additionalErrorSchema);
|
|
2955
|
+
var errorSchema = additionalErrorSchema;
|
|
2956
|
+
if (!isEmpty(oldErrorSchema)) {
|
|
2957
|
+
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2958
|
+
errors = [].concat(oldErrors).concat(errors);
|
|
2959
|
+
}
|
|
2960
|
+
return {
|
|
2961
|
+
errorSchema: errorSchema,
|
|
2962
|
+
errors: errors
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
/** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
2967
|
+
* `withIdRefPrefix` for any other elements.
|
|
2968
|
+
*
|
|
2969
|
+
* @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
2970
|
+
*/
|
|
2971
|
+
function withIdRefPrefixObject(node) {
|
|
2972
|
+
for (var key in node) {
|
|
2973
|
+
var realObj = node;
|
|
2974
|
+
var value = realObj[key];
|
|
2975
|
+
if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
|
|
2976
|
+
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
2977
|
+
} else {
|
|
2978
|
+
realObj[key] = withIdRefPrefix(value);
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
return node;
|
|
2982
|
+
}
|
|
2983
|
+
/** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
2984
|
+
* `withIdRefPrefix` for any other elements.
|
|
2985
|
+
*
|
|
2986
|
+
* @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
2987
|
+
*/
|
|
2988
|
+
function withIdRefPrefixArray(node) {
|
|
2989
|
+
for (var i = 0; i < node.length; i++) {
|
|
2990
|
+
node[i] = withIdRefPrefix(node[i]);
|
|
2991
|
+
}
|
|
2992
|
+
return node;
|
|
2993
|
+
}
|
|
2994
|
+
/** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
|
|
2995
|
+
* This is used in isValid to make references to the rootSchema
|
|
2996
|
+
*
|
|
2997
|
+
* @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
2998
|
+
* @returns - A copy of the `schemaNode` with updated `$ref`s
|
|
2999
|
+
*/
|
|
3000
|
+
function withIdRefPrefix(schemaNode) {
|
|
3001
|
+
if (schemaNode.constructor === Object) {
|
|
3002
|
+
return withIdRefPrefixObject(_extends({}, schemaNode));
|
|
3003
|
+
}
|
|
3004
|
+
if (Array.isArray(schemaNode)) {
|
|
3005
|
+
return withIdRefPrefixArray([].concat(schemaNode));
|
|
3006
|
+
}
|
|
3007
|
+
return schemaNode;
|
|
3008
|
+
}
|
|
3009
|
+
|
|
2790
3010
|
/** An enumeration of all the translatable strings used by `@rjsf/core` and its themes. The value of each of the
|
|
2791
3011
|
* enumeration keys is expected to be the actual english string. Some strings contain replaceable parameter values
|
|
2792
3012
|
* as indicated by `%1`, `%2`, etc. The number after the `%` indicates the order of the parameter. The ordering of
|
|
@@ -2863,5 +3083,5 @@ var TranslatableString;
|
|
|
2863
3083
|
TranslatableString["FilesInfo"] = "<strong>%1</strong> (%2, %3 bytes)";
|
|
2864
3084
|
})(TranslatableString || (TranslatableString = {}));
|
|
2865
3085
|
|
|
2866
|
-
export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, CONST_KEY, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, ENUM_KEY, ERRORS_KEY, ErrorSchemaBuilder, ID_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, SUBMIT_BTN_OPTIONS_KEY, TranslatableString, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toIdSchema, toPathSchema, utcToLocal };
|
|
3086
|
+
export { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, CONST_KEY, DEFAULT_KEY, DEFINITIONS_KEY, DEPENDENCIES_KEY, ENUM_KEY, ERRORS_KEY, ErrorSchemaBuilder, ID_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, REQUIRED_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, ROOT_SCHEMA_PREFIX, SUBMIT_BTN_OPTIONS_KEY, TranslatableString, UI_FIELD_KEY, UI_GLOBAL_OPTIONS_KEY, UI_OPTIONS_KEY, UI_WIDGET_KEY, allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, findSchemaDefinition, getClosestMatchingOption, getDefaultFormState, getDisplayLabel, getFirstMatchingOption, getInputProps, getMatchingOption, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, helpId, isConstant, isCustomWidget, isFilesArray, isFixedItems, isMultiSelect, isObject, isSelect, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, mergeValidationData, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, retrieveSchema, sanitizeDataForNewSchema, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, toIdSchema, toPathSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix };
|
|
2867
3087
|
//# sourceMappingURL=utils.esm.js.map
|