@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/utils.esm.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
1
|
// src/isObject.ts
|
|
10
2
|
function isObject(thing) {
|
|
11
3
|
if (typeof File !== "undefined" && thing instanceof File) {
|
|
@@ -963,14 +955,18 @@ function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValu
|
|
|
963
955
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
964
956
|
if (isObject(computedDefault)) {
|
|
965
957
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
966
|
-
if (
|
|
958
|
+
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
959
|
+
if (!isEmpty(computedDefault)) {
|
|
960
|
+
obj[key] = computedDefault;
|
|
961
|
+
}
|
|
962
|
+
} else if ((!isEmpty(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
967
963
|
obj[key] = computedDefault;
|
|
968
964
|
}
|
|
969
965
|
} else if (
|
|
970
966
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
971
967
|
// Condition 1: computedDefault is not undefined
|
|
972
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or if the key is a required field
|
|
973
|
-
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || requiredFields.includes(key))
|
|
968
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults) or if the key is a required field
|
|
969
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || requiredFields.includes(key))
|
|
974
970
|
) {
|
|
975
971
|
obj[key] = computedDefault;
|
|
976
972
|
}
|
|
@@ -1123,6 +1119,9 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1123
1119
|
case "array": {
|
|
1124
1120
|
const neverPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "never";
|
|
1125
1121
|
const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
|
|
1122
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1123
|
+
const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
1124
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1126
1125
|
if (Array.isArray(defaults)) {
|
|
1127
1126
|
defaults = defaults.map((item, idx) => {
|
|
1128
1127
|
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
@@ -1153,14 +1152,14 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1153
1152
|
}
|
|
1154
1153
|
}
|
|
1155
1154
|
if (neverPopulate) {
|
|
1156
|
-
return defaults ??
|
|
1155
|
+
return defaults ?? emptyDefault;
|
|
1157
1156
|
}
|
|
1158
1157
|
if (ignoreMinItemsFlagSet && !required) {
|
|
1159
1158
|
return defaults ? defaults : void 0;
|
|
1160
1159
|
}
|
|
1161
1160
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1162
|
-
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1163
|
-
return defaults ? defaults :
|
|
1161
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1162
|
+
return defaults ? defaults : emptyDefault;
|
|
1164
1163
|
}
|
|
1165
1164
|
const defaultEntries = defaults || [];
|
|
1166
1165
|
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
@@ -1735,7 +1734,7 @@ function dataURItoBlob(dataURILike) {
|
|
|
1735
1734
|
if (splitted.length !== 2) {
|
|
1736
1735
|
throw new Error("File is invalid: dataURI must be base64");
|
|
1737
1736
|
}
|
|
1738
|
-
const [media,
|
|
1737
|
+
const [media, base64] = splitted;
|
|
1739
1738
|
const [mime, ...mediaparams] = media.split(";");
|
|
1740
1739
|
const type = mime || "";
|
|
1741
1740
|
const name = decodeURI(
|
|
@@ -1744,7 +1743,7 @@ function dataURItoBlob(dataURILike) {
|
|
|
1744
1743
|
mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
|
|
1745
1744
|
);
|
|
1746
1745
|
try {
|
|
1747
|
-
const binary = atob(
|
|
1746
|
+
const binary = atob(base64);
|
|
1748
1747
|
const array = new Array(binary.length);
|
|
1749
1748
|
for (let i = 0; i < binary.length; i++) {
|
|
1750
1749
|
array[i] = binary.charCodeAt(i);
|
|
@@ -2454,33 +2453,6 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2454
2453
|
return schemaNode;
|
|
2455
2454
|
}
|
|
2456
2455
|
|
|
2457
|
-
// src/base64.ts
|
|
2458
|
-
var base64 = function() {
|
|
2459
|
-
return {
|
|
2460
|
-
encode(text) {
|
|
2461
|
-
let encoder;
|
|
2462
|
-
if (typeof TextEncoder !== "undefined") {
|
|
2463
|
-
encoder = new TextEncoder();
|
|
2464
|
-
} else {
|
|
2465
|
-
const { TextEncoder: TextEncoder2 } = __require("util");
|
|
2466
|
-
encoder = new TextEncoder2();
|
|
2467
|
-
}
|
|
2468
|
-
return btoa(String.fromCharCode(...encoder.encode(text)));
|
|
2469
|
-
},
|
|
2470
|
-
decode(text) {
|
|
2471
|
-
let decoder;
|
|
2472
|
-
if (typeof TextDecoder !== "undefined") {
|
|
2473
|
-
decoder = new TextDecoder();
|
|
2474
|
-
} else {
|
|
2475
|
-
const { TextDecoder: TextDecoder2 } = __require("util");
|
|
2476
|
-
decoder = new TextDecoder2();
|
|
2477
|
-
}
|
|
2478
|
-
return decoder.decode(Uint8Array.from(atob(text), (c) => c.charCodeAt(0)));
|
|
2479
|
-
}
|
|
2480
|
-
};
|
|
2481
|
-
}();
|
|
2482
|
-
var base64_default = base64;
|
|
2483
|
-
|
|
2484
2456
|
// src/enums.ts
|
|
2485
2457
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2486
2458
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
@@ -2511,7 +2483,7 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2511
2483
|
TranslatableString2["UnsupportedFieldWithId"] = "Unsupported field schema for field <code>%1</code>.";
|
|
2512
2484
|
TranslatableString2["UnsupportedFieldWithReason"] = "Unsupported field schema: <em>%1</em>.";
|
|
2513
2485
|
TranslatableString2["UnsupportedFieldWithIdAndReason"] = "Unsupported field schema for field <code>%1</code>: <em>%2</em>.";
|
|
2514
|
-
TranslatableString2["FilesInfo"] = "
|
|
2486
|
+
TranslatableString2["FilesInfo"] = "**%1** (%2, %3 bytes)";
|
|
2515
2487
|
return TranslatableString2;
|
|
2516
2488
|
})(TranslatableString || {});
|
|
2517
2489
|
|
|
@@ -2664,7 +2636,6 @@ export {
|
|
|
2664
2636
|
allowAdditionalItems,
|
|
2665
2637
|
ariaDescribedByIds,
|
|
2666
2638
|
asNumber,
|
|
2667
|
-
base64_default as base64,
|
|
2668
2639
|
canExpand,
|
|
2669
2640
|
createErrorHandler,
|
|
2670
2641
|
createSchemaUtils,
|