@codeleap/mobile 1.9.11 → 1.9.12
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.
|
@@ -23,5 +23,6 @@ export declare type FileInputProps = {
|
|
|
23
23
|
alertProps?: Parameters<typeof OSAlert.ask>[0];
|
|
24
24
|
pickerOptions?: Partial<Options>;
|
|
25
25
|
required?: boolean;
|
|
26
|
+
onError?: (error: any) => void;
|
|
26
27
|
};
|
|
27
|
-
export declare const FileInput: React.ForwardRefExoticComponent<Pick<FileInputProps, "label" | "variants" | "styles" | "placeholder" | "type" | "options" | "required" | "buttonProps" | "iconName" | "mode" | "onFileSelect" | "alertProps" | "pickerOptions"> & React.RefAttributes<FileInputRef>>;
|
|
28
|
+
export declare const FileInput: React.ForwardRefExoticComponent<Pick<FileInputProps, "label" | "variants" | "styles" | "onError" | "placeholder" | "type" | "options" | "required" | "buttonProps" | "iconName" | "mode" | "onFileSelect" | "alertProps" | "pickerOptions"> & React.RefAttributes<FileInputRef>>;
|
|
@@ -101,7 +101,7 @@ function parsePickerData(data) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
exports.FileInput = (0, react_1.forwardRef)(function (fileInputProps, ref) {
|
|
104
|
-
var _a = fileInputProps.mode, mode = _a === void 0 ? 'hidden' : _a, onFileSelect = fileInputProps.onFileSelect, iconName = fileInputProps.iconName, styles = fileInputProps.styles, label = fileInputProps.label, variants = fileInputProps.variants, options = fileInputProps.options, _b = fileInputProps.type, type = _b === void 0 ? 'image' : _b, alertProps = fileInputProps.alertProps, _c = fileInputProps.placeholder, placeholder = _c === void 0 ? 'Select a file' : _c, pickerOptions = fileInputProps.pickerOptions, required = fileInputProps.required, buttonProps = fileInputProps.buttonProps;
|
|
104
|
+
var _a = fileInputProps.mode, mode = _a === void 0 ? 'hidden' : _a, onFileSelect = fileInputProps.onFileSelect, iconName = fileInputProps.iconName, styles = fileInputProps.styles, label = fileInputProps.label, variants = fileInputProps.variants, options = fileInputProps.options, _b = fileInputProps.type, type = _b === void 0 ? 'image' : _b, alertProps = fileInputProps.alertProps, _c = fileInputProps.placeholder, placeholder = _c === void 0 ? 'Select a file' : _c, pickerOptions = fileInputProps.pickerOptions, required = fileInputProps.required, buttonProps = fileInputProps.buttonProps, onError = fileInputProps.onError;
|
|
105
105
|
var _d = react_1.default.useState(null), file = _d[0], setFile = _d[1];
|
|
106
106
|
var logger = (0, common_1.useCodeleapContext)().logger;
|
|
107
107
|
function openFileSystem() {
|
|
@@ -122,18 +122,35 @@ exports.FileInput = (0, react_1.forwardRef)(function (fileInputProps, ref) {
|
|
|
122
122
|
return [3 /*break*/, 3];
|
|
123
123
|
case 2:
|
|
124
124
|
err_1 = _a.sent();
|
|
125
|
-
|
|
126
|
-
logger.log('User cancelled the picker.', null, 'Component');
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
throw err_1;
|
|
130
|
-
}
|
|
125
|
+
handleError(err_1);
|
|
131
126
|
return [3 /*break*/, 3];
|
|
132
127
|
case 3: return [2 /*return*/];
|
|
133
128
|
}
|
|
134
129
|
});
|
|
135
130
|
});
|
|
136
131
|
}
|
|
132
|
+
function handleError(err) {
|
|
133
|
+
var warn = documentPicker_1.DocumentPicker.isCancel(err) || String(err).includes('Error: User cancelled');
|
|
134
|
+
if (warn) {
|
|
135
|
+
// NOTE yeah, it should not be both of course but just logger.* isn't showing for some reason
|
|
136
|
+
logger.warn(err);
|
|
137
|
+
console.warn(err);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// NOTE yeah, it should not be both of course but just logger.* isn't showing for some reason
|
|
141
|
+
logger.error(err);
|
|
142
|
+
console.error(err);
|
|
143
|
+
if (onError) {
|
|
144
|
+
onError(err);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
OSAlert_1.default.error({
|
|
148
|
+
title: 'Error',
|
|
149
|
+
body: err.message,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
137
154
|
var mergedOptions = __assign(__assign({}, pickerDefaults), pickerOptions);
|
|
138
155
|
var handlePickerResolution = function (data) {
|
|
139
156
|
onFileSelect(mergedOptions.multiple ? data.map(parsePickerData) : [
|
|
@@ -146,10 +163,10 @@ exports.FileInput = (0, react_1.forwardRef)(function (fileInputProps, ref) {
|
|
|
146
163
|
if (type === 'image') {
|
|
147
164
|
OSAlert_1.default.ask(__assign(__assign({ title: 'Change Image', body: 'Do you want to take a new picture or select an existing one?' }, alertProps), { options: [
|
|
148
165
|
__assign({ text: ((_b = (_a = alertProps === null || alertProps === void 0 ? void 0 : alertProps.options) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) || 'Camera', onPress: function () {
|
|
149
|
-
documentPicker_1.ImageCropPicker.openCamera(mergedOptions).then(handlePickerResolution);
|
|
166
|
+
documentPicker_1.ImageCropPicker.openCamera(mergedOptions).then(handlePickerResolution).catch(handleError);
|
|
150
167
|
} }, alertProps === null || alertProps === void 0 ? void 0 : alertProps.options[1]),
|
|
151
168
|
__assign({ text: 'Library', onPress: function () {
|
|
152
|
-
documentPicker_1.ImageCropPicker.openPicker(mergedOptions).then(handlePickerResolution);
|
|
169
|
+
documentPicker_1.ImageCropPicker.openPicker(mergedOptions).then(handlePickerResolution).catch(handleError);
|
|
153
170
|
} }, alertProps === null || alertProps === void 0 ? void 0 : alertProps.options[2]),
|
|
154
171
|
__assign({ text: 'Cancel', style: 'cancel', onPress: function () { } }, alertProps === null || alertProps === void 0 ? void 0 : alertProps.options[0]),
|
|
155
172
|
] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../src/components/FileInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA8D;AAC9D,4DAA2E;AAC3E,2CASyB;AAEzB,m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AE,WAAI,CAAC,CACR,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -37,6 +37,7 @@ export type FileInputProps = {
|
|
|
37
37
|
alertProps?: Parameters<typeof OSAlert.ask>[0]
|
|
38
38
|
pickerOptions?: Partial<Options>
|
|
39
39
|
required?: boolean
|
|
40
|
+
onError?: (error: any) => void
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
const pickerDefaults = {
|
|
@@ -80,6 +81,7 @@ export const FileInput = forwardRef<
|
|
|
80
81
|
pickerOptions,
|
|
81
82
|
required,
|
|
82
83
|
buttonProps,
|
|
84
|
+
onError,
|
|
83
85
|
} = fileInputProps
|
|
84
86
|
|
|
85
87
|
const [file, setFile] = React.useState(null)
|
|
@@ -95,10 +97,27 @@ export const FileInput = forwardRef<
|
|
|
95
97
|
setFile(files)
|
|
96
98
|
onFileSelect(files.map((file) => ({ preview: file.uri, file })))
|
|
97
99
|
} catch (err) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
handleError(err)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleError(err) {
|
|
105
|
+
const warn = DocumentPicker.isCancel(err) || String(err).includes('Error: User cancelled')
|
|
106
|
+
if (warn) {
|
|
107
|
+
// NOTE yeah, it should not be both of course but just logger.* isn't showing for some reason
|
|
108
|
+
logger.warn(err)
|
|
109
|
+
console.warn(err)
|
|
110
|
+
} else {
|
|
111
|
+
// NOTE yeah, it should not be both of course but just logger.* isn't showing for some reason
|
|
112
|
+
logger.error(err)
|
|
113
|
+
console.error(err)
|
|
114
|
+
if (onError) {
|
|
115
|
+
onError(err)
|
|
100
116
|
} else {
|
|
101
|
-
|
|
117
|
+
OSAlert.error({
|
|
118
|
+
title: 'Error',
|
|
119
|
+
body: err.message,
|
|
120
|
+
})
|
|
102
121
|
}
|
|
103
122
|
}
|
|
104
123
|
}
|
|
@@ -115,7 +134,6 @@ export const FileInput = forwardRef<
|
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
const openFilePicker = async () => {
|
|
118
|
-
|
|
119
137
|
if (type === 'image') {
|
|
120
138
|
OSAlert.ask({
|
|
121
139
|
title: 'Change Image',
|
|
@@ -125,14 +143,14 @@ export const FileInput = forwardRef<
|
|
|
125
143
|
{
|
|
126
144
|
text: alertProps?.options?.[0]?.text || 'Camera',
|
|
127
145
|
onPress: () => {
|
|
128
|
-
ImageCropPicker.openCamera(mergedOptions).then(handlePickerResolution)
|
|
146
|
+
ImageCropPicker.openCamera(mergedOptions).then(handlePickerResolution).catch(handleError)
|
|
129
147
|
},
|
|
130
148
|
...alertProps?.options[1],
|
|
131
149
|
},
|
|
132
150
|
{
|
|
133
151
|
text: 'Library',
|
|
134
152
|
onPress: () => {
|
|
135
|
-
ImageCropPicker.openPicker(mergedOptions).then(handlePickerResolution)
|
|
153
|
+
ImageCropPicker.openPicker(mergedOptions).then(handlePickerResolution).catch(handleError)
|
|
136
154
|
},
|
|
137
155
|
...alertProps?.options[2],
|
|
138
156
|
},
|