@raketa-builder/file-input 1.3.8 → 1.3.10
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
package/package.json
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/file-input",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
5
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"import": "./dist/*.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
6
20
|
"license": "MIT",
|
|
7
21
|
"scripts": {
|
|
8
|
-
"build": "tsup
|
|
9
|
-
"dev": "tsup
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
10
24
|
"format": "prettier --write .",
|
|
11
25
|
"lint": "biome lint --max-diagnostics=5000 ."
|
|
12
26
|
},
|
|
@@ -16,7 +30,7 @@
|
|
|
16
30
|
},
|
|
17
31
|
"dependencies": {
|
|
18
32
|
"react-dropzone": "14.3.8",
|
|
19
|
-
"@raketa-builder/ui": "1.3.
|
|
33
|
+
"@raketa-builder/ui": "1.3.10"
|
|
20
34
|
},
|
|
21
35
|
"devDependencies": {
|
|
22
36
|
"@biomejs/biome": "1.9.4",
|
package/biome.json
DELETED
package/src/FileManager.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
const DOCUMENTS_QUERY = `
|
|
2
|
-
query($input: DocumentsInput!) {
|
|
3
|
-
documents(input: $input) {
|
|
4
|
-
list {
|
|
5
|
-
id
|
|
6
|
-
filename
|
|
7
|
-
mimeType
|
|
8
|
-
size
|
|
9
|
-
uploadStatus
|
|
10
|
-
url
|
|
11
|
-
createdAt
|
|
12
|
-
}
|
|
13
|
-
pagination {
|
|
14
|
-
cursor
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
const CREATE_DOCUMENT_MUTATION = `
|
|
21
|
-
mutation($input: CreateDocumentInput!) {
|
|
22
|
-
createDocument(input: $input) {
|
|
23
|
-
document {
|
|
24
|
-
id
|
|
25
|
-
filename
|
|
26
|
-
mimeType
|
|
27
|
-
size
|
|
28
|
-
uploadStatus
|
|
29
|
-
url
|
|
30
|
-
createdAt
|
|
31
|
-
uploadUrl
|
|
32
|
-
}
|
|
33
|
-
errors {
|
|
34
|
-
key
|
|
35
|
-
message
|
|
36
|
-
codes {
|
|
37
|
-
key
|
|
38
|
-
placeholders
|
|
39
|
-
}
|
|
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
|
-
|
|
69
|
-
const DELETE_DOCUMENT_MUTATION = `
|
|
70
|
-
mutation($input: DeleteDocumentInput!) {
|
|
71
|
-
deleteDocument(input: $input) {
|
|
72
|
-
document {
|
|
73
|
-
id
|
|
74
|
-
filename
|
|
75
|
-
mimeType
|
|
76
|
-
size
|
|
77
|
-
uploadStatus
|
|
78
|
-
url
|
|
79
|
-
createdAt
|
|
80
|
-
}
|
|
81
|
-
errors {
|
|
82
|
-
key
|
|
83
|
-
message
|
|
84
|
-
codes {
|
|
85
|
-
key
|
|
86
|
-
placeholders
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
`;
|
|
92
|
-
|
|
93
|
-
async function uploadFile(file, document, progressCallback) {
|
|
94
|
-
const xhr = new XMLHttpRequest();
|
|
95
|
-
|
|
96
|
-
return new Promise((resolve) => {
|
|
97
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
98
|
-
if (event.lengthComputable) {
|
|
99
|
-
progressCallback({
|
|
100
|
-
type: "progress",
|
|
101
|
-
payload: {
|
|
102
|
-
loaded: event.loaded,
|
|
103
|
-
total: event.total,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
xhr.addEventListener("loadend", (event) => {
|
|
110
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
|
|
111
|
-
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
112
|
-
progressCallback({
|
|
113
|
-
type: "uploaded",
|
|
114
|
-
payload: {},
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
progressCallback({
|
|
118
|
-
type: "errored",
|
|
119
|
-
payload: {
|
|
120
|
-
errors: `ReadyState: ${xhr.readyState} - ${xhr.status} - ${event.type}: ${event.loaded} bytes transferred.`,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
resolve(xhr.readyState === 4 && xhr.status === 200);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
xhr.withCredentials = false;
|
|
129
|
-
xhr.open("PUT", document.uploadUrl, true);
|
|
130
|
-
xhr.setRequestHeader("content-type", file.type);
|
|
131
|
-
|
|
132
|
-
// Read the file as ArrayBuffer and send it!
|
|
133
|
-
const reader = new FileReader();
|
|
134
|
-
reader.onload = (event) => {
|
|
135
|
-
xhr.send(event.target.result);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
reader.readAsArrayBuffer(file);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export default class FileManager {
|
|
143
|
-
constructor(url, headers) {
|
|
144
|
-
this.url = url;
|
|
145
|
-
this.headers = headers;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async graphQLRequest(query, variables) {
|
|
149
|
-
return fetch(this.url, {
|
|
150
|
-
method: "POST",
|
|
151
|
-
headers: Object.assign(
|
|
152
|
-
{ "Content-Type": "application/json" },
|
|
153
|
-
this.headers
|
|
154
|
-
),
|
|
155
|
-
body: JSON.stringify({
|
|
156
|
-
query: query,
|
|
157
|
-
variables: variables,
|
|
158
|
-
}),
|
|
159
|
-
}).then((res) => res.json());
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
buildFilters(params) {
|
|
163
|
-
const filters = {
|
|
164
|
-
uploadStatus: "COMPLETED",
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
if (params?.mimeTypes?.length > 0) {
|
|
168
|
-
filters.mimeTypes = params.mimeTypes;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (params?.excludeMimeTypes?.length > 0) {
|
|
172
|
-
filters.excludeMimeTypes = params.excludeMimeTypes;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (params?.keyword) {
|
|
176
|
-
filters.keyword = params.keyword;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return filters;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
buildVariables(params) {
|
|
183
|
-
const variables = {
|
|
184
|
-
input: {
|
|
185
|
-
filters: this.buildFilters(params),
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
if (params.nextCursor) {
|
|
190
|
-
variables.input.pagination = { cursor: params.nextCursor };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return variables;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async all(params = {}) {
|
|
197
|
-
return this.graphQLRequest(
|
|
198
|
-
DOCUMENTS_QUERY,
|
|
199
|
-
this.buildVariables(params)
|
|
200
|
-
).then((d) => {
|
|
201
|
-
return d?.data.documents || {};
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async createAndUpload(fileInfo, progressCallback) {
|
|
206
|
-
const { file, id } = fileInfo;
|
|
207
|
-
|
|
208
|
-
const { document, errors } = await this.create({
|
|
209
|
-
filename: file.name,
|
|
210
|
-
mime_type: file.type,
|
|
211
|
-
size: file.size,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
if (errors) {
|
|
215
|
-
progressCallback(id, {
|
|
216
|
-
type: "errored",
|
|
217
|
-
payload: {
|
|
218
|
-
errors,
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const result = await uploadFile(file, document, (state) =>
|
|
225
|
-
progressCallback(id, state)
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
if (result) {
|
|
229
|
-
const notify = await this.notifyUploaded(document.id);
|
|
230
|
-
|
|
231
|
-
if (notify.errors) {
|
|
232
|
-
progressCallback(id, {
|
|
233
|
-
type: "errored",
|
|
234
|
-
payload: {
|
|
235
|
-
errors,
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
progressCallback(id, {
|
|
242
|
-
type: "completed",
|
|
243
|
-
payload: {
|
|
244
|
-
document: notify.document,
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async create(params) {
|
|
251
|
-
return this.graphQLRequest(CREATE_DOCUMENT_MUTATION, {
|
|
252
|
-
input: {
|
|
253
|
-
document: {
|
|
254
|
-
filename: params.filename,
|
|
255
|
-
mime_type: params.mime_type,
|
|
256
|
-
size: params.size,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
}).then((d) => {
|
|
260
|
-
return d?.data?.createDocument || {};
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async notifyUploaded(id) {
|
|
265
|
-
return this.graphQLRequest(NOTIFY_UPLOADED_DOCUMENT_MUTATION, {
|
|
266
|
-
input: {
|
|
267
|
-
id: id,
|
|
268
|
-
},
|
|
269
|
-
}).then((d) => {
|
|
270
|
-
return d?.data?.notifyUploadedDocument || {};
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async destroy(id) {
|
|
275
|
-
return this.graphQLRequest(DELETE_DOCUMENT_MUTATION, {
|
|
276
|
-
input: {
|
|
277
|
-
id: id,
|
|
278
|
-
},
|
|
279
|
-
}).then((d) => {
|
|
280
|
-
return d?.data?.deleteDocument || {};
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
package/src/FilePicker/Dialog.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from "react";
|
|
2
|
-
import { useDropzone } from "react-dropzone";
|
|
3
|
-
import { Modal, Button, cn } from "@raketa-builder/ui";
|
|
4
|
-
|
|
5
|
-
const DropZone = ({ children, onDrop }) => {
|
|
6
|
-
const onFilesDrop = useCallback(
|
|
7
|
-
(acceptedFiles) => {
|
|
8
|
-
onDrop(acceptedFiles);
|
|
9
|
-
},
|
|
10
|
-
[onDrop],
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
14
|
-
onDropAccepted: onFilesDrop,
|
|
15
|
-
noClick: true,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div
|
|
20
|
-
className={cn(
|
|
21
|
-
"r-reset",
|
|
22
|
-
"r-dropzone-modal",
|
|
23
|
-
isDragActive ? "r-dropzone-modal-active" : "",
|
|
24
|
-
)}
|
|
25
|
-
{...getRootProps()}
|
|
26
|
-
>
|
|
27
|
-
<input {...getInputProps()} />
|
|
28
|
-
|
|
29
|
-
<div>
|
|
30
|
-
{isDragActive && <strong className="r-fs-large">Drop here</strong>}
|
|
31
|
-
</div>
|
|
32
|
-
|
|
33
|
-
{!isDragActive && children}
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const Dialog = ({
|
|
39
|
-
disablePrimary = false,
|
|
40
|
-
onClose,
|
|
41
|
-
onPrimary,
|
|
42
|
-
onDrop,
|
|
43
|
-
children,
|
|
44
|
-
}) => {
|
|
45
|
-
return (
|
|
46
|
-
<Modal
|
|
47
|
-
title="Files"
|
|
48
|
-
onClose={onClose}
|
|
49
|
-
onDrop={onDrop}
|
|
50
|
-
customWrapper={DropZone}
|
|
51
|
-
FooterContent={() => (
|
|
52
|
-
<>
|
|
53
|
-
<Button
|
|
54
|
-
type="button"
|
|
55
|
-
variant="primary"
|
|
56
|
-
disabled={disablePrimary}
|
|
57
|
-
onClick={onPrimary}
|
|
58
|
-
>
|
|
59
|
-
Select
|
|
60
|
-
</Button>
|
|
61
|
-
|
|
62
|
-
<Button type="button" variant="secondary" onClick={onClose}>
|
|
63
|
-
Cancel
|
|
64
|
-
</Button>
|
|
65
|
-
</>
|
|
66
|
-
)}
|
|
67
|
-
>
|
|
68
|
-
{children}
|
|
69
|
-
</Modal>
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export default Dialog;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
FormGroup,
|
|
4
|
-
Label,
|
|
5
|
-
Input,
|
|
6
|
-
Hint,
|
|
7
|
-
Button,
|
|
8
|
-
Stack,
|
|
9
|
-
} from "@raketa-builder/ui";
|
|
10
|
-
|
|
11
|
-
const FileInput = ({ value, label, hint, onBrowse, onClear }) => {
|
|
12
|
-
const filename = value?.document?.filename;
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<FormGroup>
|
|
16
|
-
{label && <Label>{label}</Label>}
|
|
17
|
-
|
|
18
|
-
<Stack className="r-stack-justify-center" style={{ gap: "0.5rem" }}>
|
|
19
|
-
<Input
|
|
20
|
-
disabled
|
|
21
|
-
placeholder={filename ? filename : "No file selected"}
|
|
22
|
-
/>
|
|
23
|
-
|
|
24
|
-
<Button type="button" variant="primary" onClick={onBrowse}>
|
|
25
|
-
Browse...
|
|
26
|
-
</Button>
|
|
27
|
-
<Button type="button" variant="secondary" onClick={() => onClear()}>
|
|
28
|
-
Clear
|
|
29
|
-
</Button>
|
|
30
|
-
</Stack>
|
|
31
|
-
|
|
32
|
-
{hint && <Hint>{hint}</Hint>}
|
|
33
|
-
</FormGroup>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default FileInput;
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Button, Stack, Input, cn } from "@raketa-builder/ui";
|
|
3
|
-
import { fileSizeFormatter } from "./utils";
|
|
4
|
-
import { toFileCategory } from "./FileCategory";
|
|
5
|
-
|
|
6
|
-
const DeleteIcon = (props) => {
|
|
7
|
-
return (
|
|
8
|
-
<svg
|
|
9
|
-
width="24"
|
|
10
|
-
height="25"
|
|
11
|
-
viewBox="0 0 24 25"
|
|
12
|
-
fill="none"
|
|
13
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
14
|
-
className="r-file-input-delete-icon"
|
|
15
|
-
{...props}
|
|
16
|
-
>
|
|
17
|
-
<title>Delete</title>
|
|
18
|
-
<path
|
|
19
|
-
d="M3 6.5H5H21"
|
|
20
|
-
stroke="currentColor"
|
|
21
|
-
strokeWidth="2"
|
|
22
|
-
strokeLinecap="round"
|
|
23
|
-
strokeLinejoin="round"
|
|
24
|
-
/>
|
|
25
|
-
<path
|
|
26
|
-
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"
|
|
27
|
-
stroke="currentColor"
|
|
28
|
-
strokeWidth="2"
|
|
29
|
-
strokeLinecap="round"
|
|
30
|
-
strokeLinejoin="round"
|
|
31
|
-
/>
|
|
32
|
-
<path
|
|
33
|
-
d="M10 11.5V17.5"
|
|
34
|
-
stroke="currentColor"
|
|
35
|
-
strokeWidth="2"
|
|
36
|
-
strokeLinecap="round"
|
|
37
|
-
strokeLinejoin="round"
|
|
38
|
-
/>
|
|
39
|
-
<path
|
|
40
|
-
d="M14 11.5V17.5"
|
|
41
|
-
stroke="currentColor"
|
|
42
|
-
strokeWidth="2"
|
|
43
|
-
strokeLinecap="round"
|
|
44
|
-
strokeLinejoin="round"
|
|
45
|
-
/>
|
|
46
|
-
</svg>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const CopyIcon = (props) => (
|
|
51
|
-
<svg
|
|
52
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
53
|
-
width="24"
|
|
54
|
-
height="25"
|
|
55
|
-
viewBox="0 0 24 25"
|
|
56
|
-
fill="none"
|
|
57
|
-
className="r-file-input-copy-icon"
|
|
58
|
-
{...props}
|
|
59
|
-
>
|
|
60
|
-
<title>Copy file URL</title>
|
|
61
|
-
<path
|
|
62
|
-
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"
|
|
63
|
-
stroke="black"
|
|
64
|
-
strokeWidth="2"
|
|
65
|
-
strokeLinecap="round"
|
|
66
|
-
strokeLinejoin="round"
|
|
67
|
-
/>
|
|
68
|
-
<path
|
|
69
|
-
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"
|
|
70
|
-
stroke="black"
|
|
71
|
-
strokeWidth="2"
|
|
72
|
-
strokeLinecap="round"
|
|
73
|
-
strokeLinejoin="round"
|
|
74
|
-
/>
|
|
75
|
-
</svg>
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const formatDate = (dateStr) =>
|
|
79
|
-
new Date(dateStr).toLocaleDateString(undefined, {
|
|
80
|
-
year: "numeric",
|
|
81
|
-
month: "long",
|
|
82
|
-
day: "numeric",
|
|
83
|
-
hour: "numeric",
|
|
84
|
-
minute: "numeric",
|
|
85
|
-
second: "numeric",
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const FileList = ({
|
|
89
|
-
files,
|
|
90
|
-
fetching,
|
|
91
|
-
selected,
|
|
92
|
-
allowDelete,
|
|
93
|
-
onMore,
|
|
94
|
-
onSelect,
|
|
95
|
-
onDelete,
|
|
96
|
-
}) => {
|
|
97
|
-
const showLoadMore = !fetching && onMore;
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<div className="r-reset">
|
|
101
|
-
<table className="r-table">
|
|
102
|
-
<thead>
|
|
103
|
-
<tr>
|
|
104
|
-
<th>Name</th>
|
|
105
|
-
<th>Type</th>
|
|
106
|
-
<th>Size</th>
|
|
107
|
-
<th>Uploaded</th>
|
|
108
|
-
</tr>
|
|
109
|
-
</thead>
|
|
110
|
-
|
|
111
|
-
<tbody>
|
|
112
|
-
{files.map((file) => (
|
|
113
|
-
<tr
|
|
114
|
-
key={file.id}
|
|
115
|
-
className={cn(
|
|
116
|
-
"r-file-input-file-row",
|
|
117
|
-
selected?.id === file.id ? "r-file-input-file-row-active" : ""
|
|
118
|
-
)}
|
|
119
|
-
onClick={() => onSelect(file.id)}
|
|
120
|
-
>
|
|
121
|
-
<td
|
|
122
|
-
style={{
|
|
123
|
-
width: "50%",
|
|
124
|
-
}}
|
|
125
|
-
>
|
|
126
|
-
<Stack
|
|
127
|
-
className="r-stack-align-center"
|
|
128
|
-
style={{ gap: "0.5rem" }}
|
|
129
|
-
>
|
|
130
|
-
<Input
|
|
131
|
-
type="radio"
|
|
132
|
-
checked={selected?.id === file.id}
|
|
133
|
-
readOnly
|
|
134
|
-
/>
|
|
135
|
-
|
|
136
|
-
<div>{decodeURI(file.filename)}</div>
|
|
137
|
-
|
|
138
|
-
<CopyIcon
|
|
139
|
-
onClick={(e) => {
|
|
140
|
-
e.stopPropagation();
|
|
141
|
-
navigator.clipboard.writeText(file.url);
|
|
142
|
-
}}
|
|
143
|
-
/>
|
|
144
|
-
|
|
145
|
-
{allowDelete && (
|
|
146
|
-
<DeleteIcon
|
|
147
|
-
onClick={(event) => {
|
|
148
|
-
event.stopPropagation();
|
|
149
|
-
|
|
150
|
-
if (confirm("Are you sure?")) {
|
|
151
|
-
onDelete(file.id);
|
|
152
|
-
}
|
|
153
|
-
}}
|
|
154
|
-
/>
|
|
155
|
-
)}
|
|
156
|
-
</Stack>
|
|
157
|
-
</td>
|
|
158
|
-
<td>{toFileCategory(file.mimeType, "human")}</td>
|
|
159
|
-
<td>{fileSizeFormatter(file.size)}</td>
|
|
160
|
-
<td>{formatDate(file.createdAt)}</td>
|
|
161
|
-
</tr>
|
|
162
|
-
))}
|
|
163
|
-
</tbody>
|
|
164
|
-
</table>
|
|
165
|
-
|
|
166
|
-
{showLoadMore && (
|
|
167
|
-
<Button variant="secondary" disabled={fetching} onClick={onMore}>
|
|
168
|
-
Load more
|
|
169
|
-
</Button>
|
|
170
|
-
)}
|
|
171
|
-
</div>
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
export default FileList;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Input, Stack, cn } from "@raketa-builder/ui";
|
|
3
|
-
import { fileCategoriesOptions } from "./FileCategory";
|
|
4
|
-
|
|
5
|
-
const useDebunce = (value, onDebouncedChange) => {
|
|
6
|
-
const timerRef = React.useRef(null);
|
|
7
|
-
|
|
8
|
-
React.useEffect(() => {
|
|
9
|
-
timerRef.current = setTimeout(() => {
|
|
10
|
-
onDebouncedChange(value);
|
|
11
|
-
}, 500);
|
|
12
|
-
|
|
13
|
-
return () => {
|
|
14
|
-
clearTimeout(timerRef.current);
|
|
15
|
-
};
|
|
16
|
-
}, [value]);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const SearchInput = ({ onChange }) => {
|
|
20
|
-
const [q, setQ] = React.useState("");
|
|
21
|
-
|
|
22
|
-
useDebunce(q, onChange);
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Input
|
|
26
|
-
placeholder="Start typing file name..."
|
|
27
|
-
value={q}
|
|
28
|
-
onChange={(e) => {
|
|
29
|
-
setQ(e.target.value);
|
|
30
|
-
}}
|
|
31
|
-
/>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
|
|
36
|
-
const onCategoryPick = (val) => {
|
|
37
|
-
onChange({
|
|
38
|
-
...value,
|
|
39
|
-
category: val,
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const onSearchTermChange = (q) => {
|
|
44
|
-
onChange({
|
|
45
|
-
...value,
|
|
46
|
-
keyword: q,
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
if (allowedFileCategory) {
|
|
51
|
-
return (
|
|
52
|
-
<div className="r-spacing-bottom-sm">
|
|
53
|
-
<SearchInput onChange={onSearchTermChange} />
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
<SearchInput onChange={onSearchTermChange} />
|
|
61
|
-
|
|
62
|
-
<Stack className="r-spacing-both-sm">
|
|
63
|
-
<div className={cn("r-reset", "r-tab-wrapper")}>
|
|
64
|
-
<button
|
|
65
|
-
type="button"
|
|
66
|
-
disabled={fetching}
|
|
67
|
-
className={`r-reset-button r-tab-button ${
|
|
68
|
-
value?.category === "" ? "r-tab-button-active" : ""
|
|
69
|
-
}`}
|
|
70
|
-
onClick={() => onCategoryPick("")}
|
|
71
|
-
>
|
|
72
|
-
All
|
|
73
|
-
</button>
|
|
74
|
-
|
|
75
|
-
{fileCategoriesOptions().map((category) => {
|
|
76
|
-
const [key, label] = category;
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<button
|
|
80
|
-
type="button"
|
|
81
|
-
key={key}
|
|
82
|
-
disabled={fetching}
|
|
83
|
-
className={`r-reset-button r-tab-button ${
|
|
84
|
-
value?.category === key ? "r-tab-button-active" : ""
|
|
85
|
-
}`}
|
|
86
|
-
onClick={() => onCategoryPick(key)}
|
|
87
|
-
>
|
|
88
|
-
{label}
|
|
89
|
-
</button>
|
|
90
|
-
);
|
|
91
|
-
})}
|
|
92
|
-
</div>
|
|
93
|
-
</Stack>
|
|
94
|
-
</>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default FileSearch;
|