@aws-amplify/ui-react-storage 0.0.0-storagemanager-86af8ff-20230330233729
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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/esm/StorageManager/Container/Container.mjs +1 -0
- package/dist/esm/StorageManager/DropZone/DropZone.mjs +1 -0
- package/dist/esm/StorageManager/DropZone/FilePicker.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileControl.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileDetails.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileList.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileRemoveButton.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileStatusMessage.mjs +1 -0
- package/dist/esm/StorageManager/FileList/FileThumbnail.mjs +1 -0
- package/dist/esm/StorageManager/FileListHeader/FileListHeader.mjs +1 -0
- package/dist/esm/StorageManager/StorageManager/StorageManager.mjs +1 -0
- package/dist/esm/StorageManager/displayText.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useDropZone/useDropZone.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useStorageManager/actions.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useStorageManager/reducer.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useStorageManager/types.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useStorageManager/useStorageManager.mjs +1 -0
- package/dist/esm/StorageManager/hooks/useUploadFiles/useUploadFiles.mjs +1 -0
- package/dist/esm/StorageManager/types.mjs +1 -0
- package/dist/esm/StorageManager/utils/checkMaxFileSize.mjs +1 -0
- package/dist/esm/StorageManager/utils/filterAllowedFiles.mjs +1 -0
- package/dist/esm/StorageManager/utils/humanFileSize.mjs +1 -0
- package/dist/esm/StorageManager/utils/uploadFile.mjs +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/index.js +1 -0
- package/dist/styles.css +4556 -0
- package/dist/styles.js +2 -0
- package/dist/types/StorageManager/Container/Container.d.ts +7 -0
- package/dist/types/StorageManager/Container/index.d.ts +1 -0
- package/dist/types/StorageManager/DropZone/DropZone.d.ts +3 -0
- package/dist/types/StorageManager/DropZone/FilePicker.d.ts +3 -0
- package/dist/types/StorageManager/DropZone/index.d.ts +1 -0
- package/dist/types/StorageManager/DropZone/types.d.ts +20 -0
- package/dist/types/StorageManager/FileList/FileControl.d.ts +3 -0
- package/dist/types/StorageManager/FileList/FileDetails.d.ts +3 -0
- package/dist/types/StorageManager/FileList/FileList.d.ts +3 -0
- package/dist/types/StorageManager/FileList/FileRemoveButton.d.ts +3 -0
- package/dist/types/StorageManager/FileList/FileStatusMessage.d.ts +3 -0
- package/dist/types/StorageManager/FileList/FileThumbnail.d.ts +3 -0
- package/dist/types/StorageManager/FileList/index.d.ts +1 -0
- package/dist/types/StorageManager/FileList/types.d.ts +61 -0
- package/dist/types/StorageManager/FileListContainer/FileListContainer.d.ts +6 -0
- package/dist/types/StorageManager/FileListContainer/index.d.ts +1 -0
- package/dist/types/StorageManager/FileListHeader/FileListHeader.d.ts +9 -0
- package/dist/types/StorageManager/FileListHeader/index.d.ts +1 -0
- package/dist/types/StorageManager/StorageManager/StorageManager.d.ts +11 -0
- package/dist/types/StorageManager/StorageManager/index.d.ts +1 -0
- package/dist/types/StorageManager/StorageManager/types.d.ts +79 -0
- package/dist/types/StorageManager/displayText.d.ts +19 -0
- package/dist/types/StorageManager/hooks/index.d.ts +3 -0
- package/dist/types/StorageManager/hooks/useDropZone/index.d.ts +1 -0
- package/dist/types/StorageManager/hooks/useDropZone/useDropZone.d.ts +13 -0
- package/dist/types/StorageManager/hooks/useStorageManager/actions.d.ts +19 -0
- package/dist/types/StorageManager/hooks/useStorageManager/index.d.ts +1 -0
- package/dist/types/StorageManager/hooks/useStorageManager/reducer.d.ts +2 -0
- package/dist/types/StorageManager/hooks/useStorageManager/types.d.ts +37 -0
- package/dist/types/StorageManager/hooks/useStorageManager/useStorageManager.d.ts +31 -0
- package/dist/types/StorageManager/hooks/useUploadFiles/index.d.ts +1 -0
- package/dist/types/StorageManager/hooks/useUploadFiles/useUploadFiles.d.ts +5 -0
- package/dist/types/StorageManager/index.d.ts +1 -0
- package/dist/types/StorageManager/types.d.ts +20 -0
- package/dist/types/StorageManager/utils/checkMaxFileSize.d.ts +5 -0
- package/dist/types/StorageManager/utils/filterAllowedFiles.d.ts +1 -0
- package/dist/types/StorageManager/utils/humanFileSize.d.ts +11 -0
- package/dist/types/StorageManager/utils/uploadFile.d.ts +19 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/styles.d.ts +1 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2017 - 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Amplify UI
|
|
2
|
+
|
|
3
|
+
Amplify UI is an open-source UI library with cloud-connected components that are endlessly customizable, accessible, and can integrate into _any_ application. Amplify UI consists of:
|
|
4
|
+
|
|
5
|
+
1. Connected components that simplify complex cloud-connected workflows, like Authenticator.
|
|
6
|
+
2. Primitive components that create consistency across Amplify UI and allow you to build complete applications that fit your brand, like Buttons and Badges.
|
|
7
|
+
3. Data-bound components that make it easy to display dynamic data, like DataStoreCollections.
|
|
8
|
+
4. Theming capabilities that allow you to customize the appearance of Amplify UI to match your brand.
|
|
9
|
+
|
|
10
|
+
## React Documentation
|
|
11
|
+
|
|
12
|
+
- https://ui.docs.amplify.aws/react
|
|
13
|
+
|
|
14
|
+
## Features 🚀
|
|
15
|
+
|
|
16
|
+
- **Better developer experience** Connected-components like Authenticator are being written with framework-specific implementations so that they follow framework conventions and are easier to integrate into your application.
|
|
17
|
+
- **Endlessly customizable** Every detail of Amplify UI is customizable to match your brand. Style all of Amplify UI with themes, override components with your own, or build your own UI and use Amplify for complex state management.
|
|
18
|
+
- **Accessible** Amplify UI components follow [WCAG](https://www.w3.org/WAI/standards-guidelines/wcag/) and [WAI-ARIA](https://www.w3.org/TR/wai-aria-1.2/) best practices and guidelines such as color contrast, keyboard navigation, accessible labels, and focus management.
|
|
19
|
+
- **Primitive components (React only right now)** Primitive components are used in the connected components, like Authenticator, you can also customize them and use them to build the rest of your UI.
|
|
20
|
+
|
|
21
|
+
## We love contributors!!
|
|
22
|
+
|
|
23
|
+
See our contributing guide [CONTRIBUTING.md](/CONTRIBUTING.md) to help us scale Amplify UI!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{View as r}from"@aws-amplify/ui-react";function a({children:a,className:t}){return e.createElement(r,{className:t},a)}export{a as Container};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"react";import e from"classnames";import{View as a,ComponentClassNames as o,Text as n}from"@aws-amplify/ui-react";import{classNameModifier as t}from"@aws-amplify/ui";import{IconUpload as i}from"@aws-amplify/ui-react/internal";function m({inDropZone:m,onDragEnter:p,onDragLeave:g,onDragOver:c,onDragStart:s,onDrop:D,displayText:l,children:f}){const{dropFilesText:S}=l;return r.createElement(a,{className:e(m&&t(o.StorageManagerDropZone,"active"),o.StorageManagerDropZone),onDragStart:s,onDragEnter:p,onDragLeave:g,onDrop:D,onDragOver:c},r.createElement(i,{"aria-hidden":!0,className:o.StorageManagerDropZoneIcon}),r.createElement(n,{className:o.StorageManagerDropZoneText},S),f)}export{m as DropZone};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{View as t,Button as l,ComponentClassNames as n,VisuallyHidden as r}from"@aws-amplify/ui-react";function a({onFileChange:a,acceptedFileTypes:c,allowMultipleFiles:i,displayText:o}){const u=e.useRef(null),{browseFilesText:p}=o;return e.createElement(t,null,e.createElement(l,{className:n.StorageManagerDropZoneButton,onClick:()=>{u.current&&(u.current.click(),u.current.value="")},size:"small"},p),e.createElement(r,null,e.createElement("input",{type:"file",tabIndex:-1,ref:u,onChange:a,multiple:i,accept:c.join(",")})))}export{a as FilePicker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{View as a,ComponentClassNames as t,Loader as r,Button as l}from"@aws-amplify/ui-react";import{FileStatus as s}from"../types.mjs";import{FileStatusMessage as i}from"./FileStatusMessage.mjs";import{FileRemoveButton as m}from"./FileRemoveButton.mjs";import{UploadDetails as n}from"./FileDetails.mjs";import{FileThumbnail as o}from"./FileThumbnail.mjs";function u({onPause:u,onResume:c,displayName:p,errorMessage:g,isImage:f,isResumable:d,loaderIsDeterminate:T,onRemove:x,progress:E,showThumbnails:S=!0,size:N,status:P,displayText:D,thumbnailUrl:U}){const{getPausedText:v,getUploadingText:F,uploadSuccessfulText:M,pauseText:j,resumeText:k}=D;return e.createElement(a,{className:t.StorageManagerFile},e.createElement(a,{className:t.StorageManagerFileWrapper},S?e.createElement(o,{isImage:f,fileName:p,url:U}):null,e.createElement(n,{displayName:p,fileSize:N}),P===s.UPLOADING?e.createElement(r,{className:t.StorageManagerLoader,variation:"linear",percentage:E,isDeterminate:T,isPercentageTextHidden:!0}):null,!d||P!==s.UPLOADING&&P!==s.PAUSED?null:P===s.PAUSED?e.createElement(l,{onClick:c,size:"small",variation:"link"},k):e.createElement(l,{onClick:u,size:"small",variation:"link"},j),e.createElement(m,{altText:`Remove file ${p}`,onClick:x})),e.createElement(i,{uploadSuccessfulText:M,getUploadingText:F,getPausedText:v,status:P,errorMessage:g,percentage:E}))}export{u as FileControl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{View as a,ComponentClassNames as r,Text as t}from"@aws-amplify/ui-react";import{humanFileSize as m}from"@aws-amplify/ui";const l=({displayName:l,fileSize:i})=>e.createElement(e.Fragment,null,e.createElement(a,{className:r.StorageManagerFileMain},e.createElement(t,{className:r.StorageManagerFileName},l)),e.createElement(t,{as:"span",className:r.StorageManagerFileSize},i?m(i,!0):""));export{l as UploadDetails};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{View as a,Alert as s}from"@aws-amplify/ui-react";import{FileStatus as r}from"../types.mjs";import{FileControl as o}from"./FileControl.mjs";function i({displayText:i,files:t,hasMaxFilesError:l,isResumable:m,onCancelUpload:n,onDeleteUpload:u,onResume:p,onPause:d,showThumbnails:c,maxFileCount:f}){if(t.length<1)return null;const{getMaxFilesErrorText:g}=i,T=g(f);return e.createElement(a,{className:"amplify-storagemanager--filelist"},t.map((a=>{const{file:s,status:t,progress:l,error:f,key:g,isImage:T,id:U,uploadTask:h}=a,y=s&&T?URL.createObjectURL(s):"",x=!m||l>0,R=t===r.UPLOADING;return e.createElement(o,{displayName:g,errorMessage:f,displayText:i,isImage:T,isUploading:R,isResumable:m,key:U,loaderIsDeterminate:x,onRemove:()=>{m&&(t===r.UPLOADING||t===r.PAUSED)&&h?n({id:U,uploadTask:h}):u({id:U})},onPause:()=>{h&&d({id:U,uploadTask:h})},onResume:()=>{h&&p({id:U,uploadTask:h})},progress:l,showThumbnails:c,size:null==s?void 0:s.size,status:t,thumbnailUrl:y})})),l&&e.createElement(s,{variation:"error",heading:T}))}export{i as FileList};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{IconClose as t}from"@aws-amplify/ui-react/internal";import{Button as a,VisuallyHidden as i}from"@aws-amplify/ui-react";const r=({altText:r,onClick:m})=>e.createElement(a,{size:"small",onClick:m},e.createElement(i,null,r),e.createElement(t,{"aria-hidden":!0,fontSize:"medium"}));export{r as FileRemoveButton};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import a from"classnames";import{Text as t,ComponentClassNames as r}from"@aws-amplify/ui-react";import{IconError as s,IconCheck as l}from"@aws-amplify/ui-react/internal";import{classNameModifier as m}from"@aws-amplify/ui";import{FileStatus as n}from"../types.mjs";const o=({errorMessage:o,getPausedText:c,getUploadingText:i,percentage:u,status:g,uploadSuccessfulText:S})=>{switch(g){case n.UPLOADING:return e.createElement(t,{className:r.StorageManagerFileStatus},i(u));case n.PAUSED:return e.createElement(t,{className:r.StorageManagerFileStatus},c(u));case n.UPLOADED:return e.createElement(t,{className:a(r.StorageManagerFileStatus,m(r.StorageManagerFileStatus,"success"))},e.createElement(l,{fontSize:"xl"})," ",S);case n.ERROR:return e.createElement(t,{className:a(r.StorageManagerFileStatus,m(r.StorageManagerFileStatus,"error"))},e.createElement(s,{fontSize:"xl"})," ",o);default:return null}};export{o as FileStatusMessage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{Image as a,View as r,ComponentClassNames as t}from"@aws-amplify/ui-react";import{IconFile as m}from"@aws-amplify/ui-react/internal";const l=({fileName:l,isImage:i,url:c})=>{const n=i?e.createElement(a,{alt:l,src:c}):e.createElement(m,null);return e.createElement(r,{className:t.StorageManagerFileImage},n)};export{l as FileThumbnail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"react";import{Text as t,ComponentClassNames as a}from"@aws-amplify/ui-react";function i({fileCount:i,remainingFilesCount:r,displayText:l,allUploadsSuccessful:n}){const{getFilesUploadedText:o,getRemainingFilesText:s}=l;return e.createElement(t,{className:a.StorageManagerPreviewerText},n?o(i):s(r))}export{i as FileListHeader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"react";import{Logger as s}from"aws-amplify";import{checkMaxFileSize as o}from"../utils/checkMaxFileSize.mjs";import{ComponentClassNames as i}from"@aws-amplify/ui-react";import{Container as r}from"../Container/Container.mjs";import{defaultStorageManagerDisplayText as l}from"../displayText.mjs";import{DropZone as a}from"../DropZone/DropZone.mjs";import{FileList as t}from"../FileList/FileList.mjs";import{FileListHeader as n}from"../FileListHeader/FileListHeader.mjs";import{FilePicker as p}from"../DropZone/FilePicker.mjs";import{FileStatus as m}from"../types.mjs";import{filterAllowedFiles as d}from"../utils/filterAllowedFiles.mjs";import{useDropZone as c}from"../hooks/useDropZone/useDropZone.mjs";import{useStorageManager as u}from"../hooks/useStorageManager/useStorageManager.mjs";import{useUploadFiles as F}from"../hooks/useUploadFiles/useUploadFiles.mjs";const f=new s("Storage.StorageManager");function g({acceptedFileTypes:s,accessLevel:g,defaultFiles:y,displayText:U,isResumable:h=!1,maxFileCount:T,maxFileSize:x,onUploadError:j,onUploadSuccess:S,onFileRemove:C,showThumbnails:L=!0,processFile:k,components:E,provider:v}){s&&g&&T||f.warn("FileUploader requires accessLevel, acceptedFileTypes and maxFileCount props");const D=Object.assign({Container:r,DropZone:a,FileList:t,FilePicker:p,FileListHeader:n},E),b=void 0===T||"number"==typeof T&&T>1,M=Object.assign(Object.assign({},l),U),{getFileSizeErrorText:P}=M,w=e=>o({file:e,maxFileSize:x,getFileSizeErrorText:P}),{addFiles:Z,files:R,removeUpload:z,setUploadingFile:H,setUploadPaused:O,setUploadProgress:A,setUploadSuccess:$,setUploadResumed:q}=u(y),N=c({onChange:e=>{const{files:o}=e.dataTransfer;if(!o||0===o.length)return;const i=d(Array.from(o),s);Z({files:i,getFileErrorMessage:w})}});F({accessLevel:g,files:R,isResumable:h,maxFileCount:T,onUploadError:j,onUploadSuccess:S,setUploadingFile:H,setUploadProgress:A,setUploadSuccess:$,processFile:k,provider:v});const B=0!==R.length&&R.every((e=>100===(null==e?void 0:e.progress))),G=R.filter((e=>e.progress<100)).length>T,I=R.filter((e=>(null==e?void 0:e.status)===m.UPLOADED)).length,J=R.length-I,K=R.length>0;return e.createElement(D.Container,{className:`${i.StorageManager} ${K?i.StorageManagerPreviewer:""}`},e.createElement(D.DropZone,Object.assign({},N,{acceptedFileTypes:s,displayText:M}),e.createElement(D.FilePicker,{onFileChange:e=>{const{files:s}=e.target;s&&0!==s.length&&Z({files:Array.from(s),getFileErrorMessage:w})},displayText:M,acceptedFileTypes:s,allowMultipleFiles:b})),K?e.createElement(D.FileListHeader,{allUploadsSuccessful:B,displayText:M,fileCount:R.length,remainingFilesCount:J}):null,e.createElement(D.FileList,{displayText:M,files:R,isResumable:h,onCancelUpload:({id:e,uploadTask:s})=>{s.pause(),z({id:e})},onDeleteUpload:({id:e})=>{if(z({id:e}),"function"==typeof C){const s=R.find((s=>s.id===e));s&&C({key:s.key})}},onResume:({id:e,uploadTask:s})=>{s.resume(),q({id:e})},onPause:({id:e,uploadTask:s})=>{s.pause(),O({id:e})},showThumbnails:L,hasMaxFilesError:G,maxFileCount:T}))}g.Container=r,g.DropZone=a,g.FileList=t,g.FileListHeader=n,g.FilePicker=p;export{g as StorageManager};
|
|
@@ -0,0 +1 @@
|
|
|
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`,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 successfully",getPausedText:e=>`Paused: ${e}%`};export{e as defaultStorageManagerDisplayText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as a}from"react";function r({onChange:r}){const[t,o]=a(!1);return{onDragStart:a=>{a.dataTransfer.clearData()},onDragEnter:a=>{a.preventDefault(),a.stopPropagation()},onDragLeave:a=>{a.preventDefault(),a.stopPropagation(),o(!1)},onDragOver:a=>{a.preventDefault(),a.stopPropagation(),a.dataTransfer.dropEffect="copy",o(!0)},onDrop:a=>{a.preventDefault(),a.stopPropagation(),o(!1),r(a)},inDropZone:t}}export{r as useDropZone};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{StorageManagerActionTypes as e}from"./types.mjs";const s=({files:s,getFileErrorMessage:t})=>({type:e.ADD_FILES,files:s,getFileErrorMessage:t}),t=({id:s,uploadTask:t})=>({type:e.SET_STATUS_UPLOADING,id:s,uploadTask:t}),i=({id:s,progress:t})=>({type:e.SET_UPLOAD_PROGRESS,id:s,progress:t}),r=({id:s,status:t})=>({type:e.SET_STATUS,id:s,status:t}),p=({id:s})=>({type:e.REMOVE_UPLOAD,id:s});export{s as addFilesAction,p as removeUploadAction,i as setUploadProgressAction,r as setUploadStatusAction,t as setUploadingFileAction};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{FileStatus as s}from"../../types.mjs";import{StorageManagerActionTypes as e}from"./types.mjs";function t(t,i){switch(i.type){case e.ADD_FILES:{const{files:e}=i,a=e.map((e=>{const t=i.getFileErrorMessage(e);return{id:e.name,file:e,error:t,key:e.name,status:t?s.ERROR:s.QUEUED,isImage:e.type.startsWith("image/"),progress:-1}})),r=[...t.files,...a];return Object.assign(Object.assign({},t),{files:r})}case e.SET_STATUS_UPLOADING:{const{id:e,uploadTask:a}=i,{files:r}=t,c=r.reduce(((t,i)=>i.id===e?[...t,Object.assign(Object.assign({},i),{status:s.UPLOADING,progress:0,uploadTask:a||void 0})]:[...t,i]),[]);return Object.assign(Object.assign({},t),{files:c})}case e.SET_UPLOAD_PROGRESS:{const{id:s,progress:e}=i,{files:a}=t,r=a.reduce(((t,i)=>i.id===s?[...t,Object.assign(Object.assign({},i),{progress:e})]:[...t,i]),[]);return Object.assign(Object.assign({},t),{files:r})}case e.SET_STATUS:{const{id:s,status:e}=i,{files:a}=t,r=a.reduce(((t,i)=>i.id===s?[...t,Object.assign(Object.assign({},i),{status:e})]:[...t,i]),[]);return Object.assign(Object.assign({},t),{files:r})}case e.REMOVE_UPLOAD:{const{id:s}=i,{files:e}=t,a=e.reduce(((e,t)=>t.id===s?[...e]:[...e,t]),[]);return Object.assign(Object.assign({},t),{files:a})}}}export{t as storageManagerStateReducer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var S;!function(S){S.ADD_FILES="ADD_FILES",S.SET_STATUS="SET_STATUS",S.SET_STATUS_UPLOADING="SET_STATUS_UPLOADING",S.SET_UPLOAD_PROGRESS="SET_UPLOAD_PROGRESS",S.REMOVE_UPLOAD="REMOVE_UPLOAD"}(S||(S={}));export{S as StorageManagerActionTypes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import s from"react";import{FileStatus as e}from"../../types.mjs";import{storageManagerStateReducer as i}from"./reducer.mjs";import{addFilesAction as r,setUploadingFileAction as t,setUploadProgressAction as d,setUploadStatusAction as o,removeUploadAction as a}from"./actions.mjs";function l(l=[]){const[{files:p},m]=s.useReducer(i,{files:l.map((s=>Object.assign(Object.assign({},s),{id:s.key,key:s.key,status:e.UPLOADED})))});return{removeUpload:({id:s})=>{m(a({id:s}))},setUploadPaused:({id:s})=>{m(o({id:s,status:e.PAUSED}))},setUploadProgress:({progress:s,id:e})=>{m(d({id:e,progress:s}))},setUploadResumed:({id:s})=>{m(o({id:s,status:e.UPLOADING}))},setUploadSuccess:({id:s})=>{m(o({id:s,status:e.UPLOADED}))},setUploadingFile:({uploadTask:s,id:e})=>{m(t({id:e,uploadTask:s}))},addFiles:({files:s,getFileErrorMessage:e})=>{m(r({files:s,getFileErrorMessage:e}))},files:p}}export{l as useStorageManager};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"react";import{uploadFile as l}from"../../utils/uploadFile.mjs";import{FileStatus as o}from"../../types.mjs";function s({files:s,accessLevel:i,isResumable:r,setUploadProgress:a,setUploadingFile:t,setUploadSuccess:c,onUploadError:f,onUploadSuccess:p,maxFileCount:d,processFile:n,provider:m}){e.useEffect((()=>{const e=s.filter((e=>e.status===o.QUEUED));if(!(e.length>d))for(const{file:o,key:s,id:d}of e){const e=e=>{null==p||p(e),c({id:d})},u=e=>{const l=0===e.total?100:Math.floor(e.loaded/e.total*100);a({id:d,progress:l})},k=e=>{null==f||f(e)};if(o){const a="function"==typeof n?n({file:o,key:s}):{file:o,key:s};if(r){const o=l({file:a.file,fileName:a.key,isResumable:!0,level:i,completeCallback:e,progressCallback:u,errorCallback:k,provider:m});t({id:d,uploadTask:o})}else l({file:a.file,fileName:a.key,isResumable:!1,level:i,completeCallback:e,progressCallback:u,errorCallback:k,provider:m}),t({id:d})}}}),[s,i,r,a,t,f,p,d,c,n,m])}export{s as useUploadFiles};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e;!function(e){e.QUEUED="queued",e.UPLOADING="uploading",e.PAUSED="paused",e.ERROR="error",e.UPLOADED="uploaded"}(e||(e={}));export{e as FileStatus};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e,t)=>e.filter((e=>{const r=e.name||"",o=(e.type||"").toLowerCase(),s=o.replace(/\/.*$/,"");return t.some((e=>{const t=e.trim().toLowerCase();return"."===t.charAt(0)?r.toLowerCase().endsWith(t):t.endsWith("/*")?s===t.replace(/\/.*$/,""):o===t}))}));export{e as filterAllowedFiles};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function B(B,t=!1,i=1){const n=t?1e3:1024;if(Math.abs(B)<n)return`${B} B`;const o=t?["kB","MB","GB","TB","PB","EB","ZB","YB"]:["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"];let e=-1;const a=Math.pow(10,i);do{B/=n,++e}while(Math.round(Math.abs(B)*a)/a>=n&&e<o.length-1);return B.toFixed(i)+" "+o[e]}export{B as humanFileSize};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__rest as e}from"tslib";import{Storage as l}from"aws-amplify";function r(r){var{file:a,fileName:o,level:t="private",progressCallback:s,errorCallback:p,completeCallback:c,isResumable:i=!1,provider:b}=r,m=e(r,["file","fileName","level","progressCallback","errorCallback","completeCallback","isResumable","provider"]);const n=a.type||"binary/octet-stream";return!0===i?l.put(o,a,Object.assign({level:t,resumable:!0,progressCallback:s,errorCallback:p,completeCallback:c,contentType:n,provider:b},m)):l.put(o,a,Object.assign({level:t,resumable:!1,progressCallback:s,contentType:n,provider:b},m)).then(c,p)}export{r as uploadFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{StorageManager}from"./StorageManager/StorageManager/StorageManager.mjs";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),a=require("aws-amplify"),t=require("@aws-amplify/ui-react"),s=require("classnames"),l=require("@aws-amplify/ui"),r=require("@aws-amplify/ui-react/internal"),n=require("tslib");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var a=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var s=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,s.get?s:{enumerable:!0,get:function(){return e[t]}})}})),a.default=e,Object.freeze(a)}var u=o(e),c=i(e),d=o(s);const p=({file:e,getFileSizeErrorText:a,maxFileSize:t})=>void 0===t?"":e.size>t?a(function(e,a=!1,t=1){const s=a?1e3:1024;if(Math.abs(e)<s)return`${e} B`;const l=a?["kB","MB","GB","TB","PB","EB","ZB","YB"]:["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"];let r=-1;const n=Math.pow(10,t);do{e/=s,++r}while(Math.round(Math.abs(e)*n)/n>=s&&r<l.length-1);return e.toFixed(t)+" "+l[r]}(t,!0)):"";function m({children:e,className:a}){return u.default.createElement(t.View,{className:a},e)}const g={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`,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 successfully",getPausedText:e=>`Paused: ${e}%`};function f({inDropZone:e,onDragEnter:a,onDragLeave:s,onDragOver:n,onDragStart:o,onDrop:i,displayText:c,children:p}){const{dropFilesText:m}=c;return u.default.createElement(t.View,{className:d.default(e&&l.classNameModifier(t.ComponentClassNames.StorageManagerDropZone,"active"),t.ComponentClassNames.StorageManagerDropZone),onDragStart:o,onDragEnter:a,onDragLeave:s,onDrop:i,onDragOver:n},u.default.createElement(r.IconUpload,{"aria-hidden":!0,className:t.ComponentClassNames.StorageManagerDropZoneIcon}),u.default.createElement(t.Text,{className:t.ComponentClassNames.StorageManagerDropZoneText},m),p)}var E;!function(e){e.QUEUED="queued",e.UPLOADING="uploading",e.PAUSED="paused",e.ERROR="error",e.UPLOADED="uploaded"}(E||(E={}));const T=({errorMessage:e,getPausedText:a,getUploadingText:s,percentage:n,status:o,uploadSuccessfulText:i})=>{switch(o){case E.UPLOADING:return u.default.createElement(t.Text,{className:t.ComponentClassNames.StorageManagerFileStatus},s(n));case E.PAUSED:return u.default.createElement(t.Text,{className:t.ComponentClassNames.StorageManagerFileStatus},a(n));case E.UPLOADED:return u.default.createElement(t.Text,{className:d.default(t.ComponentClassNames.StorageManagerFileStatus,l.classNameModifier(t.ComponentClassNames.StorageManagerFileStatus,"success"))},u.default.createElement(r.IconCheck,{fontSize:"xl"})," ",i);case E.ERROR:return u.default.createElement(t.Text,{className:d.default(t.ComponentClassNames.StorageManagerFileStatus,l.classNameModifier(t.ComponentClassNames.StorageManagerFileStatus,"error"))},u.default.createElement(r.IconError,{fontSize:"xl"})," ",e);default:return null}},S=({altText:e,onClick:a})=>u.default.createElement(t.Button,{size:"small",onClick:a},u.default.createElement(t.VisuallyHidden,null,e),u.default.createElement(r.IconClose,{"aria-hidden":!0,fontSize:"medium"})),U=({displayName:e,fileSize:a})=>u.default.createElement(u.default.Fragment,null,u.default.createElement(t.View,{className:t.ComponentClassNames.StorageManagerFileMain},u.default.createElement(t.Text,{className:t.ComponentClassNames.StorageManagerFileName},e)),u.default.createElement(t.Text,{as:"span",className:t.ComponentClassNames.StorageManagerFileSize},a?l.humanFileSize(a,!0):"")),C=({fileName:e,isImage:a,url:s})=>{const l=a?u.default.createElement(t.Image,{alt:e,src:s}):u.default.createElement(r.IconFile,null);return u.default.createElement(t.View,{className:t.ComponentClassNames.StorageManagerFileImage},l)};function D({onPause:e,onResume:a,displayName:s,errorMessage:l,isImage:r,isResumable:n,loaderIsDeterminate:o,onRemove:i,progress:c,showThumbnails:d=!0,size:p,status:m,displayText:g,thumbnailUrl:f}){const{getPausedText:D,getUploadingText:F,uploadSuccessfulText:b,pauseText:x,resumeText:O}=g;return u.default.createElement(t.View,{className:t.ComponentClassNames.StorageManagerFile},u.default.createElement(t.View,{className:t.ComponentClassNames.StorageManagerFileWrapper},d?u.default.createElement(C,{isImage:r,fileName:s,url:f}):null,u.default.createElement(U,{displayName:s,fileSize:p}),m===E.UPLOADING?u.default.createElement(t.Loader,{className:t.ComponentClassNames.StorageManagerLoader,variation:"linear",percentage:c,isDeterminate:o,isPercentageTextHidden:!0}):null,!n||m!==E.UPLOADING&&m!==E.PAUSED?null:m===E.PAUSED?u.default.createElement(t.Button,{onClick:a,size:"small",variation:"link"},O):u.default.createElement(t.Button,{onClick:e,size:"small",variation:"link"},x),u.default.createElement(S,{altText:`Remove file ${s}`,onClick:i})),u.default.createElement(T,{uploadSuccessfulText:b,getUploadingText:F,getPausedText:D,status:m,errorMessage:l,percentage:c}))}function F({displayText:e,files:a,hasMaxFilesError:s,isResumable:l,onCancelUpload:r,onDeleteUpload:n,onResume:o,onPause:i,showThumbnails:c,maxFileCount:d}){if(a.length<1)return null;const{getMaxFilesErrorText:p}=e,m=p(d);return u.default.createElement(t.View,{className:"amplify-storagemanager--filelist"},a.map((a=>{const{file:t,status:s,progress:d,error:p,key:m,isImage:g,id:f,uploadTask:T}=a,S=t&&g?URL.createObjectURL(t):"",U=!l||d>0,C=s===E.UPLOADING;return u.default.createElement(D,{displayName:m,errorMessage:p,displayText:e,isImage:g,isUploading:C,isResumable:l,key:f,loaderIsDeterminate:U,onRemove:()=>{l&&(s===E.UPLOADING||s===E.PAUSED)&&T?r({id:f,uploadTask:T}):n({id:f})},onPause:()=>{T&&i({id:f,uploadTask:T})},onResume:()=>{T&&o({id:f,uploadTask:T})},progress:d,showThumbnails:c,size:null==t?void 0:t.size,status:s,thumbnailUrl:S})})),s&&u.default.createElement(t.Alert,{variation:"error",heading:m}))}function b({fileCount:e,remainingFilesCount:a,displayText:s,allUploadsSuccessful:l}){const{getFilesUploadedText:r,getRemainingFilesText:n}=s;return u.default.createElement(t.Text,{className:t.ComponentClassNames.StorageManagerPreviewerText},l?r(e):n(a))}function x({onFileChange:e,acceptedFileTypes:a,allowMultipleFiles:s,displayText:l}){const r=u.default.useRef(null),{browseFilesText:n}=l;return u.default.createElement(t.View,null,u.default.createElement(t.Button,{className:t.ComponentClassNames.StorageManagerDropZoneButton,onClick:()=>{r.current&&(r.current.click(),r.current.value="")},size:"small"},n),u.default.createElement(t.VisuallyHidden,null,u.default.createElement("input",{type:"file",tabIndex:-1,ref:r,onChange:e,multiple:s,accept:a.join(",")})))}var O;function N(e,a){switch(a.type){case O.ADD_FILES:{const{files:t}=a,s=t.map((e=>{const t=a.getFileErrorMessage(e);return{id:e.name,file:e,error:t,key:e.name,status:t?E.ERROR:E.QUEUED,isImage:e.type.startsWith("image/"),progress:-1}})),l=[...e.files,...s];return Object.assign(Object.assign({},e),{files:l})}case O.SET_STATUS_UPLOADING:{const{id:t,uploadTask:s}=a,{files:l}=e,r=l.reduce(((e,a)=>a.id===t?[...e,Object.assign(Object.assign({},a),{status:E.UPLOADING,progress:0,uploadTask:s||void 0})]:[...e,a]),[]);return Object.assign(Object.assign({},e),{files:r})}case O.SET_UPLOAD_PROGRESS:{const{id:t,progress:s}=a,{files:l}=e,r=l.reduce(((e,a)=>a.id===t?[...e,Object.assign(Object.assign({},a),{progress:s})]:[...e,a]),[]);return Object.assign(Object.assign({},e),{files:r})}case O.SET_STATUS:{const{id:t,status:s}=a,{files:l}=e,r=l.reduce(((e,a)=>a.id===t?[...e,Object.assign(Object.assign({},a),{status:s})]:[...e,a]),[]);return Object.assign(Object.assign({},e),{files:r})}case O.REMOVE_UPLOAD:{const{id:t}=a,{files:s}=e,l=s.reduce(((e,a)=>a.id===t?[...e]:[...e,a]),[]);return Object.assign(Object.assign({},e),{files:l})}}}!function(e){e.ADD_FILES="ADD_FILES",e.SET_STATUS="SET_STATUS",e.SET_STATUS_UPLOADING="SET_STATUS_UPLOADING",e.SET_UPLOAD_PROGRESS="SET_UPLOAD_PROGRESS",e.REMOVE_UPLOAD="REMOVE_UPLOAD"}(O||(O={}));const y=({id:e,status:a})=>({type:O.SET_STATUS,id:e,status:a});function P(e=[]){const[{files:a},t]=u.default.useReducer(N,{files:e.map((e=>Object.assign(Object.assign({},e),{id:e.key,key:e.key,status:E.UPLOADED})))});return{removeUpload:({id:e})=>{t((({id:e})=>({type:O.REMOVE_UPLOAD,id:e}))({id:e}))},setUploadPaused:({id:e})=>{t(y({id:e,status:E.PAUSED}))},setUploadProgress:({progress:e,id:a})=>{t((({id:e,progress:a})=>({type:O.SET_UPLOAD_PROGRESS,id:e,progress:a}))({id:a,progress:e}))},setUploadResumed:({id:e})=>{t(y({id:e,status:E.UPLOADING}))},setUploadSuccess:({id:e})=>{t(y({id:e,status:E.UPLOADED}))},setUploadingFile:({uploadTask:e,id:a})=>{t((({id:e,uploadTask:a})=>({type:O.SET_STATUS_UPLOADING,id:e,uploadTask:a}))({id:a,uploadTask:e}))},addFiles:({files:e,getFileErrorMessage:a})=>{t((({files:e,getFileErrorMessage:a})=>({type:O.ADD_FILES,files:e,getFileErrorMessage:a}))({files:e,getFileErrorMessage:a}))},files:a}}function v(e){var{file:t,fileName:s,level:l="private",progressCallback:r,errorCallback:o,completeCallback:i,isResumable:u=!1,provider:c}=e,d=n.__rest(e,["file","fileName","level","progressCallback","errorCallback","completeCallback","isResumable","provider"]);const p=t.type||"binary/octet-stream";return!0===u?a.Storage.put(s,t,Object.assign({level:l,resumable:!0,progressCallback:r,errorCallback:o,completeCallback:i,contentType:p,provider:c},d)):a.Storage.put(s,t,Object.assign({level:l,resumable:!1,progressCallback:r,contentType:p,provider:c},d)).then(i,o)}const k=new a.Logger("Storage.StorageManager");function M({acceptedFileTypes:a,accessLevel:s,defaultFiles:l,displayText:r,isResumable:n=!1,maxFileCount:o,maxFileSize:i,onUploadError:u,onUploadSuccess:d,onFileRemove:T,showThumbnails:S=!0,processFile:U,components:C,provider:D}){a&&s&&o||k.warn("FileUploader requires accessLevel, acceptedFileTypes and maxFileCount props");const O=Object.assign({Container:m,DropZone:f,FileList:F,FilePicker:x,FileListHeader:b},C),N=void 0===o||"number"==typeof o&&o>1,y=Object.assign(Object.assign({},g),r),{getFileSizeErrorText:M}=y,h=e=>p({file:e,maxFileSize:i,getFileSizeErrorText:M}),{addFiles:L,files:R,removeUpload:A,setUploadingFile:w,setUploadPaused:_,setUploadProgress:j,setUploadSuccess:I,setUploadResumed:B}=P(l),z=function({onChange:a}){const[t,s]=e.useState(!1);return{onDragStart:e=>{e.dataTransfer.clearData()},onDragEnter:e=>{e.preventDefault(),e.stopPropagation()},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),s(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="copy",s(!0)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),s(!1),a(e)},inDropZone:t}}({onChange:e=>{const{files:t}=e.dataTransfer;if(!t||0===t.length)return;const s=((e,a)=>e.filter((e=>{const t=e.name||"",s=(e.type||"").toLowerCase(),l=s.replace(/\/.*$/,"");return a.some((e=>{const a=e.trim().toLowerCase();return"."===a.charAt(0)?t.toLowerCase().endsWith(a):a.endsWith("/*")?l===a.replace(/\/.*$/,""):s===a}))})))(Array.from(t),a);L({files:s,getFileErrorMessage:h})}});!function({files:e,accessLevel:a,isResumable:t,setUploadProgress:s,setUploadingFile:l,setUploadSuccess:r,onUploadError:n,onUploadSuccess:o,maxFileCount:i,processFile:u,provider:d}){c.useEffect((()=>{const c=e.filter((e=>e.status===E.QUEUED));if(!(c.length>i))for(const{file:e,key:i,id:p}of c){const c=e=>{null==o||o(e),r({id:p})},m=e=>{const a=0===e.total?100:Math.floor(e.loaded/e.total*100);s({id:p,progress:a})},g=e=>{null==n||n(e)};if(e){const s="function"==typeof u?u({file:e,key:i}):{file:e,key:i};if(t){const e=v({file:s.file,fileName:s.key,isResumable:!0,level:a,completeCallback:c,progressCallback:m,errorCallback:g,provider:d});l({id:p,uploadTask:e})}else v({file:s.file,fileName:s.key,isResumable:!1,level:a,completeCallback:c,progressCallback:m,errorCallback:g,provider:d}),l({id:p})}}}),[e,a,t,s,l,n,o,i,r,u,d])}({accessLevel:s,files:R,isResumable:n,maxFileCount:o,onUploadError:u,onUploadSuccess:d,setUploadingFile:w,setUploadProgress:j,setUploadSuccess:I,processFile:U,provider:D});const G=0!==R.length&&R.every((e=>100===(null==e?void 0:e.progress))),$=R.filter((e=>e.progress<100)).length>o,V=R.filter((e=>(null==e?void 0:e.status)===E.UPLOADED)).length,Z=R.length-V,q=R.length>0;return c.createElement(O.Container,{className:`${t.ComponentClassNames.StorageManager} ${q?t.ComponentClassNames.StorageManagerPreviewer:""}`},c.createElement(O.DropZone,Object.assign({},z,{acceptedFileTypes:a,displayText:y}),c.createElement(O.FilePicker,{onFileChange:e=>{const{files:a}=e.target;a&&0!==a.length&&L({files:Array.from(a),getFileErrorMessage:h})},displayText:y,acceptedFileTypes:a,allowMultipleFiles:N})),q?c.createElement(O.FileListHeader,{allUploadsSuccessful:G,displayText:y,fileCount:R.length,remainingFilesCount:Z}):null,c.createElement(O.FileList,{displayText:y,files:R,isResumable:n,onCancelUpload:({id:e,uploadTask:a})=>{a.pause(),A({id:e})},onDeleteUpload:({id:e})=>{if(A({id:e}),"function"==typeof T){const a=R.find((a=>a.id===e));a&&T({key:a.key})}},onResume:({id:e,uploadTask:a})=>{a.resume(),B({id:e})},onPause:({id:e,uploadTask:a})=>{a.pause(),_({id:e})},showThumbnails:S,hasMaxFilesError:$,maxFileCount:o}))}M.Container=m,M.DropZone=f,M.FileList=F,M.FileListHeader=b,M.FilePicker=x,exports.StorageManager=M;
|