@raketa-builder/file-input 1.0.8 → 1.1.0
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/index.js +1261 -0
- package/package.json +2 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,1261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
var __async = (__this, __arguments, generator) => {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
var fulfilled = (value) => {
|
|
45
|
+
try {
|
|
46
|
+
step(generator.next(value));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var rejected = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.throw(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/index.js
|
|
64
|
+
var src_exports = {};
|
|
65
|
+
__export(src_exports, {
|
|
66
|
+
FileManager: () => FileManager,
|
|
67
|
+
FilePicker: () => FilePicker_default
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(src_exports);
|
|
70
|
+
|
|
71
|
+
// src/FilePicker/index.js
|
|
72
|
+
var import_react7 = __toESM(require("react"));
|
|
73
|
+
var import_ui7 = require("@raketa-builder/ui");
|
|
74
|
+
|
|
75
|
+
// src/FilePicker/FileCategory.js
|
|
76
|
+
var VIDEO = ["video/3gpp", "video/3gpp2", "video/mp4", "video/webm"];
|
|
77
|
+
var AUDIO = [
|
|
78
|
+
"audio/webm",
|
|
79
|
+
"audio/wav",
|
|
80
|
+
"audio/mpeg",
|
|
81
|
+
"audio/aac",
|
|
82
|
+
"audio/midi",
|
|
83
|
+
"audio/x-midi",
|
|
84
|
+
"audio/ogg",
|
|
85
|
+
"audio/3gpp",
|
|
86
|
+
"audio/3gpp2",
|
|
87
|
+
"audio/m4a"
|
|
88
|
+
];
|
|
89
|
+
var DOCUMENT = [
|
|
90
|
+
"application/pdf",
|
|
91
|
+
"application/msword",
|
|
92
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
93
|
+
"application/vnd.ms-excel",
|
|
94
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
95
|
+
"application/vnd.ms-powerpoint",
|
|
96
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
97
|
+
"text/plain",
|
|
98
|
+
"application/epub+zip",
|
|
99
|
+
"application/x-mobipocket-ebook",
|
|
100
|
+
"application/rtf",
|
|
101
|
+
"text/csv",
|
|
102
|
+
"application/vnd.apple.pages",
|
|
103
|
+
"application/vnd.apple.numbers",
|
|
104
|
+
"application/vnd.apple.keynote"
|
|
105
|
+
];
|
|
106
|
+
var IMAGE = [
|
|
107
|
+
"image/png",
|
|
108
|
+
"image/x-png",
|
|
109
|
+
"image/vnd.mozilla.apng",
|
|
110
|
+
"image/jpeg",
|
|
111
|
+
"image/svg+xml",
|
|
112
|
+
"image/gif",
|
|
113
|
+
"image/avif",
|
|
114
|
+
"image/webp",
|
|
115
|
+
"application/postscript",
|
|
116
|
+
"mage/heic",
|
|
117
|
+
"mage/heic-sequence"
|
|
118
|
+
];
|
|
119
|
+
var ARCHIVE = [
|
|
120
|
+
"application/zip",
|
|
121
|
+
"application/gzip",
|
|
122
|
+
"application/x-gtar",
|
|
123
|
+
"application/x-tar",
|
|
124
|
+
"application/x-rar-compressed",
|
|
125
|
+
"application/x-7z-compressed"
|
|
126
|
+
];
|
|
127
|
+
var MIME_TYPES = IMAGE.concat(VIDEO).concat(DOCUMENT).concat(AUDIO).concat(ARCHIVE);
|
|
128
|
+
var MAPPING = {
|
|
129
|
+
video: VIDEO,
|
|
130
|
+
document: DOCUMENT,
|
|
131
|
+
image: IMAGE,
|
|
132
|
+
audio: AUDIO,
|
|
133
|
+
archive: ARCHIVE,
|
|
134
|
+
other: []
|
|
135
|
+
};
|
|
136
|
+
var FILE_CATEGORIES = {
|
|
137
|
+
document: "Document",
|
|
138
|
+
archive: "Archive",
|
|
139
|
+
image: "Image",
|
|
140
|
+
video: "Video",
|
|
141
|
+
audio: "Audio",
|
|
142
|
+
other: "Other"
|
|
143
|
+
};
|
|
144
|
+
function toMimeTypes(fileCategory) {
|
|
145
|
+
return MAPPING[fileCategory] || [];
|
|
146
|
+
}
|
|
147
|
+
function toExcludedMimeTypes(fileCategory) {
|
|
148
|
+
if (fileCategory === "other") {
|
|
149
|
+
return MIME_TYPES;
|
|
150
|
+
}
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
function toFileCategory(mimeType, format = "robot") {
|
|
154
|
+
let fileCategory = null;
|
|
155
|
+
Object.keys(FILE_CATEGORIES).forEach((key) => {
|
|
156
|
+
if (fileCategory) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (MAPPING[key].find((mt) => mt === mimeType)) {
|
|
160
|
+
fileCategory = key;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
if (!fileCategory) {
|
|
164
|
+
fileCategory = "other";
|
|
165
|
+
}
|
|
166
|
+
if (format === "human") {
|
|
167
|
+
return FILE_CATEGORIES[fileCategory] || fileCategory;
|
|
168
|
+
}
|
|
169
|
+
return fileCategory;
|
|
170
|
+
}
|
|
171
|
+
function fileCategoriesOptions() {
|
|
172
|
+
return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
|
|
173
|
+
}
|
|
174
|
+
function sanitizeFileCategory(fileCategory) {
|
|
175
|
+
if (fileCategory === "other") {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
if (Object.keys(FILE_CATEGORIES).includes(fileCategory)) {
|
|
179
|
+
return fileCategory;
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/FilePicker/stateManagement.js
|
|
185
|
+
function mimeTypes(category) {
|
|
186
|
+
return toMimeTypes(category);
|
|
187
|
+
}
|
|
188
|
+
function excludeMimeTypes(category) {
|
|
189
|
+
return toExcludedMimeTypes(category);
|
|
190
|
+
}
|
|
191
|
+
function initialState(initialSelected, initialCategory) {
|
|
192
|
+
return {
|
|
193
|
+
open: false,
|
|
194
|
+
fetching: false,
|
|
195
|
+
selected: initialSelected,
|
|
196
|
+
uploads: [],
|
|
197
|
+
files: {
|
|
198
|
+
initial: true,
|
|
199
|
+
list: [],
|
|
200
|
+
nextCursor: null,
|
|
201
|
+
filters: {
|
|
202
|
+
keyword: "",
|
|
203
|
+
category: initialCategory || ""
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function initialUploadState(file, allowedMimeTypes) {
|
|
209
|
+
if (allowedMimeTypes.length === 0 || allowedMimeTypes.includes(file.type)) {
|
|
210
|
+
return {
|
|
211
|
+
type: "pending",
|
|
212
|
+
payload: {}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
type: "rejected",
|
|
217
|
+
payload: {
|
|
218
|
+
errors: [`Files of type "${file.type}" are not supported.`]
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function uploadFiles(fileManager, files, allowedFileCategory, setState) {
|
|
223
|
+
const allowedMimeTypes = toMimeTypes(allowedFileCategory);
|
|
224
|
+
const fileUploads = files.map((file) => ({
|
|
225
|
+
file,
|
|
226
|
+
id: (Math.random() * 1e6).toFixed(0),
|
|
227
|
+
state: initialUploadState(file, allowedMimeTypes)
|
|
228
|
+
}));
|
|
229
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
230
|
+
uploads: [...currentState.uploads, ...fileUploads]
|
|
231
|
+
}));
|
|
232
|
+
fileUploads.filter((fu) => fu.state.type === "pending").forEach(
|
|
233
|
+
(fileUpload) => fileManager.createAndUpload(
|
|
234
|
+
fileUpload,
|
|
235
|
+
(tmpId, newState) => setState((currentState) => {
|
|
236
|
+
if (newState.type === "completed") {
|
|
237
|
+
if (currentState.files.list.find(
|
|
238
|
+
(file) => file.id === newState.payload.document.id
|
|
239
|
+
)) {
|
|
240
|
+
return currentState;
|
|
241
|
+
}
|
|
242
|
+
return __spreadProps(__spreadValues({}, currentState), {
|
|
243
|
+
uploads: currentState.uploads.filter(
|
|
244
|
+
(upload) => upload.id !== tmpId
|
|
245
|
+
),
|
|
246
|
+
files: __spreadProps(__spreadValues({}, currentState.files), {
|
|
247
|
+
list: [
|
|
248
|
+
__spreadValues({}, newState.payload.document),
|
|
249
|
+
...currentState.files.list
|
|
250
|
+
]
|
|
251
|
+
})
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const newUploads = currentState.uploads.map((upload) => {
|
|
255
|
+
if (upload.id === tmpId) {
|
|
256
|
+
return __spreadProps(__spreadValues({}, upload), { state: newState });
|
|
257
|
+
}
|
|
258
|
+
return upload;
|
|
259
|
+
});
|
|
260
|
+
return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
|
|
261
|
+
})
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
function loadFiles(fileManager, state, setState) {
|
|
266
|
+
return __async(this, null, function* () {
|
|
267
|
+
if (state.files.initial) {
|
|
268
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
269
|
+
open: true,
|
|
270
|
+
fetching: true
|
|
271
|
+
}));
|
|
272
|
+
const resp = yield fileManager.all({
|
|
273
|
+
mimeTypes: mimeTypes(state.files.filters.category),
|
|
274
|
+
excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
|
|
275
|
+
});
|
|
276
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
277
|
+
fetching: false,
|
|
278
|
+
files: {
|
|
279
|
+
initial: false,
|
|
280
|
+
list: resp.list || [],
|
|
281
|
+
nextCursor: resp.pagination.cursor,
|
|
282
|
+
filters: {
|
|
283
|
+
keyword: "",
|
|
284
|
+
category: ""
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}));
|
|
288
|
+
} else {
|
|
289
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
290
|
+
open: true
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function searchFiles(fileManager, filters, state, setState) {
|
|
296
|
+
return __async(this, null, function* () {
|
|
297
|
+
if ((filters.keyword !== state.files.filters.keyword || filters.category !== state.files.filters.category) && !state.fetching) {
|
|
298
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
299
|
+
fetching: true
|
|
300
|
+
}));
|
|
301
|
+
const resp = yield fileManager.all({
|
|
302
|
+
nextCursor: null,
|
|
303
|
+
keyword: filters.keyword,
|
|
304
|
+
mimeTypes: mimeTypes(filters.category),
|
|
305
|
+
excludeMimeTypes: excludeMimeTypes(filters.category)
|
|
306
|
+
});
|
|
307
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
308
|
+
fetching: false,
|
|
309
|
+
files: {
|
|
310
|
+
list: [...resp.list],
|
|
311
|
+
nextCursor: resp.pagination.cursor,
|
|
312
|
+
filters: {
|
|
313
|
+
keyword: filters.keyword,
|
|
314
|
+
category: filters.category
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}));
|
|
318
|
+
} else {
|
|
319
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
320
|
+
fetching: false,
|
|
321
|
+
files: __spreadProps(__spreadValues({}, currentState.files), {
|
|
322
|
+
filters: {
|
|
323
|
+
keyword: filters.keyword,
|
|
324
|
+
category: filters.category
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
}));
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function deleteFile(fileManager, fileId, state, setState, onChange) {
|
|
332
|
+
return __async(this, null, function* () {
|
|
333
|
+
var _a, _b;
|
|
334
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
335
|
+
fetching: true
|
|
336
|
+
}));
|
|
337
|
+
const response = yield fileManager.destroy(fileId);
|
|
338
|
+
let removeFromList = false;
|
|
339
|
+
let removeSelected = false;
|
|
340
|
+
if (response.errors) {
|
|
341
|
+
alert(`Something went wrong while deleting document#${fileId}`);
|
|
342
|
+
}
|
|
343
|
+
if (!response.errors && response.document) {
|
|
344
|
+
removeFromList = true;
|
|
345
|
+
if (fileId === ((_b = (_a = state.selected) == null ? void 0 : _a.document) == null ? void 0 : _b.id)) {
|
|
346
|
+
removeSelected = true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
350
|
+
fetching: false,
|
|
351
|
+
selected: removeSelected ? null : currentState.selected,
|
|
352
|
+
files: __spreadProps(__spreadValues({}, currentState.files), {
|
|
353
|
+
list: currentState.files.list.filter((f) => f.id !== fileId)
|
|
354
|
+
})
|
|
355
|
+
}));
|
|
356
|
+
if (removeSelected) {
|
|
357
|
+
onChange(null);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function selectFile(fileId, setState) {
|
|
362
|
+
setState((currentState) => {
|
|
363
|
+
const file = currentState.files.list.find((f) => f.id === fileId);
|
|
364
|
+
let newSelected = null;
|
|
365
|
+
if (file) {
|
|
366
|
+
newSelected = {
|
|
367
|
+
document: file,
|
|
368
|
+
uri: `raketacloud://documents/${file.id}`
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
return __spreadProps(__spreadValues({}, currentState), {
|
|
372
|
+
selected: newSelected
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function loadMoreFiles(fileManager, state, setState) {
|
|
377
|
+
if (!state.files.nextCursor) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
return function loadMore() {
|
|
381
|
+
return __async(this, null, function* () {
|
|
382
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
383
|
+
fetching: true
|
|
384
|
+
}));
|
|
385
|
+
const resp = yield fileManager.all({
|
|
386
|
+
nextCursor: state.files.nextCursor,
|
|
387
|
+
keyword: state.files.filters.keyword,
|
|
388
|
+
mimeTypes: mimeTypes(state.files.filters.category),
|
|
389
|
+
excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
|
|
390
|
+
});
|
|
391
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
392
|
+
fetching: false,
|
|
393
|
+
files: {
|
|
394
|
+
list: [...currentState.files.list, ...resp.list],
|
|
395
|
+
nextCursor: resp.pagination.cursor,
|
|
396
|
+
filters: __spreadValues({}, currentState.files.filters)
|
|
397
|
+
}
|
|
398
|
+
}));
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/FilePicker/Dialog.js
|
|
404
|
+
var import_react = __toESM(require("react"));
|
|
405
|
+
var import_react_dropzone = require("react-dropzone");
|
|
406
|
+
var import_ui = require("@raketa-builder/ui");
|
|
407
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
408
|
+
var DropZone = ({ children, onDrop }) => {
|
|
409
|
+
const onFilesDrop = (0, import_react.useCallback)(
|
|
410
|
+
(acceptedFiles) => {
|
|
411
|
+
onDrop(acceptedFiles);
|
|
412
|
+
},
|
|
413
|
+
[onDrop]
|
|
414
|
+
);
|
|
415
|
+
const { getRootProps, getInputProps, isDragActive } = (0, import_react_dropzone.useDropzone)({
|
|
416
|
+
onDropAccepted: onFilesDrop,
|
|
417
|
+
noClick: true
|
|
418
|
+
});
|
|
419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
420
|
+
"div",
|
|
421
|
+
__spreadProps(__spreadValues({
|
|
422
|
+
className: (0, import_ui.cn)(
|
|
423
|
+
"r-reset",
|
|
424
|
+
"r-dropzone-modal",
|
|
425
|
+
isDragActive ? "r-dropzone-modal-active" : ""
|
|
426
|
+
)
|
|
427
|
+
}, getRootProps()), {
|
|
428
|
+
children: [
|
|
429
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", __spreadValues({}, getInputProps())),
|
|
430
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: isDragActive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { className: "r-fs-large", children: "Drop here" }) }),
|
|
431
|
+
!isDragActive && children
|
|
432
|
+
]
|
|
433
|
+
})
|
|
434
|
+
);
|
|
435
|
+
};
|
|
436
|
+
var Dialog = ({
|
|
437
|
+
disablePrimary = false,
|
|
438
|
+
onClose,
|
|
439
|
+
onPrimary,
|
|
440
|
+
onDrop,
|
|
441
|
+
children
|
|
442
|
+
}) => {
|
|
443
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
444
|
+
import_ui.Modal,
|
|
445
|
+
{
|
|
446
|
+
title: "Files",
|
|
447
|
+
onClose,
|
|
448
|
+
onDrop,
|
|
449
|
+
customWrapper: DropZone,
|
|
450
|
+
FooterContent: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
452
|
+
import_ui.Button,
|
|
453
|
+
{
|
|
454
|
+
type: "button",
|
|
455
|
+
variant: "primary",
|
|
456
|
+
disabled: disablePrimary,
|
|
457
|
+
onClick: onPrimary,
|
|
458
|
+
children: "Select"
|
|
459
|
+
}
|
|
460
|
+
),
|
|
461
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { type: "button", variant: "secondary", onClick: onClose, children: "Cancel" })
|
|
462
|
+
] }),
|
|
463
|
+
children
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
};
|
|
467
|
+
var Dialog_default = Dialog;
|
|
468
|
+
|
|
469
|
+
// src/FilePicker/FileSearch.js
|
|
470
|
+
var import_react2 = __toESM(require("react"));
|
|
471
|
+
var import_ui2 = require("@raketa-builder/ui");
|
|
472
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
473
|
+
var useDebunce = (value, onDebouncedChange) => {
|
|
474
|
+
const timerRef = import_react2.default.useRef(null);
|
|
475
|
+
import_react2.default.useEffect(() => {
|
|
476
|
+
timerRef.current = setTimeout(() => {
|
|
477
|
+
onDebouncedChange(value);
|
|
478
|
+
}, 500);
|
|
479
|
+
return () => {
|
|
480
|
+
clearTimeout(timerRef.current);
|
|
481
|
+
};
|
|
482
|
+
}, [value]);
|
|
483
|
+
};
|
|
484
|
+
var SearchInput = ({ onChange }) => {
|
|
485
|
+
const [q, setQ] = import_react2.default.useState("");
|
|
486
|
+
useDebunce(q, onChange);
|
|
487
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
488
|
+
import_ui2.Input,
|
|
489
|
+
{
|
|
490
|
+
placeholder: "Start typing file name...",
|
|
491
|
+
value: q,
|
|
492
|
+
onChange: (e) => {
|
|
493
|
+
setQ(e.target.value);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
);
|
|
497
|
+
};
|
|
498
|
+
var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
|
|
499
|
+
const onCategoryPick = (val) => {
|
|
500
|
+
onChange(__spreadProps(__spreadValues({}, value), {
|
|
501
|
+
category: val
|
|
502
|
+
}));
|
|
503
|
+
};
|
|
504
|
+
const onSearchTermChange = (q) => {
|
|
505
|
+
onChange(__spreadProps(__spreadValues({}, value), {
|
|
506
|
+
keyword: q
|
|
507
|
+
}));
|
|
508
|
+
};
|
|
509
|
+
if (allowedFileCategory) {
|
|
510
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "r-spacing-bottom-sm", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }) });
|
|
511
|
+
}
|
|
512
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
513
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }),
|
|
514
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui2.Stack, { className: "r-spacing-both-sm", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: (0, import_ui2.cn)("r-reset", "r-tab-wrapper"), children: [
|
|
515
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
516
|
+
"button",
|
|
517
|
+
{
|
|
518
|
+
type: "button",
|
|
519
|
+
disabled: fetching,
|
|
520
|
+
className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === "" ? "r-tab-button-active" : ""}`,
|
|
521
|
+
onClick: () => onCategoryPick(""),
|
|
522
|
+
children: "All"
|
|
523
|
+
}
|
|
524
|
+
),
|
|
525
|
+
fileCategoriesOptions().map((category) => {
|
|
526
|
+
const [key, label] = category;
|
|
527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
528
|
+
"button",
|
|
529
|
+
{
|
|
530
|
+
type: "button",
|
|
531
|
+
disabled: fetching,
|
|
532
|
+
className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === key ? "r-tab-button-active" : ""}`,
|
|
533
|
+
onClick: () => onCategoryPick(key),
|
|
534
|
+
children: label
|
|
535
|
+
},
|
|
536
|
+
key
|
|
537
|
+
);
|
|
538
|
+
})
|
|
539
|
+
] }) })
|
|
540
|
+
] });
|
|
541
|
+
};
|
|
542
|
+
var FileSearch_default = FileSearch;
|
|
543
|
+
|
|
544
|
+
// src/FilePicker/FileList.js
|
|
545
|
+
var import_react3 = __toESM(require("react"));
|
|
546
|
+
var import_ui3 = require("@raketa-builder/ui");
|
|
547
|
+
|
|
548
|
+
// src/FilePicker/utils.js
|
|
549
|
+
function fileSizeFormatter(size) {
|
|
550
|
+
if (size < 1024) {
|
|
551
|
+
return `${size} B`;
|
|
552
|
+
}
|
|
553
|
+
if (size < 1024 * 1024) {
|
|
554
|
+
return `${(size / 1024).toFixed(2)} kB`;
|
|
555
|
+
}
|
|
556
|
+
if (size < 1024 * 1024 * 1024) {
|
|
557
|
+
return `${(size / 1024 / 1024).toFixed(2)} MB`;
|
|
558
|
+
}
|
|
559
|
+
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/FilePicker/FileList.js
|
|
563
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
564
|
+
var DeleteIcon = (props) => {
|
|
565
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
566
|
+
"svg",
|
|
567
|
+
__spreadProps(__spreadValues({
|
|
568
|
+
width: "24",
|
|
569
|
+
height: "25",
|
|
570
|
+
viewBox: "0 0 24 25",
|
|
571
|
+
fill: "none",
|
|
572
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
573
|
+
className: "r-file-input-delete-icon"
|
|
574
|
+
}, props), {
|
|
575
|
+
children: [
|
|
576
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Delete" }),
|
|
577
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
578
|
+
"path",
|
|
579
|
+
{
|
|
580
|
+
d: "M3 6.5H5H21",
|
|
581
|
+
stroke: "currentColor",
|
|
582
|
+
strokeWidth: "2",
|
|
583
|
+
strokeLinecap: "round",
|
|
584
|
+
strokeLinejoin: "round"
|
|
585
|
+
}
|
|
586
|
+
),
|
|
587
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
588
|
+
"path",
|
|
589
|
+
{
|
|
590
|
+
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",
|
|
591
|
+
stroke: "currentColor",
|
|
592
|
+
strokeWidth: "2",
|
|
593
|
+
strokeLinecap: "round",
|
|
594
|
+
strokeLinejoin: "round"
|
|
595
|
+
}
|
|
596
|
+
),
|
|
597
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
598
|
+
"path",
|
|
599
|
+
{
|
|
600
|
+
d: "M10 11.5V17.5",
|
|
601
|
+
stroke: "currentColor",
|
|
602
|
+
strokeWidth: "2",
|
|
603
|
+
strokeLinecap: "round",
|
|
604
|
+
strokeLinejoin: "round"
|
|
605
|
+
}
|
|
606
|
+
),
|
|
607
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
608
|
+
"path",
|
|
609
|
+
{
|
|
610
|
+
d: "M14 11.5V17.5",
|
|
611
|
+
stroke: "currentColor",
|
|
612
|
+
strokeWidth: "2",
|
|
613
|
+
strokeLinecap: "round",
|
|
614
|
+
strokeLinejoin: "round"
|
|
615
|
+
}
|
|
616
|
+
)
|
|
617
|
+
]
|
|
618
|
+
})
|
|
619
|
+
);
|
|
620
|
+
};
|
|
621
|
+
var CopyIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
622
|
+
"svg",
|
|
623
|
+
__spreadProps(__spreadValues({
|
|
624
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
625
|
+
width: "24",
|
|
626
|
+
height: "25",
|
|
627
|
+
viewBox: "0 0 24 25",
|
|
628
|
+
fill: "none",
|
|
629
|
+
className: "r-file-input-copy-icon"
|
|
630
|
+
}, props), {
|
|
631
|
+
children: [
|
|
632
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Copy file URL" }),
|
|
633
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
634
|
+
"path",
|
|
635
|
+
{
|
|
636
|
+
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",
|
|
637
|
+
stroke: "black",
|
|
638
|
+
strokeWidth: "2",
|
|
639
|
+
strokeLinecap: "round",
|
|
640
|
+
strokeLinejoin: "round"
|
|
641
|
+
}
|
|
642
|
+
),
|
|
643
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
644
|
+
"path",
|
|
645
|
+
{
|
|
646
|
+
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",
|
|
647
|
+
stroke: "black",
|
|
648
|
+
strokeWidth: "2",
|
|
649
|
+
strokeLinecap: "round",
|
|
650
|
+
strokeLinejoin: "round"
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
]
|
|
654
|
+
})
|
|
655
|
+
);
|
|
656
|
+
var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
|
|
657
|
+
year: "numeric",
|
|
658
|
+
month: "long",
|
|
659
|
+
day: "numeric",
|
|
660
|
+
hour: "numeric",
|
|
661
|
+
minute: "numeric",
|
|
662
|
+
second: "numeric"
|
|
663
|
+
});
|
|
664
|
+
var FileList = ({
|
|
665
|
+
files,
|
|
666
|
+
fetching,
|
|
667
|
+
selected,
|
|
668
|
+
allowDelete,
|
|
669
|
+
onMore,
|
|
670
|
+
onSelect,
|
|
671
|
+
onDelete
|
|
672
|
+
}) => {
|
|
673
|
+
const showLoadMore = !fetching && onMore;
|
|
674
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "r-reset", children: [
|
|
675
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { className: "r-table", children: [
|
|
676
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
|
|
677
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Name" }),
|
|
678
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Type" }),
|
|
679
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Size" }),
|
|
680
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Uploaded" })
|
|
681
|
+
] }) }),
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
683
|
+
"tr",
|
|
684
|
+
{
|
|
685
|
+
className: (0, import_ui3.cn)(
|
|
686
|
+
"r-file-input-file-row",
|
|
687
|
+
(selected == null ? void 0 : selected.id) === file.id ? "r-file-input-file-row-active" : ""
|
|
688
|
+
),
|
|
689
|
+
onClick: () => onSelect(file.id),
|
|
690
|
+
children: [
|
|
691
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
692
|
+
"td",
|
|
693
|
+
{
|
|
694
|
+
style: {
|
|
695
|
+
width: "50%"
|
|
696
|
+
},
|
|
697
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
698
|
+
import_ui3.Stack,
|
|
699
|
+
{
|
|
700
|
+
className: "r-stack-align-center",
|
|
701
|
+
style: { gap: "0.5rem" },
|
|
702
|
+
children: [
|
|
703
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
704
|
+
import_ui3.Input,
|
|
705
|
+
{
|
|
706
|
+
type: "radio",
|
|
707
|
+
checked: (selected == null ? void 0 : selected.id) === file.id,
|
|
708
|
+
readOnly: true
|
|
709
|
+
}
|
|
710
|
+
),
|
|
711
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
|
|
712
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
713
|
+
CopyIcon,
|
|
714
|
+
{
|
|
715
|
+
onClick: (e) => {
|
|
716
|
+
e.stopPropagation();
|
|
717
|
+
navigator.clipboard.writeText(file.url);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
),
|
|
721
|
+
allowDelete && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
722
|
+
DeleteIcon,
|
|
723
|
+
{
|
|
724
|
+
onClick: (event) => {
|
|
725
|
+
event.stopPropagation();
|
|
726
|
+
if (confirm("Are you sure?")) {
|
|
727
|
+
onDelete(file.id);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
)
|
|
732
|
+
]
|
|
733
|
+
}
|
|
734
|
+
)
|
|
735
|
+
}
|
|
736
|
+
),
|
|
737
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: toFileCategory(file.mimeType, "human") }),
|
|
738
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: fileSizeFormatter(file.size) }),
|
|
739
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: formatDate(file.createdAt) })
|
|
740
|
+
]
|
|
741
|
+
},
|
|
742
|
+
file.id
|
|
743
|
+
)) })
|
|
744
|
+
] }),
|
|
745
|
+
showLoadMore && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Button, { variant: "secondary", disabled: fetching, onClick: onMore, children: "Load more" })
|
|
746
|
+
] });
|
|
747
|
+
};
|
|
748
|
+
var FileList_default = FileList;
|
|
749
|
+
|
|
750
|
+
// src/FilePicker/FileInput.js
|
|
751
|
+
var import_react4 = __toESM(require("react"));
|
|
752
|
+
var import_ui4 = require("@raketa-builder/ui");
|
|
753
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
754
|
+
var FileInput = ({ value, label, hint, onBrowse, onClear }) => {
|
|
755
|
+
var _a;
|
|
756
|
+
const filename = (_a = value == null ? void 0 : value.document) == null ? void 0 : _a.filename;
|
|
757
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.FormGroup, { children: [
|
|
758
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Label, { children: label }),
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Stack, { className: "r-stack-justify-center", style: { gap: "0.5rem" }, children: [
|
|
760
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
761
|
+
import_ui4.Input,
|
|
762
|
+
{
|
|
763
|
+
disabled: true,
|
|
764
|
+
placeholder: filename ? filename : "No file selected"
|
|
765
|
+
}
|
|
766
|
+
),
|
|
767
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "primary", onClick: onBrowse, children: "Browse..." }),
|
|
768
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "secondary", onClick: () => onClear(), children: "Clear" })
|
|
769
|
+
] }),
|
|
770
|
+
hint && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Hint, { children: hint })
|
|
771
|
+
] });
|
|
772
|
+
};
|
|
773
|
+
var FileInput_default = FileInput;
|
|
774
|
+
|
|
775
|
+
// src/FilePicker/UploadProgress.js
|
|
776
|
+
var import_react5 = __toESM(require("react"));
|
|
777
|
+
var import_ui5 = require("@raketa-builder/ui");
|
|
778
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
779
|
+
var UploadState = ({ upload }) => {
|
|
780
|
+
var _a, _b;
|
|
781
|
+
switch (upload.state.type) {
|
|
782
|
+
case "pending":
|
|
783
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
|
|
784
|
+
fileSizeFormatter(0),
|
|
785
|
+
" / ",
|
|
786
|
+
fileSizeFormatter(upload.file.size || 0)
|
|
787
|
+
] });
|
|
788
|
+
case "progress":
|
|
789
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
790
|
+
"div",
|
|
791
|
+
{
|
|
792
|
+
className: (0, import_ui5.cn)(
|
|
793
|
+
"r-reset",
|
|
794
|
+
"r-stack",
|
|
795
|
+
"r-stack-justify-beteen",
|
|
796
|
+
"r-stack-align-center"
|
|
797
|
+
),
|
|
798
|
+
children: [
|
|
799
|
+
fileSizeFormatter(((_b = (_a = upload.state) == null ? void 0 : _a.payload) == null ? void 0 : _b.loaded) || 0),
|
|
800
|
+
" /",
|
|
801
|
+
" ",
|
|
802
|
+
fileSizeFormatter(upload.file.size || 0)
|
|
803
|
+
]
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
case "uploaded":
|
|
807
|
+
case "completed":
|
|
808
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
|
|
809
|
+
fileSizeFormatter(upload.file.size || 0),
|
|
810
|
+
" /",
|
|
811
|
+
" ",
|
|
812
|
+
fileSizeFormatter(upload.file.size || 0)
|
|
813
|
+
] });
|
|
814
|
+
case "errored":
|
|
815
|
+
console.error({ upload });
|
|
816
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: "Failed to upload" });
|
|
817
|
+
case "rejected":
|
|
818
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: upload.state.payload.errors.join("; ") });
|
|
819
|
+
default:
|
|
820
|
+
console.error({ upload });
|
|
821
|
+
throw `Unknown state: ${upload.state}`;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
var UploadName = ({ upload }) => {
|
|
825
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "r-reset", children: upload.file.name });
|
|
826
|
+
};
|
|
827
|
+
var UploadProgress = ({ uploads }) => {
|
|
828
|
+
if (uploads.length === 0) {
|
|
829
|
+
return null;
|
|
830
|
+
}
|
|
831
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-spacing-top-sm"), children: uploads.map((upload) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
832
|
+
import_ui5.Stack,
|
|
833
|
+
{
|
|
834
|
+
className: (0, import_ui5.cn)(
|
|
835
|
+
"r-reset",
|
|
836
|
+
"r-stack-justify-beteen",
|
|
837
|
+
"r-stack-align-center",
|
|
838
|
+
"r-file-progress"
|
|
839
|
+
),
|
|
840
|
+
children: [
|
|
841
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadName, { upload }),
|
|
842
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadState, { upload })
|
|
843
|
+
]
|
|
844
|
+
},
|
|
845
|
+
upload.id
|
|
846
|
+
)) });
|
|
847
|
+
};
|
|
848
|
+
var UploadProgress_default = UploadProgress;
|
|
849
|
+
|
|
850
|
+
// src/FilePicker/UploadFilesButton.js
|
|
851
|
+
var import_react6 = __toESM(require("react"));
|
|
852
|
+
var import_ui6 = require("@raketa-builder/ui");
|
|
853
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
854
|
+
var UploadFilesButton = ({ allowedFileCategory, onSelect }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
855
|
+
"div",
|
|
856
|
+
{
|
|
857
|
+
className: (0, import_ui6.cn)("r-reset", "r-spacing-both-sm", "r-file-input-upload-button"),
|
|
858
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: (0, import_ui6.cn)("r-button", "r-button-secondary"), children: [
|
|
859
|
+
"Upload files...",
|
|
860
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
861
|
+
"input",
|
|
862
|
+
{
|
|
863
|
+
id: "r-files-input",
|
|
864
|
+
type: "file",
|
|
865
|
+
multiple: true,
|
|
866
|
+
accept: allowedFileCategory ? toMimeTypes(allowedFileCategory) : "",
|
|
867
|
+
onChange: (event) => {
|
|
868
|
+
const fileList = event.target.files;
|
|
869
|
+
const files = [];
|
|
870
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
871
|
+
files[i] = fileList.item(i);
|
|
872
|
+
}
|
|
873
|
+
onSelect(files);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
)
|
|
877
|
+
] })
|
|
878
|
+
}
|
|
879
|
+
);
|
|
880
|
+
var UploadFilesButton_default = UploadFilesButton;
|
|
881
|
+
|
|
882
|
+
// src/FilePicker/index.js
|
|
883
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
884
|
+
var FilePicker = ({
|
|
885
|
+
fileManager,
|
|
886
|
+
value: initialValue,
|
|
887
|
+
label,
|
|
888
|
+
hint,
|
|
889
|
+
fileCategory = null,
|
|
890
|
+
allowFilesDelete = true,
|
|
891
|
+
onChange
|
|
892
|
+
}) => {
|
|
893
|
+
var _a;
|
|
894
|
+
const allowedFileCategory = import_react7.default.useMemo(
|
|
895
|
+
() => sanitizeFileCategory(fileCategory),
|
|
896
|
+
[fileCategory]
|
|
897
|
+
);
|
|
898
|
+
const [state, setState] = import_react7.default.useState(
|
|
899
|
+
initialState(initialValue, allowedFileCategory)
|
|
900
|
+
);
|
|
901
|
+
const onFilesUpload = (files) => {
|
|
902
|
+
uploadFiles(fileManager, files, allowedFileCategory, setState);
|
|
903
|
+
};
|
|
904
|
+
const onBrowse = () => __async(void 0, null, function* () {
|
|
905
|
+
loadFiles(fileManager, state, setState);
|
|
906
|
+
});
|
|
907
|
+
const onClear = () => {
|
|
908
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
|
|
909
|
+
selected: null
|
|
910
|
+
}));
|
|
911
|
+
onChange(null);
|
|
912
|
+
};
|
|
913
|
+
const onSelectFile = () => {
|
|
914
|
+
if (state.selected) {
|
|
915
|
+
onChange(state.selected);
|
|
916
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
|
|
917
|
+
} else {
|
|
918
|
+
alert("No file selected!");
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
const onClose = () => {
|
|
922
|
+
setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
|
|
923
|
+
};
|
|
924
|
+
const onSearchFiltersUpdate = (value) => __async(void 0, null, function* () {
|
|
925
|
+
searchFiles(fileManager, value, state, setState);
|
|
926
|
+
});
|
|
927
|
+
const onDeleteFile = (fileId) => __async(void 0, null, function* () {
|
|
928
|
+
deleteFile(fileManager, fileId, state, setState, onChange);
|
|
929
|
+
});
|
|
930
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
931
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
932
|
+
FileInput_default,
|
|
933
|
+
{
|
|
934
|
+
label,
|
|
935
|
+
hint,
|
|
936
|
+
value: initialValue,
|
|
937
|
+
onBrowse,
|
|
938
|
+
onClear
|
|
939
|
+
}
|
|
940
|
+
),
|
|
941
|
+
state.open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
942
|
+
Dialog_default,
|
|
943
|
+
{
|
|
944
|
+
disablePrimary: !state.selected,
|
|
945
|
+
onPrimary: onSelectFile,
|
|
946
|
+
onClose,
|
|
947
|
+
onDrop: onFilesUpload,
|
|
948
|
+
children: [
|
|
949
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
950
|
+
UploadFilesButton_default,
|
|
951
|
+
{
|
|
952
|
+
allowedFileCategory,
|
|
953
|
+
onSelect: onFilesUpload
|
|
954
|
+
}
|
|
955
|
+
),
|
|
956
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UploadProgress_default, { uploads: state.uploads }),
|
|
957
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.H, { className: "r-spacing-top-sm", children: "Search" }),
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
959
|
+
FileSearch_default,
|
|
960
|
+
{
|
|
961
|
+
allowedFileCategory,
|
|
962
|
+
fetching: state.fetching,
|
|
963
|
+
value: state.files.filters,
|
|
964
|
+
onChange: onSearchFiltersUpdate
|
|
965
|
+
}
|
|
966
|
+
),
|
|
967
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
968
|
+
FileList_default,
|
|
969
|
+
{
|
|
970
|
+
fetching: state.fetching,
|
|
971
|
+
files: state.files.list,
|
|
972
|
+
onMore: loadMoreFiles(fileManager, state, setState),
|
|
973
|
+
allowDelete: allowFilesDelete,
|
|
974
|
+
onDelete: onDeleteFile,
|
|
975
|
+
selected: (_a = state.selected) == null ? void 0 : _a.document,
|
|
976
|
+
onSelect: (fileId) => selectFile(fileId, setState)
|
|
977
|
+
}
|
|
978
|
+
)
|
|
979
|
+
]
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
] });
|
|
983
|
+
};
|
|
984
|
+
var FilePicker_default = FilePicker;
|
|
985
|
+
|
|
986
|
+
// src/FileManager.js
|
|
987
|
+
var DOCUMENTS_QUERY = `
|
|
988
|
+
query($input: DocumentsInput!) {
|
|
989
|
+
documents(input: $input) {
|
|
990
|
+
list {
|
|
991
|
+
id
|
|
992
|
+
filename
|
|
993
|
+
mimeType
|
|
994
|
+
size
|
|
995
|
+
uploadStatus
|
|
996
|
+
url
|
|
997
|
+
createdAt
|
|
998
|
+
}
|
|
999
|
+
pagination {
|
|
1000
|
+
cursor
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
`;
|
|
1005
|
+
var CREATE_DOCUMENT_MUTATION = `
|
|
1006
|
+
mutation($input: CreateDocumentInput!) {
|
|
1007
|
+
createDocument(input: $input) {
|
|
1008
|
+
document {
|
|
1009
|
+
id
|
|
1010
|
+
filename
|
|
1011
|
+
mimeType
|
|
1012
|
+
size
|
|
1013
|
+
uploadStatus
|
|
1014
|
+
url
|
|
1015
|
+
createdAt
|
|
1016
|
+
uploadUrl
|
|
1017
|
+
}
|
|
1018
|
+
errors {
|
|
1019
|
+
key
|
|
1020
|
+
message
|
|
1021
|
+
codes {
|
|
1022
|
+
key
|
|
1023
|
+
placeholders
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
`;
|
|
1029
|
+
var NOTIFY_UPLOADED_DOCUMENT_MUTATION = `
|
|
1030
|
+
mutation($input: NotifyUploadedDocumentInput!) {
|
|
1031
|
+
notifyUploadedDocument(input: $input) {
|
|
1032
|
+
document {
|
|
1033
|
+
id
|
|
1034
|
+
filename
|
|
1035
|
+
mimeType
|
|
1036
|
+
size
|
|
1037
|
+
uploadStatus
|
|
1038
|
+
url
|
|
1039
|
+
createdAt
|
|
1040
|
+
}
|
|
1041
|
+
errors {
|
|
1042
|
+
key
|
|
1043
|
+
message
|
|
1044
|
+
codes {
|
|
1045
|
+
key
|
|
1046
|
+
placeholders
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
`;
|
|
1052
|
+
var DELETE_DOCUMENT_MUTATION = `
|
|
1053
|
+
mutation($input: DeleteDocumentInput!) {
|
|
1054
|
+
deleteDocument(input: $input) {
|
|
1055
|
+
document {
|
|
1056
|
+
id
|
|
1057
|
+
filename
|
|
1058
|
+
mimeType
|
|
1059
|
+
size
|
|
1060
|
+
uploadStatus
|
|
1061
|
+
url
|
|
1062
|
+
createdAt
|
|
1063
|
+
}
|
|
1064
|
+
errors {
|
|
1065
|
+
key
|
|
1066
|
+
message
|
|
1067
|
+
codes {
|
|
1068
|
+
key
|
|
1069
|
+
placeholders
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
`;
|
|
1075
|
+
function uploadFile(file, document, progressCallback) {
|
|
1076
|
+
return __async(this, null, function* () {
|
|
1077
|
+
const xhr = new XMLHttpRequest();
|
|
1078
|
+
return new Promise((resolve) => {
|
|
1079
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
1080
|
+
if (event.lengthComputable) {
|
|
1081
|
+
progressCallback({
|
|
1082
|
+
type: "progress",
|
|
1083
|
+
payload: {
|
|
1084
|
+
loaded: event.loaded,
|
|
1085
|
+
total: event.total
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
xhr.addEventListener("loadend", (event) => {
|
|
1091
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
1092
|
+
progressCallback({
|
|
1093
|
+
type: "uploaded",
|
|
1094
|
+
payload: {}
|
|
1095
|
+
});
|
|
1096
|
+
} else {
|
|
1097
|
+
progressCallback({
|
|
1098
|
+
type: "errored",
|
|
1099
|
+
payload: {
|
|
1100
|
+
errors: `ReadyState: ${xhr.readyState} - ${xhr.status} - ${event.type}: ${event.loaded} bytes transferred.`
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
resolve(xhr.readyState === 4 && xhr.status === 200);
|
|
1105
|
+
});
|
|
1106
|
+
xhr.withCredentials = false;
|
|
1107
|
+
xhr.open("PUT", document.uploadUrl, true);
|
|
1108
|
+
xhr.setRequestHeader("content-type", file.type);
|
|
1109
|
+
const reader = new FileReader();
|
|
1110
|
+
reader.onload = (event) => {
|
|
1111
|
+
xhr.send(event.target.result);
|
|
1112
|
+
};
|
|
1113
|
+
reader.readAsArrayBuffer(file);
|
|
1114
|
+
});
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
var FileManager = class {
|
|
1118
|
+
constructor(url, headers) {
|
|
1119
|
+
this.url = url;
|
|
1120
|
+
this.headers = headers;
|
|
1121
|
+
}
|
|
1122
|
+
graphQLRequest(query, variables) {
|
|
1123
|
+
return __async(this, null, function* () {
|
|
1124
|
+
return fetch(this.url, {
|
|
1125
|
+
method: "POST",
|
|
1126
|
+
headers: Object.assign(
|
|
1127
|
+
{ "Content-Type": "application/json" },
|
|
1128
|
+
this.headers
|
|
1129
|
+
),
|
|
1130
|
+
body: JSON.stringify({
|
|
1131
|
+
query,
|
|
1132
|
+
variables
|
|
1133
|
+
})
|
|
1134
|
+
}).then((res) => res.json());
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
buildFilters(params) {
|
|
1138
|
+
var _a, _b;
|
|
1139
|
+
const filters = {
|
|
1140
|
+
uploadStatus: "COMPLETED"
|
|
1141
|
+
};
|
|
1142
|
+
if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
|
|
1143
|
+
filters.mimeTypes = params.mimeTypes;
|
|
1144
|
+
}
|
|
1145
|
+
if (((_b = params == null ? void 0 : params.excludeMimeTypes) == null ? void 0 : _b.length) > 0) {
|
|
1146
|
+
filters.excludeMimeTypes = params.excludeMimeTypes;
|
|
1147
|
+
}
|
|
1148
|
+
if (params == null ? void 0 : params.keyword) {
|
|
1149
|
+
filters.keyword = params.keyword;
|
|
1150
|
+
}
|
|
1151
|
+
return filters;
|
|
1152
|
+
}
|
|
1153
|
+
buildVariables(params) {
|
|
1154
|
+
const variables = {
|
|
1155
|
+
input: {
|
|
1156
|
+
filters: this.buildFilters(params)
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
if (params.nextCursor) {
|
|
1160
|
+
variables.input.pagination = { cursor: params.nextCursor };
|
|
1161
|
+
}
|
|
1162
|
+
return variables;
|
|
1163
|
+
}
|
|
1164
|
+
all() {
|
|
1165
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1166
|
+
return this.graphQLRequest(
|
|
1167
|
+
DOCUMENTS_QUERY,
|
|
1168
|
+
this.buildVariables(params)
|
|
1169
|
+
).then((d) => {
|
|
1170
|
+
return (d == null ? void 0 : d.data.documents) || {};
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
createAndUpload(fileInfo, progressCallback) {
|
|
1175
|
+
return __async(this, null, function* () {
|
|
1176
|
+
const { file, id } = fileInfo;
|
|
1177
|
+
const { document, errors } = yield this.create({
|
|
1178
|
+
filename: file.name,
|
|
1179
|
+
mime_type: file.type,
|
|
1180
|
+
size: file.size
|
|
1181
|
+
});
|
|
1182
|
+
if (errors) {
|
|
1183
|
+
progressCallback(id, {
|
|
1184
|
+
type: "errored",
|
|
1185
|
+
payload: {
|
|
1186
|
+
errors
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
const result = yield uploadFile(
|
|
1192
|
+
file,
|
|
1193
|
+
document,
|
|
1194
|
+
(state) => progressCallback(id, state)
|
|
1195
|
+
);
|
|
1196
|
+
if (result) {
|
|
1197
|
+
const notify = yield this.notifyUploaded(document.id);
|
|
1198
|
+
if (notify.errors) {
|
|
1199
|
+
progressCallback(id, {
|
|
1200
|
+
type: "errored",
|
|
1201
|
+
payload: {
|
|
1202
|
+
errors
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
progressCallback(id, {
|
|
1208
|
+
type: "completed",
|
|
1209
|
+
payload: {
|
|
1210
|
+
document: notify.document
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
create(params) {
|
|
1217
|
+
return __async(this, null, function* () {
|
|
1218
|
+
return this.graphQLRequest(CREATE_DOCUMENT_MUTATION, {
|
|
1219
|
+
input: {
|
|
1220
|
+
document: {
|
|
1221
|
+
filename: params.filename,
|
|
1222
|
+
mime_type: params.mime_type,
|
|
1223
|
+
size: params.size
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}).then((d) => {
|
|
1227
|
+
var _a;
|
|
1228
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.createDocument) || {};
|
|
1229
|
+
});
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
notifyUploaded(id) {
|
|
1233
|
+
return __async(this, null, function* () {
|
|
1234
|
+
return this.graphQLRequest(NOTIFY_UPLOADED_DOCUMENT_MUTATION, {
|
|
1235
|
+
input: {
|
|
1236
|
+
id
|
|
1237
|
+
}
|
|
1238
|
+
}).then((d) => {
|
|
1239
|
+
var _a;
|
|
1240
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.notifyUploadedDocument) || {};
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
destroy(id) {
|
|
1245
|
+
return __async(this, null, function* () {
|
|
1246
|
+
return this.graphQLRequest(DELETE_DOCUMENT_MUTATION, {
|
|
1247
|
+
input: {
|
|
1248
|
+
id
|
|
1249
|
+
}
|
|
1250
|
+
}).then((d) => {
|
|
1251
|
+
var _a;
|
|
1252
|
+
return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.deleteDocument) || {};
|
|
1253
|
+
});
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1258
|
+
0 && (module.exports = {
|
|
1259
|
+
FileManager,
|
|
1260
|
+
FilePicker
|
|
1261
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/file-input",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"react-dropzone": "14.2.3",
|
|
19
|
-
"@raketa-builder/ui": "1.0
|
|
19
|
+
"@raketa-builder/ui": "1.1.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@biomejs/biome": "1.5.2",
|