@rjsf/utils 5.16.0 → 5.17.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/utils.esm.js CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  // src/isObject.ts
2
10
  function isObject(thing) {
3
11
  if (typeof File !== "undefined" && thing instanceof File) {
@@ -1718,29 +1726,33 @@ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateB
1718
1726
  }
1719
1727
 
1720
1728
  // src/dataURItoBlob.ts
1721
- function dataURItoBlob(dataURI) {
1722
- const splitted = dataURI.split(",");
1723
- const params = splitted[0].split(";");
1724
- const type = params[0].replace("data:", "");
1725
- const properties = params.filter((param) => {
1726
- return param.split("=")[0] === "name";
1727
- });
1728
- let name;
1729
- if (properties.length !== 1) {
1730
- name = "unknown";
1731
- } else {
1732
- name = decodeURI(properties[0].split("=")[1]);
1733
- }
1729
+ function dataURItoBlob(dataURILike) {
1730
+ if (dataURILike.indexOf("data:") === -1) {
1731
+ throw new Error("File is invalid: URI must be a dataURI");
1732
+ }
1733
+ const dataURI = dataURILike.slice(5);
1734
+ const splitted = dataURI.split(";base64,");
1735
+ if (splitted.length !== 2) {
1736
+ throw new Error("File is invalid: dataURI must be base64");
1737
+ }
1738
+ const [media, base642] = splitted;
1739
+ const [mime, ...mediaparams] = media.split(";");
1740
+ const type = mime || "";
1741
+ const name = decodeURI(
1742
+ // parse the parameters into key-value pairs, find a key, and extract a value
1743
+ // if no key is found, then the name is unknown
1744
+ mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
1745
+ );
1734
1746
  try {
1735
- const binary = atob(splitted[1]);
1736
- const array = [];
1747
+ const binary = atob(base642);
1748
+ const array = new Array(binary.length);
1737
1749
  for (let i = 0; i < binary.length; i++) {
1738
- array.push(binary.charCodeAt(i));
1750
+ array[i] = binary.charCodeAt(i);
1739
1751
  }
1740
1752
  const blob = new window.Blob([new Uint8Array(array)], { type });
1741
1753
  return { blob, name };
1742
1754
  } catch (error) {
1743
- return { blob: { size: 0, type: error.message }, name: dataURI };
1755
+ throw new Error("File is invalid: " + error.message);
1744
1756
  }
1745
1757
  }
1746
1758
 
@@ -1771,7 +1783,7 @@ import isEqual4 from "lodash/isEqual";
1771
1783
  // src/enumOptionsValueForIndex.ts
1772
1784
  function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
1773
1785
  if (Array.isArray(valueIndex)) {
1774
- return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
1786
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val !== emptyValue);
1775
1787
  }
1776
1788
  const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
1777
1789
  const option = allEnumOptions[index];
@@ -2442,6 +2454,33 @@ function withIdRefPrefix(schemaNode) {
2442
2454
  return schemaNode;
2443
2455
  }
2444
2456
 
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
+
2445
2484
  // src/enums.ts
2446
2485
  var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2447
2486
  TranslatableString2["ArrayItemTitle"] = "Item";
@@ -2625,6 +2664,7 @@ export {
2625
2664
  allowAdditionalItems,
2626
2665
  ariaDescribedByIds,
2627
2666
  asNumber,
2667
+ base64_default as base64,
2628
2668
  canExpand,
2629
2669
  createErrorHandler,
2630
2670
  createSchemaUtils,