@micromerce/media-fileuploader 1.0.1065 → 1.0.1068
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/cjs/index.js +9 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +9 -3
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -18227,19 +18227,20 @@ const FileUploader = ({ ...props }) => {
|
|
|
18227
18227
|
endpoints = typeof endpoints === 'string' ? JSON.parse(endpoints) : endpoints;
|
|
18228
18228
|
const accept = MEDIA_TYPE[type]?.name;
|
|
18229
18229
|
const infoText = info || t('info');
|
|
18230
|
-
const firstEndpoint = endpoints?.find(() => true)?.url;
|
|
18230
|
+
const firstEndpoint = endpoints?.find(() => true)?.url || '';
|
|
18231
18231
|
const connectorUrl = endpoints?.length === 1 && firstEndpoint;
|
|
18232
18232
|
const mediaServiceAvailable = connectorUrl || (endpoints && endpoints?.length > 0);
|
|
18233
18233
|
const statefulMode = mode === MODE.STATEFUL;
|
|
18234
18234
|
const inputType = (mediaServiceAvailable && 'file') || 'url';
|
|
18235
|
+
const initialError = error || '';
|
|
18235
18236
|
const initialFile = value ? { name: value.substring(value.lastIndexOf('/') + 1), url: value } : {};
|
|
18236
18237
|
const firstUpdate = r$1.useRef(true);
|
|
18237
18238
|
const [uppy, setUppy] = r$1.useState();
|
|
18238
18239
|
const [file, setFile] = r$1.useState(initialFile);
|
|
18239
18240
|
const [loaded, setLoaded] = r$1.useState(0);
|
|
18240
|
-
const [endpointUrl, setEndpointUrl] = r$1.useState(firstEndpoint
|
|
18241
|
+
const [endpointUrl, setEndpointUrl] = r$1.useState(firstEndpoint);
|
|
18241
18242
|
const [uploaderMessage, setUploaderMessage] = r$1.useState('');
|
|
18242
|
-
const [errorMessage, setErrorMessage] = r$1.useState(
|
|
18243
|
+
const [errorMessage, setErrorMessage] = r$1.useState(initialError);
|
|
18243
18244
|
const [preview, setPreview] = r$1.useState('');
|
|
18244
18245
|
const logError = (args) => {
|
|
18245
18246
|
setLoaded(0); // remove progressbar on error
|
|
@@ -18266,9 +18267,14 @@ const FileUploader = ({ ...props }) => {
|
|
|
18266
18267
|
setUppy(uppyInstance);
|
|
18267
18268
|
return () => uppyInstance.close();
|
|
18268
18269
|
}, []);
|
|
18270
|
+
//* controlled component to catch props changes
|
|
18269
18271
|
r$1.useEffect(() => {
|
|
18270
18272
|
setFile(initialFile); //* update file on value change
|
|
18271
18273
|
}, [value]);
|
|
18274
|
+
r$1.useEffect(() => {
|
|
18275
|
+
setErrorMessage(initialError); //* update error on error change
|
|
18276
|
+
}, [error]);
|
|
18277
|
+
//* ~
|
|
18272
18278
|
r$1.useEffect(() => {
|
|
18273
18279
|
if (onError && errorMessage)
|
|
18274
18280
|
onError(errorMessage);
|