@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/index.js CHANGED
@@ -61,6 +61,7 @@ __export(src_exports, {
61
61
  allowAdditionalItems: () => allowAdditionalItems,
62
62
  ariaDescribedByIds: () => ariaDescribedByIds,
63
63
  asNumber: () => asNumber,
64
+ base64: () => base64_default,
64
65
  canExpand: () => canExpand,
65
66
  createErrorHandler: () => createErrorHandler,
66
67
  createSchemaUtils: () => createSchemaUtils,
@@ -1853,29 +1854,33 @@ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateB
1853
1854
  }
1854
1855
 
1855
1856
  // src/dataURItoBlob.ts
1856
- function dataURItoBlob(dataURI) {
1857
- const splitted = dataURI.split(",");
1858
- const params = splitted[0].split(";");
1859
- const type = params[0].replace("data:", "");
1860
- const properties = params.filter((param) => {
1861
- return param.split("=")[0] === "name";
1862
- });
1863
- let name;
1864
- if (properties.length !== 1) {
1865
- name = "unknown";
1866
- } else {
1867
- name = decodeURI(properties[0].split("=")[1]);
1868
- }
1857
+ function dataURItoBlob(dataURILike) {
1858
+ if (dataURILike.indexOf("data:") === -1) {
1859
+ throw new Error("File is invalid: URI must be a dataURI");
1860
+ }
1861
+ const dataURI = dataURILike.slice(5);
1862
+ const splitted = dataURI.split(";base64,");
1863
+ if (splitted.length !== 2) {
1864
+ throw new Error("File is invalid: dataURI must be base64");
1865
+ }
1866
+ const [media, base642] = splitted;
1867
+ const [mime, ...mediaparams] = media.split(";");
1868
+ const type = mime || "";
1869
+ const name = decodeURI(
1870
+ // parse the parameters into key-value pairs, find a key, and extract a value
1871
+ // if no key is found, then the name is unknown
1872
+ mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
1873
+ );
1869
1874
  try {
1870
- const binary = atob(splitted[1]);
1871
- const array = [];
1875
+ const binary = atob(base642);
1876
+ const array = new Array(binary.length);
1872
1877
  for (let i = 0; i < binary.length; i++) {
1873
- array.push(binary.charCodeAt(i));
1878
+ array[i] = binary.charCodeAt(i);
1874
1879
  }
1875
1880
  const blob = new window.Blob([new Uint8Array(array)], { type });
1876
1881
  return { blob, name };
1877
1882
  } catch (error) {
1878
- return { blob: { size: 0, type: error.message }, name: dataURI };
1883
+ throw new Error("File is invalid: " + error.message);
1879
1884
  }
1880
1885
  }
1881
1886
 
@@ -1906,7 +1911,7 @@ var import_isEqual4 = __toESM(require("lodash/isEqual"));
1906
1911
  // src/enumOptionsValueForIndex.ts
1907
1912
  function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
1908
1913
  if (Array.isArray(valueIndex)) {
1909
- return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
1914
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val !== emptyValue);
1910
1915
  }
1911
1916
  const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
1912
1917
  const option = allEnumOptions[index];
@@ -2577,6 +2582,33 @@ function withIdRefPrefix(schemaNode) {
2577
2582
  return schemaNode;
2578
2583
  }
2579
2584
 
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
+
2580
2612
  // src/enums.ts
2581
2613
  var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
2582
2614
  TranslatableString2["ArrayItemTitle"] = "Item";