react-native-molecules 0.5.0-beta.12 → 0.5.0-beta.13
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/package.json
CHANGED
|
@@ -49,43 +49,69 @@ const getDocumentAsyncWeb = async ({
|
|
|
49
49
|
throw error;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
try {
|
|
54
|
+
const input = document.createElement('input');
|
|
55
|
+
input.style.display = 'none';
|
|
56
|
+
input.setAttribute('type', 'file');
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
input.setAttribute('accept', Array.isArray(type) ? type.join(',') : type);
|
|
59
|
+
|
|
60
|
+
if (multiple) {
|
|
61
|
+
input.setAttribute('multiple', 'multiple');
|
|
62
|
+
}
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
document.body.appendChild(input);
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
const cleanup = () => {
|
|
67
|
+
try {
|
|
68
|
+
document.body.removeChild(input);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Input already removed, ignore
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
input.addEventListener('change', async () => {
|
|
75
|
+
try {
|
|
76
|
+
if (input.files && input.files.length > 0) {
|
|
77
|
+
const response: Promise<DocumentResult>[] = [];
|
|
78
|
+
|
|
79
|
+
Array.from(input.files).forEach(file =>
|
|
80
|
+
response.push(resolveFileData(file)),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const results = await Promise.all(response);
|
|
84
|
+
resolve(results);
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
onError?.(error);
|
|
77
88
|
reject(error);
|
|
89
|
+
} finally {
|
|
90
|
+
cleanup();
|
|
78
91
|
}
|
|
79
|
-
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
input.addEventListener('cancel', () => {
|
|
95
|
+
const error = new OperationCanceledError();
|
|
96
|
+
onCancel?.();
|
|
97
|
+
cleanup();
|
|
98
|
+
reject(error);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
input.addEventListener('error', () => {
|
|
102
|
+
const error = new Error('File picker error occurred');
|
|
80
103
|
onError?.(error);
|
|
104
|
+
cleanup();
|
|
81
105
|
reject(error);
|
|
82
|
-
}
|
|
83
|
-
document.body.removeChild(input);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
106
|
+
});
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
const event = new MouseEvent('click');
|
|
109
|
+
input.dispatchEvent(event);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
// Handle errors from file picker setup or opening
|
|
112
|
+
onError?.(error);
|
|
113
|
+
reject(error);
|
|
114
|
+
}
|
|
89
115
|
});
|
|
90
116
|
};
|
|
91
117
|
|