@rjsf/utils 5.16.1 → 5.17.1
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 +22 -18
- package/dist/index.js.map +2 -2
- package/dist/utils.esm.js +22 -18
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +22 -18
- package/lib/dataURItoBlob.d.ts +1 -7
- package/lib/dataURItoBlob.js +24 -23
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/enumOptionsValueForIndex.js +4 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +2 -0
- package/package.json +6 -6
- package/src/dataURItoBlob.ts +26 -23
- package/src/enumOptionsValueForIndex.ts +6 -1
- package/src/types.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"react-is": "^18.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.23.
|
|
46
|
+
"@babel/core": "^7.23.9",
|
|
47
47
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
48
48
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
49
|
-
"@babel/preset-env": "^7.23.
|
|
49
|
+
"@babel/preset-env": "^7.23.9",
|
|
50
50
|
"@babel/preset-react": "^7.23.3",
|
|
51
51
|
"@babel/preset-typescript": "^7.23.3",
|
|
52
|
-
"@types/jest": "^29.5.
|
|
52
|
+
"@types/jest": "^29.5.12",
|
|
53
53
|
"@types/json-schema": "^7.0.15",
|
|
54
54
|
"@types/json-schema-merge-allof": "^0.6.5",
|
|
55
55
|
"@types/lodash": "^4.14.202",
|
|
56
|
-
"@types/react": "^17.0.
|
|
56
|
+
"@types/react": "^17.0.75",
|
|
57
57
|
"@types/react-is": "^17.0.7",
|
|
58
58
|
"@types/react-test-renderer": "^17.0.9",
|
|
59
59
|
"babel-jest": "^29.7.0",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
|
|
87
87
|
},
|
|
88
88
|
"license": "Apache-2.0",
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "4d13c51c861fa0d21ec6e40881a21ba16c72d8bd"
|
|
90
90
|
}
|
package/src/dataURItoBlob.ts
CHANGED
|
@@ -4,39 +4,42 @@
|
|
|
4
4
|
* @param dataURI - The `DataUrl` potentially containing name and raw data to be converted to a Blob
|
|
5
5
|
* @returns - an object containing a Blob and its name, extracted from the URI
|
|
6
6
|
*/
|
|
7
|
-
export default function dataURItoBlob(
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const params: string[] = splitted[0].split(';');
|
|
12
|
-
// Get mime-type from params
|
|
13
|
-
const type: string = params[0].replace('data:', '');
|
|
14
|
-
// Filter the name property from params
|
|
15
|
-
const properties = params.filter((param) => {
|
|
16
|
-
return param.split('=')[0] === 'name';
|
|
17
|
-
});
|
|
18
|
-
// Look for the name and use unknown if no name property.
|
|
19
|
-
let name: string;
|
|
20
|
-
if (properties.length !== 1) {
|
|
21
|
-
name = 'unknown';
|
|
22
|
-
} else {
|
|
23
|
-
// Because we filtered out the other property,
|
|
24
|
-
// we only have the name case here, which we decode to make it human-readable
|
|
25
|
-
name = decodeURI(properties[0].split('=')[1]);
|
|
7
|
+
export default function dataURItoBlob(dataURILike: string) {
|
|
8
|
+
// check if is dataURI
|
|
9
|
+
if (dataURILike.indexOf('data:') === -1) {
|
|
10
|
+
throw new Error('File is invalid: URI must be a dataURI');
|
|
26
11
|
}
|
|
12
|
+
const dataURI = dataURILike.slice(5);
|
|
13
|
+
// split the dataURI into media and base64, with the base64 signature
|
|
14
|
+
const splitted = dataURI.split(';base64,');
|
|
15
|
+
// if the base64 signature is not present, the latter part will become empty
|
|
16
|
+
if (splitted.length !== 2) {
|
|
17
|
+
throw new Error('File is invalid: dataURI must be base64');
|
|
18
|
+
}
|
|
19
|
+
// extract the mime type, media parameters including the name, and the base64 string
|
|
20
|
+
const [media, base64] = splitted;
|
|
21
|
+
const [mime, ...mediaparams] = media.split(';');
|
|
22
|
+
const type = mime || '';
|
|
23
|
+
|
|
24
|
+
// extract the name from the parameters
|
|
25
|
+
const name = decodeURI(
|
|
26
|
+
// parse the parameters into key-value pairs, find a key, and extract a value
|
|
27
|
+
// if no key is found, then the name is unknown
|
|
28
|
+
mediaparams.map((param) => param.split('=')).find(([key]) => key === 'name')?.[1] || 'unknown'
|
|
29
|
+
);
|
|
27
30
|
|
|
28
31
|
// Built the Uint8Array Blob parameter from the base64 string.
|
|
29
32
|
try {
|
|
30
|
-
const binary = atob(
|
|
31
|
-
const array =
|
|
33
|
+
const binary = atob(base64);
|
|
34
|
+
const array = new Array(binary.length);
|
|
32
35
|
for (let i = 0; i < binary.length; i++) {
|
|
33
|
-
array
|
|
36
|
+
array[i] = binary.charCodeAt(i);
|
|
34
37
|
}
|
|
35
38
|
// Create the blob object
|
|
36
39
|
const blob = new window.Blob([new Uint8Array(array)], { type });
|
|
37
40
|
|
|
38
41
|
return { blob, name };
|
|
39
42
|
} catch (error) {
|
|
40
|
-
|
|
43
|
+
throw new Error('File is invalid: ' + (error as Error).message);
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -17,7 +17,12 @@ export default function enumOptionsValueForIndex<S extends StrictRJSFSchema = RJ
|
|
|
17
17
|
emptyValue?: EnumOptionsType<S>['value']
|
|
18
18
|
): EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][] | undefined {
|
|
19
19
|
if (Array.isArray(valueIndex)) {
|
|
20
|
-
return
|
|
20
|
+
return (
|
|
21
|
+
valueIndex
|
|
22
|
+
.map((index) => enumOptionsValueForIndex(index, allEnumOptions))
|
|
23
|
+
// Since the recursive call returns `emptyValue` when we get a bad option, only filter those out
|
|
24
|
+
.filter((val) => val !== emptyValue)
|
|
25
|
+
);
|
|
21
26
|
}
|
|
22
27
|
// So Number(null) and Number('') both return 0, so use emptyValue for those two values
|
|
23
28
|
const index = valueIndex === '' || valueIndex === null ? -1 : Number(valueIndex);
|
package/src/types.ts
CHANGED
|
@@ -601,6 +601,8 @@ export type ArrayFieldTemplateProps<
|
|
|
601
601
|
formContext?: F;
|
|
602
602
|
/** The formData for this array */
|
|
603
603
|
formData?: T;
|
|
604
|
+
/** The tree of errors for this field and its children */
|
|
605
|
+
errorSchema?: ErrorSchema<T>;
|
|
604
606
|
/** An array of strings listing all generated error messages from encountered errors for this widget */
|
|
605
607
|
rawErrors?: string[];
|
|
606
608
|
/** The `registry` object */
|