@rjsf/utils 5.17.0 → 5.18.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.js +16 -37
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +16 -45
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +16 -45
- package/lib/enums.d.ts +1 -1
- package/lib/enums.js +1 -1
- package/lib/enums.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +19 -7
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +14 -1
- package/package.json +2 -2
- package/src/enums.ts +1 -1
- package/src/index.ts +0 -2
- package/src/schema/getDefaultFormState.ts +21 -6
- package/src/types.ts +18 -1
- package/lib/base64.d.ts +0 -11
- package/lib/base64.js +0 -36
- package/lib/base64.js.map +0 -1
- package/src/base64.ts +0 -34
package/dist/index.js
CHANGED
|
@@ -61,7 +61,6 @@ __export(src_exports, {
|
|
|
61
61
|
allowAdditionalItems: () => allowAdditionalItems,
|
|
62
62
|
ariaDescribedByIds: () => ariaDescribedByIds,
|
|
63
63
|
asNumber: () => asNumber,
|
|
64
|
-
base64: () => base64_default,
|
|
65
64
|
canExpand: () => canExpand,
|
|
66
65
|
createErrorHandler: () => createErrorHandler,
|
|
67
66
|
createSchemaUtils: () => createSchemaUtils,
|
|
@@ -1091,14 +1090,18 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
1091
1090
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1092
1091
|
if (isObject(computedDefault)) {
|
|
1093
1092
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1094
|
-
if (
|
|
1093
|
+
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1094
|
+
if (!(0, import_isEmpty.default)(computedDefault)) {
|
|
1095
|
+
obj[key] = computedDefault;
|
|
1096
|
+
}
|
|
1097
|
+
} else if ((!(0, import_isEmpty.default)(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1095
1098
|
obj[key] = computedDefault;
|
|
1096
1099
|
}
|
|
1097
1100
|
} else if (
|
|
1098
1101
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
1099
1102
|
// Condition 1: computedDefault is not undefined
|
|
1100
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
|
|
1101
|
-
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || requiredFields.includes(key))
|
|
1103
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults) or if the key is a required field
|
|
1104
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || requiredFields.includes(key))
|
|
1102
1105
|
) {
|
|
1103
1106
|
obj[key] = computedDefault;
|
|
1104
1107
|
}
|
|
@@ -1251,6 +1254,9 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1251
1254
|
case "array": {
|
|
1252
1255
|
const neverPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "never";
|
|
1253
1256
|
const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
|
|
1257
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1258
|
+
const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
1259
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1254
1260
|
if (Array.isArray(defaults)) {
|
|
1255
1261
|
defaults = defaults.map((item, idx) => {
|
|
1256
1262
|
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
@@ -1281,14 +1287,14 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1281
1287
|
}
|
|
1282
1288
|
}
|
|
1283
1289
|
if (neverPopulate) {
|
|
1284
|
-
return defaults ??
|
|
1290
|
+
return defaults ?? emptyDefault;
|
|
1285
1291
|
}
|
|
1286
1292
|
if (ignoreMinItemsFlagSet && !required) {
|
|
1287
1293
|
return defaults ? defaults : void 0;
|
|
1288
1294
|
}
|
|
1289
1295
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1290
|
-
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1291
|
-
return defaults ? defaults :
|
|
1296
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1297
|
+
return defaults ? defaults : emptyDefault;
|
|
1292
1298
|
}
|
|
1293
1299
|
const defaultEntries = defaults || [];
|
|
1294
1300
|
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
@@ -1863,7 +1869,7 @@ function dataURItoBlob(dataURILike) {
|
|
|
1863
1869
|
if (splitted.length !== 2) {
|
|
1864
1870
|
throw new Error("File is invalid: dataURI must be base64");
|
|
1865
1871
|
}
|
|
1866
|
-
const [media,
|
|
1872
|
+
const [media, base64] = splitted;
|
|
1867
1873
|
const [mime, ...mediaparams] = media.split(";");
|
|
1868
1874
|
const type = mime || "";
|
|
1869
1875
|
const name = decodeURI(
|
|
@@ -1872,7 +1878,7 @@ function dataURItoBlob(dataURILike) {
|
|
|
1872
1878
|
mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
|
|
1873
1879
|
);
|
|
1874
1880
|
try {
|
|
1875
|
-
const binary = atob(
|
|
1881
|
+
const binary = atob(base64);
|
|
1876
1882
|
const array = new Array(binary.length);
|
|
1877
1883
|
for (let i = 0; i < binary.length; i++) {
|
|
1878
1884
|
array[i] = binary.charCodeAt(i);
|
|
@@ -2582,33 +2588,6 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2582
2588
|
return schemaNode;
|
|
2583
2589
|
}
|
|
2584
2590
|
|
|
2585
|
-
// src/base64.ts
|
|
2586
|
-
var base64 = function() {
|
|
2587
|
-
return {
|
|
2588
|
-
encode(text) {
|
|
2589
|
-
let encoder;
|
|
2590
|
-
if (typeof TextEncoder !== "undefined") {
|
|
2591
|
-
encoder = new TextEncoder();
|
|
2592
|
-
} else {
|
|
2593
|
-
const { TextEncoder: TextEncoder2 } = require("util");
|
|
2594
|
-
encoder = new TextEncoder2();
|
|
2595
|
-
}
|
|
2596
|
-
return btoa(String.fromCharCode(...encoder.encode(text)));
|
|
2597
|
-
},
|
|
2598
|
-
decode(text) {
|
|
2599
|
-
let decoder;
|
|
2600
|
-
if (typeof TextDecoder !== "undefined") {
|
|
2601
|
-
decoder = new TextDecoder();
|
|
2602
|
-
} else {
|
|
2603
|
-
const { TextDecoder: TextDecoder2 } = require("util");
|
|
2604
|
-
decoder = new TextDecoder2();
|
|
2605
|
-
}
|
|
2606
|
-
return decoder.decode(Uint8Array.from(atob(text), (c) => c.charCodeAt(0)));
|
|
2607
|
-
}
|
|
2608
|
-
};
|
|
2609
|
-
}();
|
|
2610
|
-
var base64_default = base64;
|
|
2611
|
-
|
|
2612
2591
|
// src/enums.ts
|
|
2613
2592
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2614
2593
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
@@ -2639,7 +2618,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2639
2618
|
TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
|
|
2640
2619
|
TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
|
|
2641
2620
|
TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
|
|
2642
|
-
TranslatableString2["FilesInfo"] = "
|
|
2621
|
+
TranslatableString2["FilesInfo"] = "**%1** (%2, %3 bytes)";
|
|
2643
2622
|
return TranslatableString2;
|
|
2644
2623
|
})(TranslatableString || {});
|
|
2645
2624
|
|