@raketa-builder/file-input 1.3.6 → 1.3.9
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/FileManager.js +274 -0
- package/dist/FilePicker/Dialog.js +68 -0
- package/{src → dist}/FilePicker/FileCategory.js +16 -35
- package/dist/FilePicker/FileInput.js +27 -0
- package/dist/FilePicker/FileList.js +194 -0
- package/dist/FilePicker/FileSearch.js +78 -0
- package/dist/FilePicker/UploadFilesButton.js +35 -0
- package/dist/FilePicker/UploadProgress.js +78 -0
- package/dist/FilePicker/index.js +116 -0
- package/dist/FilePicker/stateManagement.js +220 -0
- package/{src → dist}/FilePicker/utils.js +5 -4
- package/dist/chunk-6FNC3XMI.js +41 -0
- package/dist/index.js +3 -1265
- package/package.json +18 -4
- package/biome.json +0 -3
- package/src/FileManager.js +0 -283
- package/src/FilePicker/Dialog.js +0 -73
- package/src/FilePicker/FileInput.js +0 -37
- package/src/FilePicker/FileList.js +0 -175
- package/src/FilePicker/FileSearch.js +0 -98
- package/src/FilePicker/UploadFilesButton.js +0 -31
- package/src/FilePicker/UploadProgress.js +0 -84
- package/src/FilePicker/index.js +0 -125
- package/src/FilePicker/stateManagement.js +0 -276
- package/src/index.js +0 -4
- package/src/styles.css +0 -84
- package/tsconfig.json +0 -5
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { __async } from './chunk-6FNC3XMI.js';
|
|
2
|
+
|
|
3
|
+
const DOCUMENTS_QUERY = `
|
|
4
|
+
query($input: DocumentsInput!) {
|
|
5
|
+
documents(input: $input) {
|
|
6
|
+
list {
|
|
7
|
+
id
|
|
8
|
+
filename
|
|
9
|
+
mimeType
|
|
10
|
+
size
|
|
11
|
+
uploadStatus
|
|
12
|
+
url
|
|
13
|
+
createdAt
|
|
14
|
+
}
|
|
15
|
+
pagination {
|
|
16
|
+
cursor
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const CREATE_DOCUMENT_MUTATION = `
|
|
22
|
+
mutation($input: CreateDocumentInput!) {
|
|
23
|
+
createDocument(input: $input) {
|
|
24
|
+
document {
|
|
25
|
+
id
|
|
26
|
+
filename
|
|
27
|
+
mimeType
|
|
28
|
+
size
|
|
29
|
+
uploadStatus
|
|
30
|
+
url
|
|
31
|
+
createdAt
|
|
32
|
+
uploadUrl
|
|
33
|
+
}
|
|
34
|
+
errors {
|
|
35
|
+
key
|
|
36
|
+
message
|
|
37
|
+
codes {
|
|
38
|
+
key
|
|
39
|
+
placeholders
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
const NOTIFY_UPLOADED_DOCUMENT_MUTATION = `
|
|
46
|
+
mutation($input: NotifyUploadedDocumentInput!) {
|
|
47
|
+
notifyUploadedDocument(input: $input) {
|
|
48
|
+
document {
|
|
49
|
+
id
|
|
50
|
+
filename
|
|
51
|
+
mimeType
|
|
52
|
+
size
|
|
53
|
+
uploadStatus
|
|
54
|
+
url
|
|
55
|
+
createdAt
|
|
56
|
+
}
|
|
57
|
+
errors {
|
|
58
|
+
key
|
|
59
|
+
message
|
|
60
|
+
codes {
|
|
61
|
+
key
|
|
62
|
+
placeholders
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const DELETE_DOCUMENT_MUTATION = `
|
|
69
|
+
mutation($input: DeleteDocumentInput!) {
|
|
70
|
+
deleteDocument(input: $input) {
|
|
71
|
+
document {
|
|
72
|
+
id
|
|
73
|
+
filename
|
|
74
|
+
mimeType
|
|
75
|
+
size
|
|
76
|
+
uploadStatus
|
|
77
|
+
url
|
|
78
|
+
createdAt
|
|
79
|
+
}
|
|
80
|
+
errors {
|
|
81
|
+
key
|
|
82
|
+
message
|
|
83
|
+
codes {
|
|
84
|
+
key
|
|
85
|
+
placeholders
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
function uploadFile(file, document, progressCallback) {
|
|
92
|
+
return __async(this, null, function* () {
|
|
93
|
+
const xhr = new XMLHttpRequest();
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
96
|
+
if (event.lengthComputable) {
|
|
97
|
+
progressCallback({
|
|
98
|
+
type: "progress",
|
|
99
|
+
payload: {
|
|
100
|
+
loaded: event.loaded,
|
|
101
|
+
total: event.total
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
xhr.addEventListener("loadend", (event) => {
|
|
107
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
108
|
+
progressCallback({
|
|
109
|
+
type: "uploaded",
|
|
110
|
+
payload: {}
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
progressCallback({
|
|
114
|
+
type: "errored",
|
|
115
|
+
payload: {
|
|
116
|
+
errors: `ReadyState: ${xhr.readyState} - ${xhr.status} - ${event.type}: ${event.loaded} bytes transferred.`
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
resolve(xhr.readyState === 4 && xhr.status === 200);
|
|
121
|
+
});
|
|
122
|
+
xhr.withCredentials = false;
|
|
123
|
+
xhr.open("PUT", document.uploadUrl, true);
|
|
124
|
+
xhr.setRequestHeader("content-type", file.type);
|
|
125
|
+
const reader = new FileReader();
|
|
126
|
+
reader.onload = (event) => {
|
|
127
|
+
xhr.send(event.target.result);
|
|
128
|
+
};
|
|
129
|
+
reader.readAsArrayBuffer(file);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
class FileManager {
|
|
134
|
+
constructor(url, headers) {
|
|
135
|
+
this.url = url;
|
|
136
|
+
this.headers = headers;
|
|
137
|
+
}
|
|
138
|
+
graphQLRequest(query, variables) {
|
|
139
|
+
return __async(this, null, function* () {
|
|
140
|
+
return fetch(this.url, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: Object.assign(
|
|
143
|
+
{ "Content-Type": "application/json" },
|
|
144
|
+
this.headers
|
|
145
|
+
),
|
|
146
|
+
body: JSON.stringify({
|
|
147
|
+
query,
|
|
148
|
+
variables
|
|
149
|
+
})
|
|
150
|
+
}).then((res) => res.json());
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
buildFilters(params) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
const filters = {
|
|
156
|
+
uploadStatus: "COMPLETED"
|
|
157
|
+
};
|
|
158
|
+
if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
|
|
159
|
+
filters.mimeTypes = params.mimeTypes;
|
|
160
|
+
}
|
|
161
|
+
if (((_b = params == null ? void 0 : params.excludeMimeTypes) == null ? void 0 : _b.length) > 0) {
|
|
162
|
+
filters.excludeMimeTypes = params.excludeMimeTypes;
|
|
163
|
+
}
|
|
164
|
+
if (params == null ? void 0 : params.keyword) {
|
|
165
|
+
filters.keyword = params.keyword;
|
|
166
|
+
}
|
|
167
|
+
return filters;
|
|
168
|
+
}
|
|
169
|
+
buildVariables(params) {
|
|
170
|
+
const variables = {
|
|
171
|
+
input: {
|
|
172
|
+
filters: this.buildFilters(params)
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
if (params.nextCursor) {
|
|
176
|
+
variables.input.pagination = { cursor: params.nextCursor };
|
|
177
|
+
}
|
|
178
|
+
return variables;
|
|
179
|
+
}
|
|
180
|
+
all() {
|
|
181
|
+
return __async(this, arguments, function* (params = {}) {
|
|
182
|
+
return this.graphQLRequest(
|
|
183
|
+
DOCUMENTS_QUERY,
|
|
184
|
+
this.buildVariables(params)
|
|
185
|
+
).then((d) => {
|
|
186
|
+
return (d == null ? void 0 : d.data.documents) || {};
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
createAndUpload(fileInfo, progressCallback) {
|
|
191
|
+
return __async(this, null, function* () {
|
|
192
|
+
const { file, id } = fileInfo;
|
|
193
|
+
const { document, errors } = yield this.create({
|
|
194
|
+
filename: file.name,
|
|
195
|
+
mime_type: file.type,
|
|
196
|
+
size: file.size
|
|
197
|
+
});
|
|
198
|
+
if (errors) {
|
|
199
|
+
progressCallback(id, {
|
|
200
|
+
type: "errored",
|
|
201
|
+
payload: {
|
|
202
|
+
errors
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const result = yield uploadFile(
|
|
208
|
+
file,
|
|
209
|
+
document,
|
|
210
|
+
(state) => progressCallback(id, state)
|
|
211
|
+
);
|
|
212
|
+
if (result) {
|
|
213
|
+
const notify = yield this.notifyUploaded(document.id);
|
|
214
|
+
if (notify.errors) {
|
|
215
|
+
progressCallback(id, {
|
|
216
|
+
type: "errored",
|
|
217
|
+
payload: {
|
|
218
|
+
errors
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
progressCallback(id, {
|
|
224
|
+
type: "completed",
|
|
225
|
+
payload: {
|
|
226
|
+
document: notify.document
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
create(params) {
|
|
233
|
+
return __async(this, null, function* () {
|
|
234
|
+
return this.graphQLRequest(CREATE_DOCUMENT_MUTATION, {
|
|
235
|
+
input: {
|
|
236
|
+
document: {
|
|
237
|
+
filename: params.filename,
|
|
238
|
+
mime_type: params.mime_type,
|
|
239
|
+
size: params.size
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}).then((d) => {
|
|
243
|
+
var _a;
|
|
244
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.createDocument) || {};
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
notifyUploaded(id) {
|
|
249
|
+
return __async(this, null, function* () {
|
|
250
|
+
return this.graphQLRequest(NOTIFY_UPLOADED_DOCUMENT_MUTATION, {
|
|
251
|
+
input: {
|
|
252
|
+
id
|
|
253
|
+
}
|
|
254
|
+
}).then((d) => {
|
|
255
|
+
var _a;
|
|
256
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.notifyUploadedDocument) || {};
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
destroy(id) {
|
|
261
|
+
return __async(this, null, function* () {
|
|
262
|
+
return this.graphQLRequest(DELETE_DOCUMENT_MUTATION, {
|
|
263
|
+
input: {
|
|
264
|
+
id
|
|
265
|
+
}
|
|
266
|
+
}).then((d) => {
|
|
267
|
+
var _a;
|
|
268
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.deleteDocument) || {};
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { FileManager as default };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __spreadProps, __spreadValues } from '../chunk-6FNC3XMI.js';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useDropzone } from 'react-dropzone';
|
|
5
|
+
import { Modal, Button, cn } from '@raketa-builder/ui';
|
|
6
|
+
|
|
7
|
+
const DropZone = ({ children, onDrop }) => {
|
|
8
|
+
const onFilesDrop = useCallback(
|
|
9
|
+
(acceptedFiles) => {
|
|
10
|
+
onDrop(acceptedFiles);
|
|
11
|
+
},
|
|
12
|
+
[onDrop]
|
|
13
|
+
);
|
|
14
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
15
|
+
onDropAccepted: onFilesDrop,
|
|
16
|
+
noClick: true
|
|
17
|
+
});
|
|
18
|
+
return /* @__PURE__ */ jsxs(
|
|
19
|
+
"div",
|
|
20
|
+
__spreadProps(__spreadValues({
|
|
21
|
+
className: cn(
|
|
22
|
+
"r-reset",
|
|
23
|
+
"r-dropzone-modal",
|
|
24
|
+
isDragActive ? "r-dropzone-modal-active" : ""
|
|
25
|
+
)
|
|
26
|
+
}, getRootProps()), {
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx("input", __spreadValues({}, getInputProps())),
|
|
29
|
+
/* @__PURE__ */ jsx("div", { children: isDragActive && /* @__PURE__ */ jsx("strong", { className: "r-fs-large", children: "Drop here" }) }),
|
|
30
|
+
!isDragActive && children
|
|
31
|
+
]
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
const Dialog = ({
|
|
36
|
+
disablePrimary = false,
|
|
37
|
+
onClose,
|
|
38
|
+
onPrimary,
|
|
39
|
+
onDrop,
|
|
40
|
+
children
|
|
41
|
+
}) => {
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
Modal,
|
|
44
|
+
{
|
|
45
|
+
title: "Files",
|
|
46
|
+
onClose,
|
|
47
|
+
onDrop,
|
|
48
|
+
customWrapper: DropZone,
|
|
49
|
+
FooterContent: () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
/* @__PURE__ */ jsx(
|
|
51
|
+
Button,
|
|
52
|
+
{
|
|
53
|
+
type: "button",
|
|
54
|
+
variant: "primary",
|
|
55
|
+
disabled: disablePrimary,
|
|
56
|
+
onClick: onPrimary,
|
|
57
|
+
children: "Select"
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: onClose, children: "Cancel" })
|
|
61
|
+
] }),
|
|
62
|
+
children
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
var Dialog_default = Dialog;
|
|
67
|
+
|
|
68
|
+
export { Dialog_default as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import '../chunk-6FNC3XMI.js';
|
|
2
2
|
|
|
3
|
+
const VIDEO = ["video/3gpp", "video/3gpp2", "video/mp4", "video/webm"];
|
|
3
4
|
const AUDIO = [
|
|
4
5
|
"audio/webm",
|
|
5
6
|
"audio/wav",
|
|
@@ -10,9 +11,8 @@ const AUDIO = [
|
|
|
10
11
|
"audio/ogg",
|
|
11
12
|
"audio/3gpp",
|
|
12
13
|
"audio/3gpp2",
|
|
13
|
-
"audio/m4a"
|
|
14
|
+
"audio/m4a"
|
|
14
15
|
];
|
|
15
|
-
|
|
16
16
|
const DOCUMENT = [
|
|
17
17
|
"application/pdf",
|
|
18
18
|
"application/msword",
|
|
@@ -28,9 +28,8 @@ const DOCUMENT = [
|
|
|
28
28
|
"text/csv",
|
|
29
29
|
"application/vnd.apple.pages",
|
|
30
30
|
"application/vnd.apple.numbers",
|
|
31
|
-
"application/vnd.apple.keynote"
|
|
31
|
+
"application/vnd.apple.keynote"
|
|
32
32
|
];
|
|
33
|
-
|
|
34
33
|
const IMAGE = [
|
|
35
34
|
"image/png",
|
|
36
35
|
"image/x-png",
|
|
@@ -42,89 +41,71 @@ const IMAGE = [
|
|
|
42
41
|
"image/webp",
|
|
43
42
|
"application/postscript",
|
|
44
43
|
"mage/heic",
|
|
45
|
-
"mage/heic-sequence"
|
|
44
|
+
"mage/heic-sequence"
|
|
46
45
|
];
|
|
47
|
-
|
|
48
46
|
const ARCHIVE = [
|
|
49
47
|
"application/zip",
|
|
50
48
|
"application/gzip",
|
|
51
49
|
"application/x-gtar",
|
|
52
50
|
"application/x-tar",
|
|
53
51
|
"application/x-rar-compressed",
|
|
54
|
-
"application/x-7z-compressed"
|
|
52
|
+
"application/x-7z-compressed"
|
|
55
53
|
];
|
|
56
|
-
|
|
57
|
-
const MIME_TYPES = IMAGE.concat(VIDEO)
|
|
58
|
-
.concat(DOCUMENT)
|
|
59
|
-
.concat(AUDIO)
|
|
60
|
-
.concat(ARCHIVE);
|
|
61
|
-
|
|
54
|
+
const MIME_TYPES = IMAGE.concat(VIDEO).concat(DOCUMENT).concat(AUDIO).concat(ARCHIVE);
|
|
62
55
|
const MAPPING = {
|
|
63
56
|
video: VIDEO,
|
|
64
57
|
document: DOCUMENT,
|
|
65
58
|
image: IMAGE,
|
|
66
59
|
audio: AUDIO,
|
|
67
60
|
archive: ARCHIVE,
|
|
68
|
-
other: []
|
|
61
|
+
other: []
|
|
69
62
|
};
|
|
70
|
-
|
|
71
63
|
const FILE_CATEGORIES = {
|
|
72
64
|
document: "Document",
|
|
73
65
|
archive: "Archive",
|
|
74
66
|
image: "Image",
|
|
75
67
|
video: "Video",
|
|
76
68
|
audio: "Audio",
|
|
77
|
-
other: "Other"
|
|
69
|
+
other: "Other"
|
|
78
70
|
};
|
|
79
|
-
|
|
80
|
-
export function toMimeTypes(fileCategory) {
|
|
71
|
+
function toMimeTypes(fileCategory) {
|
|
81
72
|
return MAPPING[fileCategory] || [];
|
|
82
73
|
}
|
|
83
|
-
|
|
84
|
-
export function toExcludedMimeTypes(fileCategory) {
|
|
74
|
+
function toExcludedMimeTypes(fileCategory) {
|
|
85
75
|
if (fileCategory === "other") {
|
|
86
76
|
return MIME_TYPES;
|
|
87
77
|
}
|
|
88
|
-
|
|
89
78
|
return [];
|
|
90
79
|
}
|
|
91
|
-
|
|
92
|
-
export function toFileCategory(mimeType, format = "robot") {
|
|
80
|
+
function toFileCategory(mimeType, format = "robot") {
|
|
93
81
|
let fileCategory = null;
|
|
94
|
-
|
|
95
82
|
Object.keys(FILE_CATEGORIES).forEach((key) => {
|
|
96
83
|
if (fileCategory) {
|
|
97
84
|
return;
|
|
98
85
|
}
|
|
99
|
-
|
|
100
86
|
if (MAPPING[key].find((mt) => mt === mimeType)) {
|
|
101
87
|
fileCategory = key;
|
|
102
88
|
}
|
|
103
89
|
});
|
|
104
|
-
|
|
105
90
|
if (!fileCategory) {
|
|
106
91
|
fileCategory = "other";
|
|
107
92
|
}
|
|
108
|
-
|
|
109
93
|
if (format === "human") {
|
|
110
94
|
return FILE_CATEGORIES[fileCategory] || fileCategory;
|
|
111
95
|
}
|
|
112
|
-
|
|
113
96
|
return fileCategory;
|
|
114
97
|
}
|
|
115
|
-
|
|
116
|
-
export function fileCategoriesOptions() {
|
|
98
|
+
function fileCategoriesOptions() {
|
|
117
99
|
return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
|
|
118
100
|
}
|
|
119
|
-
|
|
120
|
-
export function sanitizeFileCategory(fileCategory) {
|
|
101
|
+
function sanitizeFileCategory(fileCategory) {
|
|
121
102
|
if (fileCategory === "other") {
|
|
122
103
|
return null;
|
|
123
104
|
}
|
|
124
|
-
|
|
125
105
|
if (Object.keys(FILE_CATEGORIES).includes(fileCategory)) {
|
|
126
106
|
return fileCategory;
|
|
127
107
|
}
|
|
128
|
-
|
|
129
108
|
return null;
|
|
130
109
|
}
|
|
110
|
+
|
|
111
|
+
export { fileCategoriesOptions, sanitizeFileCategory, toExcludedMimeTypes, toFileCategory, toMimeTypes };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import '../chunk-6FNC3XMI.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { FormGroup, Label, Stack, Input, Button, Hint } from '@raketa-builder/ui';
|
|
5
|
+
|
|
6
|
+
const FileInput = ({ value, label, hint, onBrowse, onClear }) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const filename = (_a = value == null ? void 0 : value.document) == null ? void 0 : _a.filename;
|
|
9
|
+
return /* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
10
|
+
label && /* @__PURE__ */ jsx(Label, { children: label }),
|
|
11
|
+
/* @__PURE__ */ jsxs(Stack, { className: "r-stack-justify-center", style: { gap: "0.5rem" }, children: [
|
|
12
|
+
/* @__PURE__ */ jsx(
|
|
13
|
+
Input,
|
|
14
|
+
{
|
|
15
|
+
disabled: true,
|
|
16
|
+
placeholder: filename ? filename : "No file selected"
|
|
17
|
+
}
|
|
18
|
+
),
|
|
19
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "primary", onClick: onBrowse, children: "Browse..." }),
|
|
20
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: () => onClear(), children: "Clear" })
|
|
21
|
+
] }),
|
|
22
|
+
hint && /* @__PURE__ */ jsx(Hint, { children: hint })
|
|
23
|
+
] });
|
|
24
|
+
};
|
|
25
|
+
var FileInput_default = FileInput;
|
|
26
|
+
|
|
27
|
+
export { FileInput_default as default };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { __spreadProps, __spreadValues } from '../chunk-6FNC3XMI.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import { cn, Stack, Input, Button } from '@raketa-builder/ui';
|
|
5
|
+
import { fileSizeFormatter } from './utils';
|
|
6
|
+
import { toFileCategory } from './FileCategory';
|
|
7
|
+
|
|
8
|
+
const DeleteIcon = (props) => {
|
|
9
|
+
return /* @__PURE__ */ jsxs(
|
|
10
|
+
"svg",
|
|
11
|
+
__spreadProps(__spreadValues({
|
|
12
|
+
width: "24",
|
|
13
|
+
height: "25",
|
|
14
|
+
viewBox: "0 0 24 25",
|
|
15
|
+
fill: "none",
|
|
16
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
17
|
+
className: "r-file-input-delete-icon"
|
|
18
|
+
}, props), {
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ jsx("title", { children: "Delete" }),
|
|
21
|
+
/* @__PURE__ */ jsx(
|
|
22
|
+
"path",
|
|
23
|
+
{
|
|
24
|
+
d: "M3 6.5H5H21",
|
|
25
|
+
stroke: "currentColor",
|
|
26
|
+
strokeWidth: "2",
|
|
27
|
+
strokeLinecap: "round",
|
|
28
|
+
strokeLinejoin: "round"
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
"path",
|
|
33
|
+
{
|
|
34
|
+
d: "M19 6.5V20.5C19 21.0304 18.7893 21.5391 18.4142 21.9142C18.0391 22.2893 17.5304 22.5 17 22.5H7C6.46957 22.5 5.96086 22.2893 5.58579 21.9142C5.21071 21.5391 5 21.0304 5 20.5V6.5M8 6.5V4.5C8 3.96957 8.21071 3.46086 8.58579 3.08579C8.96086 2.71071 9.46957 2.5 10 2.5H14C14.5304 2.5 15.0391 2.71071 15.4142 3.08579C15.7893 3.46086 16 3.96957 16 4.5V6.5",
|
|
35
|
+
stroke: "currentColor",
|
|
36
|
+
strokeWidth: "2",
|
|
37
|
+
strokeLinecap: "round",
|
|
38
|
+
strokeLinejoin: "round"
|
|
39
|
+
}
|
|
40
|
+
),
|
|
41
|
+
/* @__PURE__ */ jsx(
|
|
42
|
+
"path",
|
|
43
|
+
{
|
|
44
|
+
d: "M10 11.5V17.5",
|
|
45
|
+
stroke: "currentColor",
|
|
46
|
+
strokeWidth: "2",
|
|
47
|
+
strokeLinecap: "round",
|
|
48
|
+
strokeLinejoin: "round"
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
d: "M14 11.5V17.5",
|
|
55
|
+
stroke: "currentColor",
|
|
56
|
+
strokeWidth: "2",
|
|
57
|
+
strokeLinecap: "round",
|
|
58
|
+
strokeLinejoin: "round"
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
const CopyIcon = (props) => /* @__PURE__ */ jsxs(
|
|
66
|
+
"svg",
|
|
67
|
+
__spreadProps(__spreadValues({
|
|
68
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
69
|
+
width: "24",
|
|
70
|
+
height: "25",
|
|
71
|
+
viewBox: "0 0 24 25",
|
|
72
|
+
fill: "none",
|
|
73
|
+
className: "r-file-input-copy-icon"
|
|
74
|
+
}, props), {
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsx("title", { children: "Copy file URL" }),
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"path",
|
|
79
|
+
{
|
|
80
|
+
d: "M10 13.5C10.4295 14.0741 10.9774 14.5491 11.6066 14.8929C12.2357 15.2367 12.9315 15.4411 13.6467 15.4923C14.3618 15.5435 15.0796 15.4403 15.7513 15.1897C16.4231 14.9392 17.0331 14.547 17.54 14.04L20.54 11.04C21.4508 10.097 21.9548 8.83394 21.9434 7.52296C21.932 6.21198 21.4061 4.95791 20.4791 4.03087C19.5521 3.10383 18.298 2.57799 16.987 2.5666C15.676 2.5552 14.413 3.05918 13.47 3.96997L11.75 5.67997",
|
|
81
|
+
stroke: "black",
|
|
82
|
+
strokeWidth: "2",
|
|
83
|
+
strokeLinecap: "round",
|
|
84
|
+
strokeLinejoin: "round"
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
/* @__PURE__ */ jsx(
|
|
88
|
+
"path",
|
|
89
|
+
{
|
|
90
|
+
d: "M14 11.5C13.5705 10.9259 13.0226 10.4508 12.3934 10.107C11.7642 9.76328 11.0684 9.55886 10.3533 9.50765C9.63816 9.45643 8.92037 9.55961 8.24861 9.8102C7.57685 10.0608 6.96684 10.4529 6.45996 10.96L3.45996 13.96C2.54917 14.903 2.04519 16.166 2.05659 17.477C2.06798 18.788 2.59382 20.042 3.52086 20.9691C4.4479 21.8961 5.70197 22.422 7.01295 22.4334C8.32393 22.4447 9.58694 21.9408 10.53 21.03L12.24 19.32",
|
|
91
|
+
stroke: "black",
|
|
92
|
+
strokeWidth: "2",
|
|
93
|
+
strokeLinecap: "round",
|
|
94
|
+
strokeLinejoin: "round"
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
]
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
const formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
|
|
101
|
+
year: "numeric",
|
|
102
|
+
month: "long",
|
|
103
|
+
day: "numeric",
|
|
104
|
+
hour: "numeric",
|
|
105
|
+
minute: "numeric",
|
|
106
|
+
second: "numeric"
|
|
107
|
+
});
|
|
108
|
+
const FileList = ({
|
|
109
|
+
files,
|
|
110
|
+
fetching,
|
|
111
|
+
selected,
|
|
112
|
+
allowDelete,
|
|
113
|
+
onMore,
|
|
114
|
+
onSelect,
|
|
115
|
+
onDelete
|
|
116
|
+
}) => {
|
|
117
|
+
const showLoadMore = !fetching && onMore;
|
|
118
|
+
return /* @__PURE__ */ jsxs("div", { className: "r-reset", children: [
|
|
119
|
+
/* @__PURE__ */ jsxs("table", { className: "r-table", children: [
|
|
120
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
121
|
+
/* @__PURE__ */ jsx("th", { children: "Name" }),
|
|
122
|
+
/* @__PURE__ */ jsx("th", { children: "Type" }),
|
|
123
|
+
/* @__PURE__ */ jsx("th", { children: "Size" }),
|
|
124
|
+
/* @__PURE__ */ jsx("th", { children: "Uploaded" })
|
|
125
|
+
] }) }),
|
|
126
|
+
/* @__PURE__ */ jsx("tbody", { children: files.map((file) => /* @__PURE__ */ jsxs(
|
|
127
|
+
"tr",
|
|
128
|
+
{
|
|
129
|
+
className: cn(
|
|
130
|
+
"r-file-input-file-row",
|
|
131
|
+
(selected == null ? void 0 : selected.id) === file.id ? "r-file-input-file-row-active" : ""
|
|
132
|
+
),
|
|
133
|
+
onClick: () => onSelect(file.id),
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
"td",
|
|
137
|
+
{
|
|
138
|
+
style: {
|
|
139
|
+
width: "50%"
|
|
140
|
+
},
|
|
141
|
+
children: /* @__PURE__ */ jsxs(
|
|
142
|
+
Stack,
|
|
143
|
+
{
|
|
144
|
+
className: "r-stack-align-center",
|
|
145
|
+
style: { gap: "0.5rem" },
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ jsx(
|
|
148
|
+
Input,
|
|
149
|
+
{
|
|
150
|
+
type: "radio",
|
|
151
|
+
checked: (selected == null ? void 0 : selected.id) === file.id,
|
|
152
|
+
readOnly: true
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
/* @__PURE__ */ jsx("div", { children: decodeURI(file.filename) }),
|
|
156
|
+
/* @__PURE__ */ jsx(
|
|
157
|
+
CopyIcon,
|
|
158
|
+
{
|
|
159
|
+
onClick: (e) => {
|
|
160
|
+
e.stopPropagation();
|
|
161
|
+
navigator.clipboard.writeText(file.url);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
allowDelete && /* @__PURE__ */ jsx(
|
|
166
|
+
DeleteIcon,
|
|
167
|
+
{
|
|
168
|
+
onClick: (event) => {
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
if (confirm("Are you sure?")) {
|
|
171
|
+
onDelete(file.id);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
/* @__PURE__ */ jsx("td", { children: toFileCategory(file.mimeType, "human") }),
|
|
182
|
+
/* @__PURE__ */ jsx("td", { children: fileSizeFormatter(file.size) }),
|
|
183
|
+
/* @__PURE__ */ jsx("td", { children: formatDate(file.createdAt) })
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
file.id
|
|
187
|
+
)) })
|
|
188
|
+
] }),
|
|
189
|
+
showLoadMore && /* @__PURE__ */ jsx(Button, { variant: "secondary", disabled: fetching, onClick: onMore, children: "Load more" })
|
|
190
|
+
] });
|
|
191
|
+
};
|
|
192
|
+
var FileList_default = FileList;
|
|
193
|
+
|
|
194
|
+
export { FileList_default as default };
|