@aws-amplify/ui-react-storage 0.0.0-studio-console-80bb2e2-20230921222703 → 0.0.0-theming-v2-c5d1f72-20240709163904

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.
Files changed (51) hide show
  1. package/dist/esm/components/StorageImage/StorageImage.mjs +57 -1
  2. package/dist/esm/components/StorageManager/StorageManager.mjs +181 -1
  3. package/dist/esm/components/StorageManager/hooks/useStorageManager/actions.mjs +35 -1
  4. package/dist/esm/components/StorageManager/hooks/useStorageManager/reducer.mjs +132 -1
  5. package/dist/esm/components/StorageManager/hooks/useStorageManager/types.mjs +12 -1
  6. package/dist/esm/components/StorageManager/hooks/useStorageManager/useStorageManager.mjs +58 -1
  7. package/dist/esm/components/StorageManager/hooks/useUploadFiles/useUploadFiles.mjs +74 -1
  8. package/dist/esm/components/StorageManager/types.mjs +11 -1
  9. package/dist/esm/components/StorageManager/ui/Container/Container.mjs +8 -1
  10. package/dist/esm/components/StorageManager/ui/DropZone/DropZone.mjs +16 -1
  11. package/dist/esm/components/StorageManager/ui/FileList/FileControl.mjs +23 -1
  12. package/dist/esm/components/StorageManager/ui/FileList/FileDetails.mjs +15 -1
  13. package/dist/esm/components/StorageManager/ui/FileList/FileList.mjs +44 -1
  14. package/dist/esm/components/StorageManager/ui/FileList/FileRemoveButton.mjs +12 -1
  15. package/dist/esm/components/StorageManager/ui/FileList/FileStatusMessage.mjs +28 -1
  16. package/dist/esm/components/StorageManager/ui/FileList/FileThumbnail.mjs +12 -1
  17. package/dist/esm/components/StorageManager/ui/FileListFooter/FileListFooter.mjs +13 -1
  18. package/dist/esm/components/StorageManager/ui/FileListHeader/FileListHeader.mjs +14 -1
  19. package/dist/esm/components/StorageManager/ui/FilePicker/FilePicker.mjs +9 -1
  20. package/dist/esm/components/StorageManager/utils/checkMaxFileSize.mjs +12 -1
  21. package/dist/esm/components/StorageManager/utils/displayText.mjs +39 -1
  22. package/dist/esm/components/StorageManager/utils/filterAllowedFiles.mjs +27 -1
  23. package/dist/esm/components/StorageManager/utils/getInput.mjs +25 -0
  24. package/dist/esm/components/StorageManager/utils/humanFileSize.mjs +29 -1
  25. package/dist/esm/components/StorageManager/utils/resolveFile.mjs +20 -0
  26. package/dist/esm/components/StorageManager/utils/uploadFile.mjs +26 -1
  27. package/dist/esm/index.mjs +2 -1
  28. package/dist/esm/version.mjs +3 -0
  29. package/dist/index.js +832 -1
  30. package/dist/styles.css +462 -370
  31. package/dist/types/components/StorageImage/StorageImage.d.ts +6 -2
  32. package/dist/types/components/StorageImage/types.d.ts +33 -2
  33. package/dist/types/components/StorageManager/StorageManager.d.ts +5 -2
  34. package/dist/types/components/StorageManager/hooks/useStorageManager/actions.d.ts +2 -5
  35. package/dist/types/components/StorageManager/hooks/useStorageManager/types.d.ts +1 -1
  36. package/dist/types/components/StorageManager/hooks/useStorageManager/useStorageManager.d.ts +2 -5
  37. package/dist/types/components/StorageManager/hooks/useUploadFiles/useUploadFiles.d.ts +5 -2
  38. package/dist/types/components/StorageManager/types.d.ts +17 -11
  39. package/dist/types/components/StorageManager/ui/FileList/types.d.ts +7 -17
  40. package/dist/types/components/StorageManager/ui/FileListFooter/FileListFooter.d.ts +2 -2
  41. package/dist/types/components/StorageManager/ui/FileListHeader/FileListHeader.d.ts +2 -2
  42. package/dist/types/components/StorageManager/utils/displayText.d.ts +22 -20
  43. package/dist/types/components/StorageManager/utils/getInput.d.ts +13 -0
  44. package/dist/types/components/StorageManager/utils/index.d.ts +3 -2
  45. package/dist/types/components/StorageManager/utils/resolveFile.d.ts +9 -0
  46. package/dist/types/components/StorageManager/utils/uploadFile.d.ts +30 -17
  47. package/dist/types/version.d.ts +1 -0
  48. package/package.json +9 -40
  49. package/dist/esm/components/StorageManager/hooks/useUploadFiles/resolveFile.mjs +0 -1
  50. package/dist/types/components/StorageImage/_tests_/StorageImage.test.d.ts +0 -1
  51. package/dist/types/components/StorageManager/hooks/useUploadFiles/resolveFile.d.ts +0 -10
@@ -1 +1,15 @@
1
- import e from"react";import{ComponentClassName as a}from"@aws-amplify/ui";import{View as m,Text as r}from"@aws-amplify/ui-react";import{humanFileSize as t}from"../../utils/humanFileSize.mjs";import"aws-amplify";const i=({displayName:i,fileSize:l})=>e.createElement(e.Fragment,null,e.createElement(m,{className:a.StorageManagerFileMain},e.createElement(r,{className:a.StorageManagerFileName},i)),e.createElement(r,{as:"span",className:a.StorageManagerFileSize},l?t(l,!0):""));export{i as UploadDetails};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { View, Text } from '@aws-amplify/ui-react';
4
+ import { humanFileSize } from '../../utils/humanFileSize.mjs';
5
+ import 'aws-amplify/auth';
6
+ import 'aws-amplify/storage';
7
+
8
+ const UploadDetails = ({ displayName, fileSize, }) => {
9
+ return (React__default.createElement(React__default.Fragment, null,
10
+ React__default.createElement(View, { className: ComponentClassName.StorageManagerFileMain },
11
+ React__default.createElement(Text, { className: ComponentClassName.StorageManagerFileName }, displayName)),
12
+ React__default.createElement(Text, { as: "span", className: ComponentClassName.StorageManagerFileSize }, fileSize ? humanFileSize(fileSize, true) : '')));
13
+ };
14
+
15
+ export { UploadDetails };
@@ -1 +1,44 @@
1
- import e from"react";import{ComponentClassName as a}from"@aws-amplify/ui";import{View as r,Alert as s}from"@aws-amplify/ui-react";import{FileStatus as o}from"../../types.mjs";import{FileControl as i}from"./FileControl.mjs";function t({displayText:t,files:l,hasMaxFilesError:m,isResumable:n,onCancelUpload:u,onDeleteUpload:p,onResume:d,onPause:c,showThumbnails:f,maxFileCount:g}){if(l.length<1)return null;const{getMaxFilesErrorText:T}=t,U=T(g);return e.createElement(r,{className:a.StorageManagerFileList},l.map((a=>{const{file:r,status:s,progress:l,error:m,key:g,isImage:T,id:U,uploadTask:h}=a,y=r&&T?URL.createObjectURL(r):"",x=!n||l>0,R=s===o.UPLOADING;return e.createElement(i,{displayName:g,errorMessage:m,displayText:t,isImage:T,isUploading:R,isResumable:n,key:U,loaderIsDeterminate:x,onRemove:()=>{n&&(s===o.UPLOADING||s===o.PAUSED)&&h?u({id:U,uploadTask:h}):p({id:U})},onPause:()=>{h&&c({id:U,uploadTask:h})},onResume:()=>{h&&d({id:U,uploadTask:h})},progress:l,showThumbnails:f,size:r?.size,status:s,thumbnailUrl:y})})),m&&e.createElement(s,{variation:"error",heading:U}))}export{t as FileList};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { View, Alert } from '@aws-amplify/ui-react';
4
+ import { FileStatus } from '../../types.mjs';
5
+ import { FileControl } from './FileControl.mjs';
6
+
7
+ function FileList({ displayText, files, hasMaxFilesError, isResumable, onCancelUpload, onDeleteUpload, onResume, onPause, showThumbnails, maxFileCount, }) {
8
+ if (files.length < 1) {
9
+ return null;
10
+ }
11
+ const { getMaxFilesErrorText } = displayText;
12
+ const headingMaxFiles = getMaxFilesErrorText(maxFileCount);
13
+ return (React__default.createElement(View, { className: ComponentClassName.StorageManagerFileList },
14
+ files.map((storageFile) => {
15
+ const { file, status, progress, error, key, isImage, id, uploadTask } = storageFile;
16
+ const thumbnailUrl = file && isImage ? URL.createObjectURL(file) : '';
17
+ const loaderIsDeterminate = isResumable ? progress > 0 : true;
18
+ const isUploading = status === FileStatus.UPLOADING;
19
+ const onRemove = () => {
20
+ if (isResumable &&
21
+ (status === FileStatus.UPLOADING || status === FileStatus.PAUSED) &&
22
+ uploadTask) {
23
+ onCancelUpload({ id, uploadTask });
24
+ }
25
+ else {
26
+ onDeleteUpload({ id });
27
+ }
28
+ };
29
+ const handlePauseUpload = () => {
30
+ if (uploadTask) {
31
+ onPause({ id, uploadTask });
32
+ }
33
+ };
34
+ const handleResumeUpload = () => {
35
+ if (uploadTask) {
36
+ onResume({ id, uploadTask });
37
+ }
38
+ };
39
+ return (React__default.createElement(FileControl, { displayName: key, errorMessage: error, displayText: displayText, isImage: isImage, isUploading: isUploading, isResumable: isResumable, key: id, loaderIsDeterminate: loaderIsDeterminate, onRemove: onRemove, onPause: handlePauseUpload, onResume: handleResumeUpload, progress: progress, showThumbnails: showThumbnails, size: file?.size, status: status, thumbnailUrl: thumbnailUrl }));
40
+ }),
41
+ hasMaxFilesError && (React__default.createElement(Alert, { variation: "error", heading: headingMaxFiles }))));
42
+ }
43
+
44
+ export { FileList };
@@ -1 +1,12 @@
1
- import e from"react";import{useIcons as t,IconClose as a}from"@aws-amplify/ui-react/internal";import{Button as r,VisuallyHidden as n,View as l}from"@aws-amplify/ui-react";const m=({altText:m,onClick:i})=>{const o=t("storageManager");return e.createElement(r,{size:"small",onClick:i},e.createElement(n,null,m),e.createElement(l,{as:"span","aria-hidden":!0,fontSize:"medium"},o?.remove??e.createElement(a,null)))};export{m as FileRemoveButton};
1
+ import React__default from 'react';
2
+ import { useIcons, IconClose } from '@aws-amplify/ui-react/internal';
3
+ import { Button, VisuallyHidden, View } from '@aws-amplify/ui-react';
4
+
5
+ const FileRemoveButton = ({ altText, onClick, }) => {
6
+ const icons = useIcons('storageManager');
7
+ return (React__default.createElement(Button, { size: "small", onClick: onClick },
8
+ React__default.createElement(VisuallyHidden, null, altText),
9
+ React__default.createElement(View, { as: "span", "aria-hidden": true, fontSize: "medium" }, icons?.remove ?? React__default.createElement(IconClose, null))));
10
+ };
11
+
12
+ export { FileRemoveButton };
@@ -1 +1,28 @@
1
- import e from"react";import a from"classnames";import{ComponentClassName as t,classNameModifier as r}from"@aws-amplify/ui";import{Text as s,View as l}from"@aws-amplify/ui-react";import{useIcons as n,IconError as c,IconCheck as m}from"@aws-amplify/ui-react/internal";import{FileStatus as o}from"../../types.mjs";const u=({errorMessage:u,getPausedText:i,getUploadingText:g,percentage:p,status:S,uploadSuccessfulText:f})=>{const E=n("storageManager");switch(S){case o.UPLOADING:return e.createElement(s,{className:t.StorageManagerFileStatus},g(p));case o.PAUSED:return e.createElement(s,{className:t.StorageManagerFileStatus},i(p));case o.UPLOADED:return e.createElement(s,{className:a(t.StorageManagerFileStatus,r(t.StorageManagerFileStatus,"success"))},e.createElement(l,{as:"span",fontSize:"xl"},E?.success??e.createElement(m,null)),f);case o.ERROR:return e.createElement(s,{className:a(t.StorageManagerFileStatus,r(t.StorageManagerFileStatus,"error"))},e.createElement(l,{as:"span",fontSize:"xl"},E?.error??e.createElement(c,null)),u);default:return null}};export{u as FileStatusMessage};
1
+ import React__default from 'react';
2
+ import { classNames, ComponentClassName, classNameModifier } from '@aws-amplify/ui';
3
+ import { Text, View } from '@aws-amplify/ui-react';
4
+ import { useIcons, IconError, IconCheck } from '@aws-amplify/ui-react/internal';
5
+ import { FileStatus } from '../../types.mjs';
6
+
7
+ const FileStatusMessage = ({ errorMessage, getPausedText, getUploadingText, percentage, status, uploadSuccessfulText, }) => {
8
+ const icons = useIcons('storageManager');
9
+ switch (status) {
10
+ case FileStatus.UPLOADING: {
11
+ return (React__default.createElement(Text, { className: ComponentClassName.StorageManagerFileStatus }, getUploadingText(percentage)));
12
+ }
13
+ case FileStatus.PAUSED:
14
+ return (React__default.createElement(Text, { className: ComponentClassName.StorageManagerFileStatus }, getPausedText(percentage)));
15
+ case FileStatus.UPLOADED:
16
+ return (React__default.createElement(Text, { className: classNames(ComponentClassName.StorageManagerFileStatus, classNameModifier(ComponentClassName.StorageManagerFileStatus, 'success')) },
17
+ React__default.createElement(View, { as: "span", fontSize: "xl" }, icons?.success ?? React__default.createElement(IconCheck, null)),
18
+ uploadSuccessfulText));
19
+ case FileStatus.ERROR:
20
+ return (React__default.createElement(Text, { className: classNames(ComponentClassName.StorageManagerFileStatus, classNameModifier(ComponentClassName.StorageManagerFileStatus, 'error')) },
21
+ React__default.createElement(View, { as: "span", fontSize: "xl" }, icons?.error ?? React__default.createElement(IconError, null)),
22
+ errorMessage));
23
+ default:
24
+ return null;
25
+ }
26
+ };
27
+
28
+ export { FileStatusMessage };
@@ -1 +1,12 @@
1
- import e from"react";import{ComponentClassName as a}from"@aws-amplify/ui";import{Image as r,View as t}from"@aws-amplify/ui-react";import{useIcons as m,IconFile as i}from"@aws-amplify/ui-react/internal";const l=({fileName:l,isImage:o,url:n})=>{const c=m("storageManager"),s=o?e.createElement(r,{alt:l,src:n}):c?.file??e.createElement(i,null);return e.createElement(t,{className:a.StorageManagerFileImage},s)};export{l as FileThumbnail};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { Image, View } from '@aws-amplify/ui-react';
4
+ import { useIcons, IconFile } from '@aws-amplify/ui-react/internal';
5
+
6
+ const FileThumbnail = ({ fileName, isImage, url, }) => {
7
+ const icons = useIcons('storageManager');
8
+ const thumbnail = isImage ? (React__default.createElement(Image, { alt: fileName, src: url })) : (icons?.file ?? React__default.createElement(IconFile, null));
9
+ return (React__default.createElement(View, { className: ComponentClassName.StorageManagerFileImage }, thumbnail));
10
+ };
11
+
12
+ export { FileThumbnail };
@@ -1 +1,13 @@
1
- import e from"react";import{ComponentClassName as a}from"@aws-amplify/ui";import{View as t,Button as r}from"@aws-amplify/ui-react";function l({displayText:l,remainingFilesCount:i,onClearAll:o,onUploadAll:n}){const{clearAllButtonText:m,getUploadButtonText:c}=l;return e.createElement(t,{className:a.StorageManagerPreviewerFooter},e.createElement(t,{className:a.StorageManagerPreviewerActions},e.createElement(r,{size:"small",variation:"link",onClick:o},m),e.createElement(r,{size:"small",variation:"primary",onClick:n},c(i))))}export{l as FileListFooter};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { View, Button } from '@aws-amplify/ui-react';
4
+
5
+ function FileListFooter({ displayText, remainingFilesCount, onClearAll, onUploadAll, }) {
6
+ const { clearAllButtonText, getUploadButtonText } = displayText;
7
+ return (React__default.createElement(View, { className: ComponentClassName.StorageManagerPreviewerFooter },
8
+ React__default.createElement(View, { className: ComponentClassName.StorageManagerPreviewerActions },
9
+ React__default.createElement(Button, { size: "small", variation: "link", onClick: onClearAll }, clearAllButtonText),
10
+ React__default.createElement(Button, { size: "small", variation: "primary", onClick: onUploadAll }, getUploadButtonText(remainingFilesCount)))));
11
+ }
12
+
13
+ export { FileListFooter };
@@ -1 +1,14 @@
1
- import e from"react";import{ComponentClassName as t}from"@aws-amplify/ui";import{Text as i}from"@aws-amplify/ui-react";function a({allUploadsSuccessful:a,displayText:l,fileCount:r,remainingFilesCount:o,selectedFilesCount:s=0}){const{getFilesUploadedText:n,getRemainingFilesText:m,getSelectedFilesText:c}=l;return e.createElement(i,{className:t.StorageManagerPreviewerText},s?c(s):a?n(r):m(o))}export{a as FileListHeader};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { Text } from '@aws-amplify/ui-react';
4
+
5
+ function FileListHeader({ allUploadsSuccessful, displayText, fileCount, remainingFilesCount, selectedFilesCount = 0, }) {
6
+ const { getFilesUploadedText, getRemainingFilesText, getSelectedFilesText } = displayText;
7
+ return (React__default.createElement(Text, { className: ComponentClassName.StorageManagerPreviewerText }, selectedFilesCount
8
+ ? getSelectedFilesText(selectedFilesCount)
9
+ : allUploadsSuccessful
10
+ ? getFilesUploadedText(fileCount)
11
+ : getRemainingFilesText(remainingFilesCount)));
12
+ }
13
+
14
+ export { FileListHeader };
@@ -1 +1,9 @@
1
- import e from"react";import{ComponentClassName as r}from"@aws-amplify/ui";import{Button as a}from"@aws-amplify/ui-react";function i({children:i,className:m=r.StorageManagerFilePicker,size:t="small",...l}){return e.createElement(a,{...l,className:m,size:t},i)}export{i as FilePicker};
1
+ import React__default from 'react';
2
+ import { ComponentClassName } from '@aws-amplify/ui';
3
+ import { Button } from '@aws-amplify/ui-react';
4
+
5
+ function FilePicker({ children, className = ComponentClassName.StorageManagerFilePicker, size = 'small', ...props }) {
6
+ return (React__default.createElement(Button, { ...props, className: className, size: size }, children));
7
+ }
8
+
9
+ export { FilePicker };
@@ -1 +1,12 @@
1
- import{humanFileSize as e}from"./humanFileSize.mjs";const i=({file:i,getFileSizeErrorText:o,maxFileSize:r})=>void 0===r?"":i.size>r?o(e(r,!0)):"";export{i as checkMaxFileSize};
1
+ import { humanFileSize } from './humanFileSize.mjs';
2
+
3
+ const checkMaxFileSize = ({ file, getFileSizeErrorText, maxFileSize, }) => {
4
+ if (maxFileSize === undefined)
5
+ return '';
6
+ if (file.size > maxFileSize) {
7
+ return getFileSizeErrorText(humanFileSize(maxFileSize, true));
8
+ }
9
+ return '';
10
+ };
11
+
12
+ export { checkMaxFileSize };
@@ -1 +1,39 @@
1
- const e={getFilesUploadedText:e=>`${e} ${1===e?"file uploaded":"files uploaded"}`,getFileSizeErrorText:e=>`File size must be below ${e}`,getRemainingFilesText:e=>`${e} ${1===e?"file":"files"} uploading`,getSelectedFilesText:e=>`${e} ${1===e?"file":"files"} selected`,getUploadingText:e=>"Uploading"+(e>0?`: ${e}%`:""),getUploadButtonText:e=>`Upload ${e} ${1===e?"file":"files"}`,getMaxFilesErrorText:e=>`Cannot choose more than ${e} ${1===e?"file":"files"}. Remove files before updating`,getErrorText:e=>e,doneButtonText:"Done",clearAllButtonText:"Clear all",extensionNotAllowedText:"Extension not allowed",browseFilesText:"Browse files",dropFilesText:"Drop files here or",pauseText:"Pause",resumeText:"Resume",uploadSuccessfulText:"Uploaded",getPausedText:e=>`Paused: ${e}%`};export{e as defaultStorageManagerDisplayText};
1
+ const defaultStorageManagerDisplayText = {
2
+ getFilesUploadedText(count) {
3
+ return `${count} ${count === 1 ? 'file uploaded' : 'files uploaded'}`;
4
+ },
5
+ getFileSizeErrorText(sizeText) {
6
+ return `File size must be below ${sizeText}`;
7
+ },
8
+ getRemainingFilesText(count) {
9
+ return `${count} ${count === 1 ? 'file' : 'files'} uploading`;
10
+ },
11
+ getSelectedFilesText(count) {
12
+ return `${count} ${count === 1 ? 'file' : 'files'} selected`;
13
+ },
14
+ getUploadingText(percentage) {
15
+ return `Uploading${percentage > 0 ? `: ${percentage}%` : ''}`;
16
+ },
17
+ getUploadButtonText(count) {
18
+ return `Upload ${count} ${count === 1 ? 'file' : 'files'}`;
19
+ },
20
+ getMaxFilesErrorText(count) {
21
+ return `Cannot choose more than ${count} ${count === 1 ? 'file' : 'files'}. Remove files before updating`;
22
+ },
23
+ getErrorText(message) {
24
+ return message;
25
+ },
26
+ doneButtonText: 'Done',
27
+ clearAllButtonText: 'Clear all',
28
+ extensionNotAllowedText: 'Extension not allowed',
29
+ browseFilesText: 'Browse files',
30
+ dropFilesText: 'Drop files here or',
31
+ pauseButtonText: 'Pause',
32
+ resumeButtonText: 'Resume',
33
+ uploadSuccessfulText: 'Uploaded',
34
+ getPausedText(percentage) {
35
+ return `Paused: ${percentage}%`;
36
+ },
37
+ };
38
+
39
+ export { defaultStorageManagerDisplayText };
@@ -1 +1,27 @@
1
- const e=(e,t)=>!t||0===t.length||t.includes("*")?e:e.filter((e=>{const r=e.name||"",o=(e.type||"").toLowerCase(),n=o.replace(/\/.*$/,"");return t.some((e=>{const t=e.trim().toLowerCase();return"."===t.charAt(0)?r.toLowerCase().endsWith(t):t.endsWith("/*")?n===t.replace(/\/.*$/,""):o===t}))}));export{e as filterAllowedFiles};
1
+ const filterAllowedFiles = (files, acceptedFileTypes) => {
2
+ // Allow any files if acceptedFileTypes is undefined, empty array, or contains '*'
3
+ if (!acceptedFileTypes ||
4
+ acceptedFileTypes.length === 0 ||
5
+ acceptedFileTypes.includes('*')) {
6
+ return files;
7
+ }
8
+ // Remove any files that are not in the accepted file list
9
+ return files.filter((file) => {
10
+ const fileName = file.name || '';
11
+ const mimeType = (file.type || '').toLowerCase();
12
+ const baseMimeType = mimeType.replace(/\/.*$/, '');
13
+ return acceptedFileTypes.some((type) => {
14
+ const validType = type.trim().toLowerCase();
15
+ if (validType.charAt(0) === '.') {
16
+ return fileName.toLowerCase().endsWith(validType);
17
+ }
18
+ else if (validType.endsWith('/*')) {
19
+ // This is something like a image/* mime type
20
+ return baseMimeType === validType.replace(/\/.*$/, '');
21
+ }
22
+ return mimeType === validType;
23
+ });
24
+ });
25
+ };
26
+
27
+ export { filterAllowedFiles };
@@ -0,0 +1,25 @@
1
+ import { fetchAuthSession } from 'aws-amplify/auth';
2
+ import { isTypedFunction, isString } from '@aws-amplify/ui';
3
+ import { resolveFile } from './resolveFile.mjs';
4
+
5
+ const getInput = ({ accessLevel, file, key, onProgress, path, processFile, }) => {
6
+ return async () => {
7
+ const hasCallbackPath = isTypedFunction(path);
8
+ const hasStringPath = isString(path);
9
+ const hasKeyInput = !!accessLevel && !hasCallbackPath;
10
+ const { file: data, key: fileKey, ...rest } = await resolveFile({ file, key, processFile });
11
+ const contentType = file.type || 'binary/octet-stream';
12
+ // IMPORTANT: always pass `...rest` here for backwards compatibility
13
+ const options = { contentType, onProgress, ...rest };
14
+ if (hasKeyInput) {
15
+ // legacy handling of `path` is to prefix to `fileKey`
16
+ const resolvedKey = hasStringPath ? `${path}${fileKey}` : fileKey;
17
+ return { data, key: resolvedKey, options: { ...options, accessLevel } };
18
+ }
19
+ const { identityId } = await fetchAuthSession();
20
+ const resolvedPath = `${hasCallbackPath ? path({ identityId }) : path}${fileKey}`;
21
+ return { data: file, path: resolvedPath, options };
22
+ };
23
+ };
24
+
25
+ export { getInput };
@@ -1 +1,29 @@
1
- function B(B,t=!1,i=1){const n=t?1e3:1024;if(Math.abs(B)<n)return`${B} B`;const e=t?["kB","MB","GB","TB","PB","EB","ZB","YB"]:["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"];let o=-1;const r=10**i;do{B/=n,++o}while(Math.round(Math.abs(B)*r)/r>=n&&o<e.length-1);return B.toFixed(i)+" "+e[o]}export{B as humanFileSize};
1
+ /**
2
+ * Format bytes as human-readable text.
3
+ *
4
+ * @param bytes Number of bytes.
5
+ * @param si True to use metric (SI) units, aka powers of 1000. False to use
6
+ * binary (IEC), aka powers of 1024.
7
+ * @param dp Number of decimal places to display.
8
+ *
9
+ * @return Formatted string.
10
+ */
11
+ function humanFileSize(bytes, si = false, dp = 1) {
12
+ const thresh = si ? 1000 : 1024;
13
+ if (Math.abs(bytes) < thresh) {
14
+ return `${bytes} B`;
15
+ }
16
+ const units = si
17
+ ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
18
+ : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
19
+ let unit = -1;
20
+ const range = 10 ** dp;
21
+ do {
22
+ bytes /= thresh;
23
+ ++unit;
24
+ } while (Math.round(Math.abs(bytes) * range) / range >= thresh &&
25
+ unit < units.length - 1);
26
+ return bytes.toFixed(dp) + ' ' + units[unit];
27
+ }
28
+
29
+ export { humanFileSize };
@@ -0,0 +1,20 @@
1
+ import { isFunction } from '@aws-amplify/ui';
2
+
3
+ /**
4
+ * Utility function that takes the processFile prop, along with a file a key
5
+ * and returns a Promise that resolves to { file, key, ..rest }
6
+ * regardless if processFile is defined and if it is sync or async
7
+ */
8
+ const resolveFile = ({ processFile, ...input }) => {
9
+ return new Promise((resolve, reject) => {
10
+ const result = isFunction(processFile) ? processFile(input) : input;
11
+ if (result instanceof Promise) {
12
+ result.then(resolve).catch(reject);
13
+ }
14
+ else {
15
+ resolve(result);
16
+ }
17
+ });
18
+ };
19
+
20
+ export { resolveFile };
@@ -1 +1,26 @@
1
- import{Storage as e}from"aws-amplify";function r({file:r,key:l,level:a="private",progressCallback:t,errorCallback:o,completeCallback:p,isResumable:c=!1,provider:s,...b}){const i=r.type||"binary/octet-stream";return!0===c?e.put(l,r,{level:a,resumable:!0,progressCallback:t,errorCallback:o,completeCallback:p,contentType:i,provider:s,...b}):e.put(l,r,{level:a,resumable:!1,progressCallback:t,contentType:i,provider:s,...b}).then(p,o)}export{r as uploadFile};
1
+ import { uploadData } from 'aws-amplify/storage';
2
+ import { isFunction } from '@aws-amplify/ui';
3
+
4
+ async function uploadFile({ input, onError, onStart, onComplete, }) {
5
+ const resolvedInput = await input();
6
+ const uploadTask = uploadData(resolvedInput);
7
+ const key = resolvedInput?.key ??
8
+ resolvedInput?.path;
9
+ if (isFunction(onStart)) {
10
+ onStart({ key, uploadTask });
11
+ }
12
+ uploadTask.result
13
+ .then((result) => {
14
+ if (isFunction(onComplete) && uploadTask.state === 'SUCCESS') {
15
+ onComplete(result);
16
+ }
17
+ })
18
+ .catch((error) => {
19
+ if (isFunction(onError)) {
20
+ onError({ key, error });
21
+ }
22
+ });
23
+ return uploadTask;
24
+ }
25
+
26
+ export { uploadFile };
@@ -1 +1,2 @@
1
- export{StorageImage}from"./components/StorageImage/StorageImage.mjs";export{StorageManager}from"./components/StorageManager/StorageManager.mjs";
1
+ export { StorageImage } from './components/StorageImage/StorageImage.mjs';
2
+ export { StorageManager } from './components/StorageManager/StorageManager.mjs';
@@ -0,0 +1,3 @@
1
+ const VERSION = '3.1.3';
2
+
3
+ export { VERSION };