@rjsf/utils 5.5.0 → 5.5.2
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 -1
- package/dist/utils.cjs.development.js +111 -47
- 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 +111 -47
- package/dist/utils.esm.js.map +1 -1
- package/dist/utils.umd.development.js +111 -47
- 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 +4 -4
package/dist/utils.esm.js
CHANGED
|
@@ -609,7 +609,7 @@ function retrieveSchema(validator, schema, rootSchema, rawFormData) {
|
|
|
609
609
|
deep: false
|
|
610
610
|
});
|
|
611
611
|
} catch (e) {
|
|
612
|
-
console.warn('could not merge subschemas in allOf:\n'
|
|
612
|
+
console.warn('could not merge subschemas in allOf:\n', e);
|
|
613
613
|
var _resolvedSchema = resolvedSchema,
|
|
614
614
|
resolvedSchemaWithoutAllOf = _objectWithoutPropertiesLoose(_resolvedSchema, _excluded3);
|
|
615
615
|
return resolvedSchemaWithoutAllOf;
|
|
@@ -739,9 +739,7 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
739
739
|
type: 'object',
|
|
740
740
|
properties: (_properties = {}, _properties[dependencyKey] = conditionPropertySchema, _properties)
|
|
741
741
|
};
|
|
742
|
-
|
|
743
|
-
errors = _validator$validateFo.errors;
|
|
744
|
-
return errors.length === 0;
|
|
742
|
+
return validator.isValid(conditionSchema, formData, rootSchema);
|
|
745
743
|
}
|
|
746
744
|
return false;
|
|
747
745
|
});
|
|
@@ -1119,15 +1117,19 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1119
1117
|
* @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
|
|
1120
1118
|
* If "excludeObjectChildren", cause undefined values for this object and pass `includeUndefinedValues` as
|
|
1121
1119
|
* false when computing defaults for any nested object properties.
|
|
1120
|
+
* @param [_recurseList=[]] - The list of ref names currently being recursed, used to prevent infinite recursion
|
|
1122
1121
|
* @returns - The resulting `formData` with all the defaults provided
|
|
1123
1122
|
*/
|
|
1124
|
-
function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues) {
|
|
1123
|
+
function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFormData, includeUndefinedValues, _recurseList) {
|
|
1125
1124
|
if (rootSchema === void 0) {
|
|
1126
1125
|
rootSchema = {};
|
|
1127
1126
|
}
|
|
1128
1127
|
if (includeUndefinedValues === void 0) {
|
|
1129
1128
|
includeUndefinedValues = false;
|
|
1130
1129
|
}
|
|
1130
|
+
if (_recurseList === void 0) {
|
|
1131
|
+
_recurseList = [];
|
|
1132
|
+
}
|
|
1131
1133
|
var formData = isObject(rawFormData) ? rawFormData : {};
|
|
1132
1134
|
var schema = isObject(rawSchema) ? rawSchema : {};
|
|
1133
1135
|
// Compute the defaults recursively: give highest priority to deepest nodes.
|
|
@@ -1139,15 +1141,18 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1139
1141
|
} else if (DEFAULT_KEY in schema) {
|
|
1140
1142
|
defaults = schema["default"];
|
|
1141
1143
|
} else if (REF_KEY in schema) {
|
|
1144
|
+
var refName = schema[REF_KEY];
|
|
1142
1145
|
// Use referenced schema defaults for this node.
|
|
1143
|
-
|
|
1144
|
-
|
|
1146
|
+
if (!_recurseList.includes(refName)) {
|
|
1147
|
+
var refSchema = findSchemaDefinition(refName, rootSchema);
|
|
1148
|
+
return computeDefaults(validator, refSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList.concat(refName));
|
|
1149
|
+
}
|
|
1145
1150
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1146
1151
|
var resolvedSchema = resolveDependencies(validator, schema, rootSchema, formData);
|
|
1147
|
-
return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues);
|
|
1152
|
+
return computeDefaults(validator, resolvedSchema, defaults, rootSchema, formData, includeUndefinedValues, _recurseList);
|
|
1148
1153
|
} else if (isFixedItems(schema)) {
|
|
1149
1154
|
defaults = schema.items.map(function (itemSchema, idx) {
|
|
1150
|
-
return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues);
|
|
1155
|
+
return computeDefaults(validator, itemSchema, Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined, rootSchema, formData, includeUndefinedValues, _recurseList);
|
|
1151
1156
|
});
|
|
1152
1157
|
} else if (ONE_OF_KEY in schema) {
|
|
1153
1158
|
if (schema.oneOf.length === 0) {
|
|
@@ -1171,16 +1176,30 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1171
1176
|
var objectDefaults = Object.keys(schema.properties || {}).reduce(function (acc, key) {
|
|
1172
1177
|
// Compute the defaults for this node, with the parent defaults we might
|
|
1173
1178
|
// have from a previous run: defaults[key].
|
|
1174
|
-
var computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues === true);
|
|
1179
|
+
var computedDefault = computeDefaults(validator, get(schema, [PROPERTIES_KEY, key]), get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues === true, _recurseList);
|
|
1175
1180
|
maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, schema.required);
|
|
1176
1181
|
return acc;
|
|
1177
1182
|
}, {});
|
|
1178
|
-
if (schema.additionalProperties
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1183
|
+
if (schema.additionalProperties) {
|
|
1184
|
+
// as per spec additionalProperties may be either schema or boolean
|
|
1185
|
+
var additionalPropertiesSchema = isObject(schema.additionalProperties) ? schema.additionalProperties : {};
|
|
1186
|
+
var keys = new Set();
|
|
1187
|
+
if (isObject(defaults)) {
|
|
1188
|
+
Object.keys(defaults).filter(function (key) {
|
|
1189
|
+
return !schema.properties || !schema.properties[key];
|
|
1190
|
+
}).forEach(function (key) {
|
|
1191
|
+
return keys.add(key);
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
if (isObject(formData)) {
|
|
1195
|
+
Object.keys(formData).filter(function (key) {
|
|
1196
|
+
return !schema.properties || !schema.properties[key];
|
|
1197
|
+
}).forEach(function (key) {
|
|
1198
|
+
return keys.add(key);
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
keys.forEach(function (key) {
|
|
1202
|
+
var computedDefault = computeDefaults(validator, additionalPropertiesSchema, get(defaults, [key]), rootSchema, get(formData, [key]), includeUndefinedValues === true, _recurseList);
|
|
1184
1203
|
maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues);
|
|
1185
1204
|
});
|
|
1186
1205
|
}
|
|
@@ -1191,14 +1210,14 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1191
1210
|
if (Array.isArray(defaults)) {
|
|
1192
1211
|
defaults = defaults.map(function (item, idx) {
|
|
1193
1212
|
var schemaItem = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Fallback, idx);
|
|
1194
|
-
return computeDefaults(validator, schemaItem, item, rootSchema);
|
|
1213
|
+
return computeDefaults(validator, schemaItem, item, rootSchema, undefined, undefined, _recurseList);
|
|
1195
1214
|
});
|
|
1196
1215
|
}
|
|
1197
1216
|
// Deeply inject defaults into already existing form data
|
|
1198
1217
|
if (Array.isArray(rawFormData)) {
|
|
1199
1218
|
var schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1200
1219
|
defaults = rawFormData.map(function (item, idx) {
|
|
1201
|
-
return computeDefaults(validator, schemaItem, get(defaults, [idx]), rootSchema, item);
|
|
1220
|
+
return computeDefaults(validator, schemaItem, get(defaults, [idx]), rootSchema, item, undefined, _recurseList);
|
|
1202
1221
|
});
|
|
1203
1222
|
}
|
|
1204
1223
|
if (schema.minItems) {
|
|
@@ -1209,7 +1228,7 @@ function computeDefaults(validator, rawSchema, parentDefaults, rootSchema, rawFo
|
|
|
1209
1228
|
// populate the array with the defaults
|
|
1210
1229
|
var fillerSchema = getInnerSchemaForArrayItem(schema, AdditionalItemsHandling.Invert);
|
|
1211
1230
|
var fillerDefault = fillerSchema["default"];
|
|
1212
|
-
var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema));
|
|
1231
|
+
var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(validator, fillerSchema, fillerDefault, rootSchema, undefined, undefined, _recurseList));
|
|
1213
1232
|
// then fill up the rest with either the item default or empty, up to minItems
|
|
1214
1233
|
return defaultEntries.concat(fillerEntries);
|
|
1215
1234
|
}
|
|
@@ -1516,30 +1535,34 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1516
1535
|
return newFormData;
|
|
1517
1536
|
}
|
|
1518
1537
|
|
|
1519
|
-
/**
|
|
1538
|
+
/** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
|
|
1539
|
+
* infinite recursion
|
|
1520
1540
|
*
|
|
1521
1541
|
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1522
1542
|
* @param schema - The schema for which the `IdSchema` is desired
|
|
1543
|
+
* @param idPrefix - The prefix to use for the id
|
|
1544
|
+
* @param idSeparator - The separator to use for the path segments in the id
|
|
1523
1545
|
* @param [id] - The base id for the schema
|
|
1524
1546
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1525
1547
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1526
|
-
* @param [
|
|
1527
|
-
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1548
|
+
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
1528
1549
|
* @returns - The `IdSchema` object for the `schema`
|
|
1529
1550
|
*/
|
|
1530
|
-
function
|
|
1531
|
-
if (
|
|
1532
|
-
|
|
1533
|
-
}
|
|
1534
|
-
if (idSeparator === void 0) {
|
|
1535
|
-
idSeparator = '_';
|
|
1551
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList) {
|
|
1552
|
+
if (_recurseList === void 0) {
|
|
1553
|
+
_recurseList = [];
|
|
1536
1554
|
}
|
|
1537
1555
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1538
1556
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1539
|
-
|
|
1557
|
+
var sameSchemaIndex = _recurseList.findIndex(function (item) {
|
|
1558
|
+
return isEqual(item, _schema);
|
|
1559
|
+
});
|
|
1560
|
+
if (sameSchemaIndex === -1) {
|
|
1561
|
+
return toIdSchemaInternal(validator, _schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList.concat(_schema));
|
|
1562
|
+
}
|
|
1540
1563
|
}
|
|
1541
1564
|
if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1542
|
-
return
|
|
1565
|
+
return toIdSchemaInternal(validator, get(schema, ITEMS_KEY), idPrefix, idSeparator, id, rootSchema, formData, _recurseList);
|
|
1543
1566
|
}
|
|
1544
1567
|
var $id = id || idPrefix;
|
|
1545
1568
|
var idSchema = {
|
|
@@ -1549,62 +1572,104 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSep
|
|
|
1549
1572
|
for (var name in schema.properties) {
|
|
1550
1573
|
var field = get(schema, [PROPERTIES_KEY, name]);
|
|
1551
1574
|
var fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1552
|
-
idSchema[name] =
|
|
1575
|
+
idSchema[name] = toIdSchemaInternal(validator, isObject(field) ? field : {}, idPrefix, idSeparator, fieldId, rootSchema,
|
|
1553
1576
|
// It's possible that formData is not an object -- this can happen if an
|
|
1554
1577
|
// array item has just been added, but not populated with data yet
|
|
1555
|
-
get(formData, [name]),
|
|
1578
|
+
get(formData, [name]), _recurseList);
|
|
1556
1579
|
}
|
|
1557
1580
|
}
|
|
1558
1581
|
return idSchema;
|
|
1559
1582
|
}
|
|
1583
|
+
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1584
|
+
*
|
|
1585
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1586
|
+
* @param schema - The schema for which the `IdSchema` is desired
|
|
1587
|
+
* @param [id] - The base id for the schema
|
|
1588
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1589
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1590
|
+
* @param [idPrefix='root'] - The prefix to use for the id
|
|
1591
|
+
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1592
|
+
* @returns - The `IdSchema` object for the `schema`
|
|
1593
|
+
*/
|
|
1594
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix, idSeparator) {
|
|
1595
|
+
if (idPrefix === void 0) {
|
|
1596
|
+
idPrefix = 'root';
|
|
1597
|
+
}
|
|
1598
|
+
if (idSeparator === void 0) {
|
|
1599
|
+
idSeparator = '_';
|
|
1600
|
+
}
|
|
1601
|
+
return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData);
|
|
1602
|
+
}
|
|
1560
1603
|
|
|
1561
|
-
/**
|
|
1604
|
+
/** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
|
|
1605
|
+
* infinite recursion
|
|
1562
1606
|
*
|
|
1563
1607
|
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1564
1608
|
* @param schema - The schema for which the `PathSchema` is desired
|
|
1565
1609
|
* @param [name=''] - The base name for the schema
|
|
1566
1610
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1567
1611
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1612
|
+
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
1568
1613
|
* @returns - The `PathSchema` object for the `schema`
|
|
1569
1614
|
*/
|
|
1570
|
-
function
|
|
1615
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList) {
|
|
1571
1616
|
var _pathSchema;
|
|
1572
|
-
if (
|
|
1573
|
-
|
|
1617
|
+
if (_recurseList === void 0) {
|
|
1618
|
+
_recurseList = [];
|
|
1574
1619
|
}
|
|
1575
1620
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1576
1621
|
var _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1577
|
-
|
|
1622
|
+
var sameSchemaIndex = _recurseList.findIndex(function (item) {
|
|
1623
|
+
return isEqual(item, _schema);
|
|
1624
|
+
});
|
|
1625
|
+
if (sameSchemaIndex === -1) {
|
|
1626
|
+
return toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList.concat(_schema));
|
|
1627
|
+
}
|
|
1578
1628
|
}
|
|
1579
1629
|
var pathSchema = (_pathSchema = {}, _pathSchema[NAME_KEY] = name.replace(/^\./, ''), _pathSchema);
|
|
1580
1630
|
if (ONE_OF_KEY in schema) {
|
|
1581
1631
|
var index = getClosestMatchingOption(validator, rootSchema, formData, schema.oneOf, 0);
|
|
1582
1632
|
var _schema2 = schema.oneOf[index];
|
|
1583
|
-
return
|
|
1633
|
+
return toPathSchemaInternal(validator, _schema2, name, rootSchema, formData, _recurseList);
|
|
1584
1634
|
}
|
|
1585
1635
|
if (ANY_OF_KEY in schema) {
|
|
1586
1636
|
var _index = getClosestMatchingOption(validator, rootSchema, formData, schema.anyOf, 0);
|
|
1587
1637
|
var _schema3 = schema.anyOf[_index];
|
|
1588
|
-
return
|
|
1638
|
+
return toPathSchemaInternal(validator, _schema3, name, rootSchema, formData, _recurseList);
|
|
1589
1639
|
}
|
|
1590
1640
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
1591
1641
|
set(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
|
|
1592
1642
|
}
|
|
1593
1643
|
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
1594
1644
|
formData.forEach(function (element, i) {
|
|
1595
|
-
pathSchema[i] =
|
|
1645
|
+
pathSchema[i] = toPathSchemaInternal(validator, schema.items, name + "." + i, rootSchema, element, _recurseList);
|
|
1596
1646
|
});
|
|
1597
1647
|
} else if (PROPERTIES_KEY in schema) {
|
|
1598
1648
|
for (var property in schema.properties) {
|
|
1599
1649
|
var field = get(schema, [PROPERTIES_KEY, property]);
|
|
1600
|
-
pathSchema[property] =
|
|
1650
|
+
pathSchema[property] = toPathSchemaInternal(validator, field, name + "." + property, rootSchema,
|
|
1601
1651
|
// It's possible that formData is not an object -- this can happen if an
|
|
1602
1652
|
// array item has just been added, but not populated with data yet
|
|
1603
|
-
get(formData, [property]));
|
|
1653
|
+
get(formData, [property]), _recurseList);
|
|
1604
1654
|
}
|
|
1605
1655
|
}
|
|
1606
1656
|
return pathSchema;
|
|
1607
1657
|
}
|
|
1658
|
+
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1659
|
+
*
|
|
1660
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
1661
|
+
* @param schema - The schema for which the `PathSchema` is desired
|
|
1662
|
+
* @param [name=''] - The base name for the schema
|
|
1663
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
1664
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
1665
|
+
* @returns - The `PathSchema` object for the `schema`
|
|
1666
|
+
*/
|
|
1667
|
+
function toPathSchema(validator, schema, name, rootSchema, formData) {
|
|
1668
|
+
if (name === void 0) {
|
|
1669
|
+
name = '';
|
|
1670
|
+
}
|
|
1671
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
1672
|
+
}
|
|
1608
1673
|
|
|
1609
1674
|
/** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
|
|
1610
1675
|
* that one does not have to explicitly pass the `validator` or `rootSchema` to each method. Since both the `validator`
|
|
@@ -2033,16 +2098,15 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions) {
|
|
|
2033
2098
|
* get the result and/or reset all the errors back to an initial set and start again.
|
|
2034
2099
|
*/
|
|
2035
2100
|
var ErrorSchemaBuilder = /*#__PURE__*/function () {
|
|
2036
|
-
/** The error schema being built
|
|
2037
|
-
*
|
|
2038
|
-
* @private
|
|
2039
|
-
*/
|
|
2040
|
-
|
|
2041
2101
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
2042
2102
|
*
|
|
2043
2103
|
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
2044
2104
|
*/
|
|
2045
2105
|
function ErrorSchemaBuilder(initialSchema) {
|
|
2106
|
+
/** The error schema being built
|
|
2107
|
+
*
|
|
2108
|
+
* @private
|
|
2109
|
+
*/
|
|
2046
2110
|
this.errorSchema = {};
|
|
2047
2111
|
this.resetAllErrors(initialSchema);
|
|
2048
2112
|
}
|