@raketa-builder/file-input 0.7.0 → 1.0.3

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 DELETED
@@ -1,2062 +0,0 @@
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 __commonJS = (cb, mod) => function __require() {
26
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
- };
28
- var __export = (target, all) => {
29
- for (var name in all)
30
- __defProp(target, name, { get: all[name], enumerable: true });
31
- };
32
- var __copyProps = (to, from, except, desc) => {
33
- if (from && typeof from === "object" || typeof from === "function") {
34
- for (let key of __getOwnPropNames(from))
35
- if (!__hasOwnProp.call(to, key) && key !== except)
36
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
37
- }
38
- return to;
39
- };
40
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
41
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
- mod
43
- ));
44
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
- var __async = (__this, __arguments, generator) => {
46
- return new Promise((resolve, reject) => {
47
- var fulfilled = (value) => {
48
- try {
49
- step(generator.next(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var rejected = (value) => {
55
- try {
56
- step(generator.throw(value));
57
- } catch (e) {
58
- reject(e);
59
- }
60
- };
61
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
62
- step((generator = generator.apply(__this, __arguments)).next());
63
- });
64
- };
65
-
66
- // ../ui/dist/index.js
67
- var require_dist = __commonJS({
68
- "../ui/dist/index.js"(exports, module2) {
69
- "use strict";
70
- var __create2 = Object.create;
71
- var __defProp2 = Object.defineProperty;
72
- var __defProps2 = Object.defineProperties;
73
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
74
- var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
75
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
76
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
77
- var __getProtoOf2 = Object.getPrototypeOf;
78
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
79
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
80
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
81
- var __spreadValues2 = (a, b) => {
82
- for (var prop in b || (b = {}))
83
- if (__hasOwnProp2.call(b, prop))
84
- __defNormalProp2(a, prop, b[prop]);
85
- if (__getOwnPropSymbols2)
86
- for (var prop of __getOwnPropSymbols2(b)) {
87
- if (__propIsEnum2.call(b, prop))
88
- __defNormalProp2(a, prop, b[prop]);
89
- }
90
- return a;
91
- };
92
- var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
93
- var __objRest = (source, exclude) => {
94
- var target = {};
95
- for (var prop in source)
96
- if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
97
- target[prop] = source[prop];
98
- if (source != null && __getOwnPropSymbols2)
99
- for (var prop of __getOwnPropSymbols2(source)) {
100
- if (exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop))
101
- target[prop] = source[prop];
102
- }
103
- return target;
104
- };
105
- var __export2 = (target, all) => {
106
- for (var name in all)
107
- __defProp2(target, name, { get: all[name], enumerable: true });
108
- };
109
- var __copyProps2 = (to, from, except, desc) => {
110
- if (from && typeof from === "object" || typeof from === "function") {
111
- for (let key of __getOwnPropNames2(from))
112
- if (!__hasOwnProp2.call(to, key) && key !== except)
113
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
114
- }
115
- return to;
116
- };
117
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
118
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
119
- mod
120
- ));
121
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
122
- var src_exports2 = {};
123
- __export2(src_exports2, {
124
- Button: () => Button_default,
125
- CategoriesMenu: () => CategoriesMenu_default,
126
- Col: () => Col,
127
- Container: () => Container_default,
128
- DataGrid: () => DataGrid_default,
129
- DefaultAvatar: () => DefaultAvatar_default,
130
- Field: () => Field_default,
131
- FormGroup: () => FormGroup_default,
132
- H: () => H_default,
133
- Handle: () => Handle_default,
134
- Hint: () => Hint_default,
135
- ImageAvatar: () => ImageAvatar_default,
136
- Input: () => Input_default,
137
- Label: () => Label_default,
138
- LanguageSwitcher: () => LanguageSwitcher_default,
139
- Modal: () => Modal_default,
140
- NavItem: () => NavItem,
141
- Navigation: () => Navigation,
142
- P: () => P_default,
143
- PageTitle: () => PageTitle_default,
144
- Pagination: () => Pagination_default,
145
- Panel: () => Panel,
146
- PanelContent: () => PanelContent,
147
- PanelTitle: () => PanelTitle,
148
- Row: () => Row,
149
- Select: () => Select_default,
150
- Shift: () => Shift,
151
- Stack: () => Stack_default,
152
- Tabs: () => Tabs_default,
153
- Textarea: () => Textarea_default,
154
- Toolbar: () => Toolbar_default,
155
- cn: () => cn6,
156
- theme: () => theme_default
157
- });
158
- module2.exports = __toCommonJS2(src_exports2);
159
- var base = 14;
160
- var fraction = 1.25;
161
- var small = base / fraction;
162
- var tiny = small / fraction;
163
- var medium = base * fraction;
164
- var large = medium * fraction;
165
- var xlarge = large * fraction;
166
- var xxlarge = xlarge * fraction;
167
- var huge = xxlarge * fraction;
168
- var theme = {
169
- font: {
170
- tiny: `${tiny}px`,
171
- small: `${small}px`,
172
- base: `${base}px`,
173
- medium: `${medium}px`,
174
- large: `${large}px`,
175
- xlarge: `${xlarge}px`,
176
- xxlarge: `${xxlarge}px`,
177
- huge: `${huge}px`,
178
- line: 1.5
179
- },
180
- colors: {
181
- trueBlack: "#000",
182
- black: "#2C2C2C",
183
- darkerGray: "#4B4B4B",
184
- darkGray: "#6E6E6E",
185
- gray: "#B3B3B3",
186
- lightGray: "#E1E1E1",
187
- lighterGray: "#F5F5F5",
188
- white: "#FAFAFA",
189
- trueWhite: "#fff",
190
- primaryDarker: "#095aba",
191
- primaryDark: "#0d66d0",
192
- primary: "#1473e6",
193
- primaryRGB06: "rgba(20, 115, 230, 0.6)",
194
- primaryLight: "#2680eb",
195
- successDarker: "#107154",
196
- successDark: "#12805c",
197
- success: "#268e6c",
198
- successLight: "#2d9d78",
199
- dangerDarker: "#bb121a",
200
- dangerDark: "#c9252d",
201
- danger: "#d7373f",
202
- dangerLight: "#e34850"
203
- }
204
- };
205
- var theme_default = theme;
206
- var import_react8 = __toESM2(require("react"));
207
- function cn6() {
208
- return Array.from(arguments).filter(Boolean).map(String).join(" ");
209
- }
210
- var import_jsx_runtime8 = require("react/jsx-runtime");
211
- var H2 = (_a) => {
212
- var _b = _a, { size = "base", className = "" } = _b, props = __objRest(_b, ["size", "className"]);
213
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
214
- "div",
215
- __spreadValues2({
216
- className: cn6("r-reset", "r-heading", `r-fs-${size}`, className)
217
- }, props)
218
- );
219
- };
220
- var H_default = H2;
221
- var import_react22 = __toESM2(require("react"));
222
- var import_jsx_runtime22 = require("react/jsx-runtime");
223
- var P = (_a) => {
224
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
225
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-paragraph", className) }, props));
226
- };
227
- var P_default = P;
228
- var import_react32 = __toESM2(require("react"));
229
- var import_jsx_runtime32 = require("react/jsx-runtime");
230
- var Button4 = (_a) => {
231
- var _b = _a, {
232
- as = "button",
233
- size = "md",
234
- variant = "primary",
235
- className,
236
- type = "button"
237
- } = _b, rest = __objRest(_b, [
238
- "as",
239
- "size",
240
- "variant",
241
- "className",
242
- "type"
243
- ]);
244
- const Component = as;
245
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
246
- Component,
247
- __spreadValues2({
248
- type,
249
- className: cn6(
250
- "r-reset",
251
- "r-reset-button",
252
- "r-button",
253
- `r-button-${size}`,
254
- `r-button-${variant}`,
255
- className
256
- )
257
- }, rest)
258
- );
259
- };
260
- Button4.variants = ["primary", "secondary", "success", "danger"];
261
- Button4.sizes = {
262
- sm: "sm",
263
- md: "md",
264
- lg: "lg"
265
- };
266
- var Button_default = Button4;
267
- var import_react42 = __toESM2(require("react"));
268
- var import_jsx_runtime42 = require("react/jsx-runtime");
269
- var TabsWrapper = (_a) => {
270
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
271
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", __spreadProps2(__spreadValues2({}, props), { className: cn6("r-reset", "r-tab-wrapper", className) }));
272
- };
273
- var Tab = (_a) => {
274
- var _b = _a, { active, className } = _b, props = __objRest(_b, ["active", "className"]);
275
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
276
- "button",
277
- __spreadValues2({
278
- className: cn6(
279
- `r-reset-button r-tab-button ${active ? "r-tab-button-active" : ""}`,
280
- className
281
- )
282
- }, props)
283
- );
284
- };
285
- var Tabs = ({ initial = 0, children }) => {
286
- const [current, setCurrent] = import_react42.default.useState(initial);
287
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_react42.default.Fragment, { children: [
288
- /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(TabsWrapper, { children: children.map((child, idx) => /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
289
- Tab,
290
- {
291
- type: "button",
292
- active: idx === current,
293
- onClick: () => setCurrent(idx),
294
- children: child.props.title
295
- },
296
- idx
297
- )) }),
298
- children[current]
299
- ] });
300
- };
301
- var Tabs_default = Tabs;
302
- var import_react52 = __toESM2(require("react"));
303
- var import_jsx_runtime52 = require("react/jsx-runtime");
304
- var Input4 = (_a) => {
305
- var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
306
- return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("input", __spreadValues2({ className: cn6("r-reset", "r-input", className) }, rest));
307
- };
308
- var Input_default = Input4;
309
- var import_react62 = __toESM2(require("react"));
310
- var import_jsx_runtime62 = require("react/jsx-runtime");
311
- var Textarea = (_a) => {
312
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
313
- return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
314
- "textarea",
315
- __spreadValues2({
316
- className: cn6("r-reset", "r-input r-textarea", className)
317
- }, props)
318
- );
319
- };
320
- var Textarea_default = Textarea;
321
- var import_react72 = __toESM2(require("react"));
322
- var import_jsx_runtime72 = require("react/jsx-runtime");
323
- var Select = (_a) => {
324
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
325
- return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)("select", __spreadValues2({ className: cn6("r-reset", "r-input r-select", className) }, props));
326
- };
327
- var Select_default = Select;
328
- var import_react82 = __toESM2(require("react"));
329
- var import_jsx_runtime82 = require("react/jsx-runtime");
330
- var Hint2 = (_a) => {
331
- var _b = _a, { type, className } = _b, props = __objRest(_b, ["type", "className"]);
332
- return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-form-group", className) }, props));
333
- };
334
- var FormGroup_default = Hint2;
335
- var import_react9 = __toESM2(require("react"));
336
- var import_jsx_runtime9 = require("react/jsx-runtime");
337
- var Label2 = (_a) => {
338
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
339
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
340
- "label",
341
- __spreadValues2({
342
- className: cn6("r-reset", "r-fs-small r-label", className)
343
- }, props)
344
- );
345
- };
346
- var Label_default = Label2;
347
- var import_react11 = __toESM2(require("react"));
348
- var import_react10 = __toESM2(require("react"));
349
- var import_jsx_runtime10 = require("react/jsx-runtime");
350
- var Hint22 = (_a) => {
351
- var _b = _a, { type, className } = _b, props = __objRest(_b, ["type", "className"]);
352
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
353
- "div",
354
- __spreadValues2({
355
- className: cn6(
356
- "r-reset",
357
- "r-fs-small r-hint",
358
- className,
359
- type === "error" && "r-hint-error"
360
- )
361
- }, props)
362
- );
363
- };
364
- var Hint_default = Hint22;
365
- var import_jsx_runtime11 = require("react/jsx-runtime");
366
- var Field = (_a) => {
367
- var _b = _a, {
368
- as = "input",
369
- r,
370
- name,
371
- label,
372
- hint = "",
373
- error = "",
374
- wrapperProps
375
- } = _b, props = __objRest(_b, [
376
- "as",
377
- "r",
378
- "name",
379
- "label",
380
- "hint",
381
- "error",
382
- "wrapperProps"
383
- ]);
384
- const types = {
385
- input: Input_default,
386
- select: Select_default,
387
- textarea: Textarea_default
388
- };
389
- const Component = types[as];
390
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(FormGroup_default, __spreadProps2(__spreadValues2({}, wrapperProps), { children: [
391
- label && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Label_default, { htmlFor: name, children: label }),
392
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, __spreadValues2({ ref: r, id: name, name }, props)),
393
- hint && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Hint_default, { children: hint }),
394
- error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Hint_default, { type: "error", children: error })
395
- ] }));
396
- };
397
- var Field_default = Field;
398
- var import_react12 = __toESM2(require("react"));
399
- var import_jsx_runtime12 = require("react/jsx-runtime");
400
- var Toolbar = (_a) => {
401
- var _b = _a, { mb, className } = _b, props = __objRest(_b, ["mb", "className"]);
402
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
403
- "div",
404
- __spreadValues2({
405
- style: { marginBottom: mb || 0 },
406
- className: cn6("r-reset", "r-toolbar", className)
407
- }, props)
408
- );
409
- };
410
- var Toolbar_default = Toolbar;
411
- var import_react13 = __toESM2(require("react"));
412
- var import_jsx_runtime13 = require("react/jsx-runtime");
413
- var Stack5 = (_a) => {
414
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
415
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", __spreadValues2({ className: cn6("r-stack", className) }, props));
416
- };
417
- var Stack_default = Stack5;
418
- var import_react14 = __toESM2(require("react"));
419
- var import_jsx_runtime14 = require("react/jsx-runtime");
420
- var Container = (_a) => {
421
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
422
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-container", className) }, props));
423
- };
424
- var Container_default = Container;
425
- var import_react15 = __toESM2(require("react"));
426
- var import_jsx_runtime15 = require("react/jsx-runtime");
427
- var Panel = (_a) => {
428
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
429
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-panel", className) }, props));
430
- };
431
- var PanelTitle = (_a) => {
432
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
433
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-panel-title", className) }, props));
434
- };
435
- var PanelContent = (_a) => {
436
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
437
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", __spreadValues2({ className: cn6("r-panel-content", className) }, props));
438
- };
439
- var import_react16 = __toESM2(require("react"));
440
- var import_jsx_runtime16 = require("react/jsx-runtime");
441
- var Handle = (_a) => {
442
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
443
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-drag-handle", className) }, props));
444
- };
445
- var Handle_default = Handle;
446
- var import_react17 = __toESM2(require("react"));
447
- var import_jsx_runtime17 = require("react/jsx-runtime");
448
- var Overlay = (_a) => {
449
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
450
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-overlay", className) }, props));
451
- };
452
- var Wrapper = (_a) => {
453
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
454
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal", className) }, props));
455
- };
456
- var Inner = (_a) => {
457
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
458
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-inner", className) }, props));
459
- };
460
- var TitleBar = (_a) => {
461
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
462
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-title-bar", className) }, props));
463
- };
464
- var Title = (_a) => {
465
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
466
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-title", className) }, props));
467
- };
468
- var CloseButton = (_a) => {
469
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
470
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
471
- "button",
472
- __spreadValues2({
473
- type: "button",
474
- className: cn6("r-reset-button r-modal-close-btn", className)
475
- }, props)
476
- );
477
- };
478
- var FooterBar = (_a) => {
479
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
480
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-footer-bar", className) }, props));
481
- };
482
- var Content = (_a) => {
483
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
484
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-content", className) }, props));
485
- };
486
- function checkForChanges(hasChanges, onClose) {
487
- if (!hasChanges) {
488
- onClose();
489
- return;
490
- }
491
- if (!confirm(
492
- "You\u2019ve made changes to the widget. Are you sure you want to cancel?"
493
- ))
494
- return;
495
- onClose();
496
- }
497
- var Modal2 = (_a) => {
498
- var _b = _a, {
499
- title,
500
- children,
501
- customWrapper,
502
- FooterContent,
503
- onClose,
504
- areChanges
505
- } = _b, rest = __objRest(_b, [
506
- "title",
507
- "children",
508
- "customWrapper",
509
- "FooterContent",
510
- "onClose",
511
- "areChanges"
512
- ]);
513
- const ModalWrapper = customWrapper ? customWrapper : Wrapper;
514
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react17.default.Fragment, { children: [
515
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, {}),
516
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModalWrapper, __spreadProps2(__spreadValues2({}, rest), { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Inner, { children: [
517
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(TitleBar, { children: [
518
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Title, { children: title }),
519
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
520
- CloseButton,
521
- {
522
- type: "button",
523
- onClick: () => checkForChanges(areChanges, onClose),
524
- children: "\xD7"
525
- }
526
- )
527
- ] }),
528
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Content, { children }),
529
- FooterContent && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterBar, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterContent, {}) })
530
- ] }) }))
531
- ] });
532
- };
533
- var Modal_default = Modal2;
534
- var import_react18 = __toESM2(require("react"));
535
- var import_jsx_runtime18 = require("react/jsx-runtime");
536
- var Wrapper2 = (_a) => {
537
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
538
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", __spreadValues2({ className: cn6("r-reset", className) }, props));
539
- };
540
- var DataGrid = ({ list, header, row }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Wrapper2, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("table", { className: "r-table", children: [
541
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tr", { children: header() }) }),
542
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tbody", { children: list.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("tr", { children: row(item) }, item.id || idx)) })
543
- ] }) });
544
- var DataGrid_default = DataGrid;
545
- var import_react19 = __toESM2(require("react"));
546
- var import_jsx_runtime19 = require("react/jsx-runtime");
547
- var getShift = (s) => {
548
- const SHIFTS = {
549
- 1: "2 / span 10",
550
- 2: "3 / span 8",
551
- 3: "4 / span 6"
552
- };
553
- return SHIFTS[s];
554
- };
555
- var Shift = (_a) => {
556
- var _b = _a, { s, className } = _b, props = __objRest(_b, ["s", "className"]);
557
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
558
- "div",
559
- __spreadValues2({
560
- style: {
561
- gridColumn: getShift(s) || "2 / span 10"
562
- },
563
- className: cn6("r-reset", className)
564
- }, props)
565
- );
566
- };
567
- var Col = (_a) => {
568
- var _b = _a, { s, className } = _b, props = __objRest(_b, ["s", "className"]);
569
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
570
- "div",
571
- __spreadValues2({
572
- style: {
573
- gridColumn: `span ${s || "12"}`
574
- },
575
- className: cn6("r-reset", className)
576
- }, props)
577
- );
578
- };
579
- var Row = (_a) => {
580
- var _b = _a, { gutter, className } = _b, props = __objRest(_b, ["gutter", "className"]);
581
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
582
- "div",
583
- __spreadValues2({
584
- style: {
585
- columnGap: gutter || "1em",
586
- rowGap: gutter || "1em"
587
- },
588
- className: cn6("r-reset", "r-row", className)
589
- }, props)
590
- );
591
- };
592
- var import_react20 = __toESM2(require("react"));
593
- var import_jsx_runtime20 = require("react/jsx-runtime");
594
- var Navigation = (_a) => {
595
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
596
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-navigation", className) }, props));
597
- };
598
- var NavItem = (_a) => {
599
- var _b = _a, { active, className } = _b, props = __objRest(_b, ["active", "className"]);
600
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
601
- "div",
602
- __spreadValues2({
603
- className: cn6(
604
- "r-reset",
605
- "r-navigation-item",
606
- active ? "r-navigation-item-active" : "",
607
- className
608
- )
609
- }, props)
610
- );
611
- };
612
- var import_react21 = __toESM2(require("react"));
613
- var import_jsx_runtime21 = require("react/jsx-runtime");
614
- var Wrapper3 = (_a) => {
615
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
616
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-page-title", className) }, props));
617
- };
618
- var PageTitle = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Wrapper3, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
619
- H_default,
620
- {
621
- as: "h1",
622
- size: "xlarge",
623
- style: { fontFamily: "sans-serif", fontWeight: 700 },
624
- children
625
- }
626
- ) });
627
- var PageTitle_default = PageTitle;
628
- var import_react222 = __toESM2(require("react"));
629
- var import_jsx_runtime222 = require("react/jsx-runtime");
630
- var Wrapper4 = (_a) => {
631
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
632
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-pagination", className) }, props));
633
- };
634
- var Prev = ({ LinkComponent, router, currentPage }) => {
635
- if (currentPage === 1) {
636
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)("span", { children: "Previous" });
637
- }
638
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)(
639
- LinkComponent,
640
- {
641
- href: {
642
- pathname: router.pathname,
643
- query: __spreadValues2(__spreadValues2({}, router.query), { page: currentPage - 1 })
644
- },
645
- children: "Previous"
646
- }
647
- );
648
- };
649
- var Next = ({ currentPage, pagesCount, LinkComponent, router }) => {
650
- if (currentPage === pagesCount) {
651
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)("span", { children: "Next" });
652
- }
653
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)(
654
- LinkComponent,
655
- {
656
- href: {
657
- pathname: router.pathname,
658
- query: __spreadValues2(__spreadValues2({}, router.query), { page: currentPage + 1 })
659
- },
660
- children: "Next"
661
- }
662
- );
663
- };
664
- var Pagination = ({ pagination, LinkComponent, router }) => {
665
- const { currentPage, pagesCount } = pagination;
666
- const pages = Array(pagesCount).fill(1);
667
- if (pagesCount <= 1 || router === null) {
668
- return "";
669
- }
670
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsxs)(Wrapper4, { children: [
671
- /* @__PURE__ */ (0, import_jsx_runtime222.jsx)(
672
- Prev,
673
- {
674
- LinkComponent,
675
- router,
676
- currentPage
677
- }
678
- ),
679
- pages.map((_, idx) => {
680
- const pageNum = idx + 1;
681
- if (pageNum === currentPage) {
682
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)("span", { children: pageNum }, pageNum);
683
- } else {
684
- return /* @__PURE__ */ (0, import_jsx_runtime222.jsx)(
685
- LinkComponent,
686
- {
687
- href: {
688
- pathname: router.pathname,
689
- query: __spreadValues2(__spreadValues2({}, router.query), { page: pageNum })
690
- },
691
- children: pageNum
692
- },
693
- pageNum
694
- );
695
- }
696
- }),
697
- /* @__PURE__ */ (0, import_jsx_runtime222.jsx)(
698
- Next,
699
- {
700
- LinkComponent,
701
- router,
702
- currentPage,
703
- pagesCount
704
- }
705
- )
706
- ] });
707
- };
708
- var Pagination_default = Pagination;
709
- var import_react23 = __toESM2(require("react"));
710
- var import_jsx_runtime23 = require("react/jsx-runtime");
711
- var LanguageSwitcherWrapper = (_a) => {
712
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
713
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-language-switcher", className) }, props));
714
- };
715
- var LanguageSwitcherMenu = (_a) => {
716
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
717
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-language-menu", className) }, props));
718
- };
719
- var LanguageSwitcherItem = (_a) => {
720
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
721
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-language-item", className) }, props));
722
- };
723
- var LanguageSwitcherNewItem = (_a) => {
724
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
725
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-language-new-item", className) }, props));
726
- };
727
- var LanguageSwitcherCurrent = (_a) => {
728
- var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
729
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
730
- "div",
731
- __spreadValues2({
732
- className: cn6("r-reset", "r-language-current-item", className)
733
- }, props)
734
- );
735
- };
736
- var LanguageSwitcherItemComponent = ({ path, label }) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(LanguageSwitcherItem, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("a", { href: path, children: label }) });
737
- var LanguageSwitcherNewItemComponent = ({ path, label }) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(LanguageSwitcherNewItem, { children: [
738
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { children: label }),
739
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("a", { href: path, children: "+" })
740
- ] });
741
- var LanguageSwitcher = ({ current, navigation }) => {
742
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(LanguageSwitcherWrapper, { children: [
743
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(LanguageSwitcherCurrent, { children: current }),
744
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(LanguageSwitcherMenu, { "data-switcher": true, children: navigation.map((navItem, idx) => {
745
- const LinkComponent = navItem.newItem ? LanguageSwitcherNewItemComponent : LanguageSwitcherItemComponent;
746
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
747
- LinkComponent,
748
- {
749
- path: navItem.path,
750
- label: navItem.label
751
- },
752
- idx
753
- );
754
- }) })
755
- ] });
756
- };
757
- var LanguageSwitcher_default = LanguageSwitcher;
758
- var import_react24 = __toESM2(require("react"));
759
- var import_jsx_runtime24 = require("react/jsx-runtime");
760
- var ImageAvatar = (_a) => {
761
- var _b = _a, { size = "24px", className } = _b, props = __objRest(_b, ["size", "className"]);
762
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
763
- "img",
764
- __spreadValues2({
765
- alt: "",
766
- style: {
767
- width: size || "2.5rem",
768
- height: size || "2.5rem"
769
- },
770
- className: cn6("r-reset", "r-image-avatar", className)
771
- }, props)
772
- );
773
- };
774
- var ImageAvatar_default = ImageAvatar;
775
- var import_react25 = __toESM2(require("react"));
776
- var import_jsx_runtime25 = require("react/jsx-runtime");
777
- var AVATAR_COLORS = [
778
- "darkkhaki",
779
- "palevioletred",
780
- "mediumseagreen",
781
- "olivedrab",
782
- "steelblue",
783
- "salmon",
784
- "indianred",
785
- "mediumpurple",
786
- "coral",
787
- "rosybrown",
788
- "lightseagreen",
789
- "plum",
790
- "tan"
791
- ];
792
- var initialsToColor = (initials, colors) => {
793
- let asciiVal = initials.charCodeAt(0);
794
- asciiVal += initials.charCodeAt(1);
795
- let colorIndex = asciiVal % colors.length;
796
- return colors[colorIndex];
797
- };
798
- var DefaultAvatarStyles = (_a) => {
799
- var _b = _a, { initials, size, className } = _b, props = __objRest(_b, ["initials", "size", "className"]);
800
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
801
- "div",
802
- __spreadValues2({
803
- style: {
804
- width: size || "2.5rem",
805
- height: size || "2.5rem",
806
- fontSize: `calc(${size} * 0.4)`,
807
- backgroundColor: initialsToColor(initials, AVATAR_COLORS)
808
- },
809
- className: cn6("r-reset", "r-default-avatar", className)
810
- }, props)
811
- );
812
- };
813
- var DefaultAvatar = (_a) => {
814
- var _b = _a, { initials = "AA", size = "24px" } = _b, props = __objRest(_b, ["initials", "size"]);
815
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DefaultAvatarStyles, __spreadProps2(__spreadValues2({ initials, size }, props), { children: initials }));
816
- };
817
- var DefaultAvatar_default = DefaultAvatar;
818
- var import_react26 = __toESM2(require("react"));
819
- var import_jsx_runtime26 = require("react/jsx-runtime");
820
- var IconsWrapper = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "r-reset r-categories-icons-wrapper", children: [
821
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
822
- "img",
823
- {
824
- style: {
825
- color: "#fff",
826
- width: "24px",
827
- height: "24px",
828
- filter: "invert(1)"
829
- },
830
- alt: "directions",
831
- src: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItZ3JpZCI+PHJlY3QgeD0iMyIgeT0iMyIgd2lkdGg9IjciIGhlaWdodD0iNyI+PC9yZWN0PjxyZWN0IHg9IjE0IiB5PSIzIiB3aWR0aD0iNyIgaGVpZ2h0PSI3Ij48L3JlY3Q+PHJlY3QgeD0iMTQiIHk9IjE0IiB3aWR0aD0iNyIgaGVpZ2h0PSI3Ij48L3JlY3Q+PHJlY3QgeD0iMyIgeT0iMTQiIHdpZHRoPSI3IiBoZWlnaHQ9IjciPjwvcmVjdD48L3N2Zz4="
832
- }
833
- ),
834
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
835
- "img",
836
- {
837
- className: "r-reset r-category-chevron",
838
- alt: "directions",
839
- src: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjIiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAyMiAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTIxIDExLjVMMTEgMS41TDEgMTEuNSIgc3Ryb2tlPSIjMEMwQTA5IiBzdHJva2Utd2lkdGg9IjIiLz4KPC9zdmc+Cg=="
840
- }
841
- )
842
- ] });
843
- var Title2 = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-categories-title", children: "Categories" });
844
- var CategoriesInner = (_a) => {
845
- var props = __objRest(_a, []);
846
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadProps2(__spreadValues2({}, props), { className: "r-reset r-categories-inner" }));
847
- };
848
- var CategoriesHiddenMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-reset r-categories-hidden-menu", children: paths.map(({ title, link }, idx) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: link, className: "r-reset r-category-link", children: title }, `${idx}-${link}`)) });
849
- var CategoriesMenuWrapper = (_a) => {
850
- var props = __objRest(_a, []);
851
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadValues2({ className: "r-reset r-categories-menu" }, props));
852
- };
853
- var CategoriesMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(CategoriesMenuWrapper, { children: [
854
- /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(CategoriesInner, { children: [
855
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(IconsWrapper, {}),
856
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Title2, {})
857
- ] }),
858
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CategoriesHiddenMenu, { paths })
859
- ] });
860
- var CategoriesMenu_default = CategoriesMenu;
861
- }
862
- });
863
-
864
- // src/index.js
865
- var src_exports = {};
866
- __export(src_exports, {
867
- FileManager: () => FileManager,
868
- FilePicker: () => FilePicker_default
869
- });
870
- module.exports = __toCommonJS(src_exports);
871
-
872
- // src/FilePicker/index.js
873
- var import_react7 = __toESM(require("react"));
874
- var import_ui7 = __toESM(require_dist());
875
-
876
- // src/FilePicker/FileCategory.js
877
- var VIDEO = ["video/3gpp", "video/3gpp2", "video/mp4", "video/webm"];
878
- var AUDIO = [
879
- "audio/webm",
880
- "audio/wav",
881
- "audio/mpeg",
882
- "audio/aac",
883
- "audio/midi",
884
- "audio/x-midi",
885
- "audio/ogg",
886
- "audio/3gpp",
887
- "audio/3gpp2",
888
- "audio/m4a"
889
- ];
890
- var DOCUMENT = [
891
- "application/pdf",
892
- "application/msword",
893
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
894
- "application/vnd.ms-excel",
895
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
896
- "application/vnd.ms-powerpoint",
897
- "application/vnd.openxmlformats-officedocument.presentationml.presentation",
898
- "text/plain",
899
- "application/epub+zip",
900
- "application/x-mobipocket-ebook",
901
- "application/rtf",
902
- "text/csv",
903
- "application/vnd.apple.pages",
904
- "application/vnd.apple.numbers",
905
- "application/vnd.apple.keynote"
906
- ];
907
- var IMAGE = [
908
- "image/png",
909
- "image/x-png",
910
- "image/vnd.mozilla.apng",
911
- "image/jpeg",
912
- "image/svg+xml",
913
- "image/gif",
914
- "image/avif",
915
- "image/webp",
916
- "application/postscript",
917
- "mage/heic",
918
- "mage/heic-sequence"
919
- ];
920
- var ARCHIVE = [
921
- "application/zip",
922
- "application/gzip",
923
- "application/x-gtar",
924
- "application/x-tar",
925
- "application/x-rar-compressed",
926
- "application/x-7z-compressed"
927
- ];
928
- var MIME_TYPES = IMAGE.concat(VIDEO).concat(DOCUMENT).concat(AUDIO).concat(ARCHIVE);
929
- var MAPPING = {
930
- video: VIDEO,
931
- document: DOCUMENT,
932
- image: IMAGE,
933
- audio: AUDIO,
934
- archive: ARCHIVE,
935
- other: []
936
- };
937
- var FILE_CATEGORIES = {
938
- document: "Document",
939
- archive: "Archive",
940
- image: "Image",
941
- video: "Video",
942
- audio: "Audio",
943
- other: "Other"
944
- };
945
- function toMimeTypes(fileCategory) {
946
- return MAPPING[fileCategory] || [];
947
- }
948
- function toExcludedMimeTypes(fileCategory) {
949
- if (fileCategory === "other") {
950
- return MIME_TYPES;
951
- }
952
- return [];
953
- }
954
- function toFileCategory(mimeType, format = "robot") {
955
- let fileCategory = null;
956
- Object.keys(FILE_CATEGORIES).forEach((key) => {
957
- if (fileCategory) {
958
- return;
959
- }
960
- if (MAPPING[key].find((mt) => mt === mimeType)) {
961
- fileCategory = key;
962
- }
963
- });
964
- if (!fileCategory) {
965
- fileCategory = "other";
966
- }
967
- if (format === "human") {
968
- return FILE_CATEGORIES[fileCategory] || fileCategory;
969
- }
970
- return fileCategory;
971
- }
972
- function fileCategoriesOptions() {
973
- return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
974
- }
975
- function sanitizeFileCategory(fileCategory) {
976
- if (fileCategory === "other") {
977
- return null;
978
- }
979
- if (Object.keys(FILE_CATEGORIES).includes(fileCategory)) {
980
- return fileCategory;
981
- }
982
- return null;
983
- }
984
-
985
- // src/FilePicker/stateManagement.js
986
- function mimeTypes(category) {
987
- return toMimeTypes(category);
988
- }
989
- function excludeMimeTypes(category) {
990
- return toExcludedMimeTypes(category);
991
- }
992
- function initialState(initialSelected, initialCategory) {
993
- return {
994
- open: false,
995
- fetching: false,
996
- selected: initialSelected,
997
- uploads: [],
998
- files: {
999
- initial: true,
1000
- list: [],
1001
- nextCursor: null,
1002
- filters: {
1003
- keyword: "",
1004
- category: initialCategory || ""
1005
- }
1006
- }
1007
- };
1008
- }
1009
- function initialUploadState(file, allowedMimeTypes) {
1010
- if (allowedMimeTypes.length === 0 || allowedMimeTypes.includes(file.type)) {
1011
- return {
1012
- type: "pending",
1013
- payload: {}
1014
- };
1015
- }
1016
- return {
1017
- type: "rejected",
1018
- payload: {
1019
- errors: [`Files of type "${file.type}" are not supported.`]
1020
- }
1021
- };
1022
- }
1023
- function uploadFiles(fileManager, files, allowedFileCategory, setState) {
1024
- const allowedMimeTypes = toMimeTypes(allowedFileCategory);
1025
- const fileUploads = files.map((file) => ({
1026
- file,
1027
- id: (Math.random() * 1e6).toFixed(0),
1028
- state: initialUploadState(file, allowedMimeTypes)
1029
- }));
1030
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1031
- uploads: [...currentState.uploads, ...fileUploads]
1032
- }));
1033
- fileUploads.filter((fu) => fu.state.type === "pending").forEach(
1034
- (fileUpload) => fileManager.createAndUpload(
1035
- fileUpload,
1036
- (tmpId, newState) => setState((currentState) => {
1037
- if (newState.type === "completed") {
1038
- if (currentState.files.list.find(
1039
- (file) => file.id === newState.payload.document.id
1040
- )) {
1041
- return currentState;
1042
- }
1043
- return __spreadProps(__spreadValues({}, currentState), {
1044
- uploads: currentState.uploads.filter(
1045
- (upload) => upload.id !== tmpId
1046
- ),
1047
- files: __spreadProps(__spreadValues({}, currentState.files), {
1048
- list: [
1049
- __spreadValues({}, newState.payload.document),
1050
- ...currentState.files.list
1051
- ]
1052
- })
1053
- });
1054
- }
1055
- const newUploads = currentState.uploads.map((upload) => {
1056
- if (upload.id === tmpId) {
1057
- return __spreadProps(__spreadValues({}, upload), { state: newState });
1058
- }
1059
- return upload;
1060
- });
1061
- return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
1062
- })
1063
- )
1064
- );
1065
- }
1066
- function loadFiles(fileManager, state, setState) {
1067
- return __async(this, null, function* () {
1068
- if (state.files.initial) {
1069
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1070
- open: true,
1071
- fetching: true
1072
- }));
1073
- const resp = yield fileManager.all({
1074
- mimeTypes: mimeTypes(state.files.filters.category),
1075
- excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
1076
- });
1077
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1078
- fetching: false,
1079
- files: {
1080
- initial: false,
1081
- list: resp.list || [],
1082
- nextCursor: resp.pagination.cursor,
1083
- filters: {
1084
- keyword: "",
1085
- category: ""
1086
- }
1087
- }
1088
- }));
1089
- } else {
1090
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1091
- open: true
1092
- }));
1093
- }
1094
- });
1095
- }
1096
- function searchFiles(fileManager, filters, state, setState) {
1097
- return __async(this, null, function* () {
1098
- if ((filters.keyword !== state.files.filters.keyword || filters.category !== state.files.filters.category) && !state.fetching) {
1099
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1100
- fetching: true
1101
- }));
1102
- const resp = yield fileManager.all({
1103
- nextCursor: null,
1104
- keyword: filters.keyword,
1105
- mimeTypes: mimeTypes(filters.category),
1106
- excludeMimeTypes: excludeMimeTypes(filters.category)
1107
- });
1108
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1109
- fetching: false,
1110
- files: {
1111
- list: [...resp.list],
1112
- nextCursor: resp.pagination.cursor,
1113
- filters: {
1114
- keyword: filters.keyword,
1115
- category: filters.category
1116
- }
1117
- }
1118
- }));
1119
- } else {
1120
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1121
- fetching: false,
1122
- files: __spreadProps(__spreadValues({}, currentState.files), {
1123
- filters: {
1124
- keyword: filters.keyword,
1125
- category: filters.category
1126
- }
1127
- })
1128
- }));
1129
- }
1130
- });
1131
- }
1132
- function deleteFile(fileManager, fileId, state, setState, onChange) {
1133
- return __async(this, null, function* () {
1134
- var _a, _b;
1135
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1136
- fetching: true
1137
- }));
1138
- const response = yield fileManager.destroy(fileId);
1139
- let removeFromList = false;
1140
- let removeSelected = false;
1141
- if (response.errors) {
1142
- alert(`Something went wrong while deleting document#${fileId}`);
1143
- }
1144
- if (!response.errors && response.document) {
1145
- removeFromList = true;
1146
- if (fileId === ((_b = (_a = state.selected) == null ? void 0 : _a.document) == null ? void 0 : _b.id)) {
1147
- removeSelected = true;
1148
- }
1149
- }
1150
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1151
- fetching: false,
1152
- selected: removeSelected ? null : currentState.selected,
1153
- files: __spreadProps(__spreadValues({}, currentState.files), {
1154
- list: currentState.files.list.filter((f) => f.id !== fileId)
1155
- })
1156
- }));
1157
- if (removeSelected) {
1158
- onChange(null);
1159
- }
1160
- });
1161
- }
1162
- function selectFile(fileId, setState) {
1163
- setState((currentState) => {
1164
- const file = currentState.files.list.find((f) => f.id === fileId);
1165
- let newSelected = null;
1166
- if (file) {
1167
- newSelected = {
1168
- document: file,
1169
- uri: `raketacloud://documents/${file.id}`
1170
- };
1171
- }
1172
- return __spreadProps(__spreadValues({}, currentState), {
1173
- selected: newSelected
1174
- });
1175
- });
1176
- }
1177
- function loadMoreFiles(fileManager, state, setState) {
1178
- if (!state.files.nextCursor) {
1179
- return null;
1180
- }
1181
- return function loadMore() {
1182
- return __async(this, null, function* () {
1183
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1184
- fetching: true
1185
- }));
1186
- const resp = yield fileManager.all({
1187
- nextCursor: state.files.nextCursor,
1188
- keyword: state.files.filters.keyword,
1189
- mimeTypes: mimeTypes(state.files.filters.category),
1190
- excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
1191
- });
1192
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1193
- fetching: false,
1194
- files: {
1195
- list: [...currentState.files.list, ...resp.list],
1196
- nextCursor: resp.pagination.cursor,
1197
- filters: __spreadValues({}, currentState.files.filters)
1198
- }
1199
- }));
1200
- });
1201
- };
1202
- }
1203
-
1204
- // src/FilePicker/Dialog.js
1205
- var import_react = __toESM(require("react"));
1206
- var import_react_dropzone = require("react-dropzone");
1207
- var import_ui = __toESM(require_dist());
1208
- var import_jsx_runtime = require("react/jsx-runtime");
1209
- var DropZone = ({ children, onDrop }) => {
1210
- const onFilesDrop = (0, import_react.useCallback)(
1211
- (acceptedFiles) => {
1212
- onDrop(acceptedFiles);
1213
- },
1214
- [onDrop]
1215
- );
1216
- const { getRootProps, getInputProps, isDragActive } = (0, import_react_dropzone.useDropzone)({
1217
- onDropAccepted: onFilesDrop,
1218
- noClick: true
1219
- });
1220
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1221
- "div",
1222
- __spreadProps(__spreadValues({
1223
- className: (0, import_ui.cn)(
1224
- "r-reset",
1225
- "r-dropzone-modal",
1226
- isDragActive ? "r-dropzone-modal-active" : ""
1227
- )
1228
- }, getRootProps()), {
1229
- children: [
1230
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", __spreadValues({}, getInputProps())),
1231
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: isDragActive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { className: "r-fs-large", children: "Drop here" }) }),
1232
- !isDragActive && children
1233
- ]
1234
- })
1235
- );
1236
- };
1237
- var Dialog = ({
1238
- disablePrimary = false,
1239
- onClose,
1240
- onPrimary,
1241
- onDrop,
1242
- children
1243
- }) => {
1244
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1245
- import_ui.Modal,
1246
- {
1247
- title: "Files",
1248
- onClose,
1249
- onDrop,
1250
- customWrapper: DropZone,
1251
- FooterContent: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1252
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1253
- import_ui.Button,
1254
- {
1255
- type: "button",
1256
- variant: "primary",
1257
- disabled: disablePrimary,
1258
- onClick: onPrimary,
1259
- children: "Select"
1260
- }
1261
- ),
1262
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { type: "button", variant: "secondary", onClick: onClose, children: "Cancel" })
1263
- ] }),
1264
- children
1265
- }
1266
- );
1267
- };
1268
- var Dialog_default = Dialog;
1269
-
1270
- // src/FilePicker/FileSearch.js
1271
- var import_react2 = __toESM(require("react"));
1272
- var import_ui2 = __toESM(require_dist());
1273
- var import_jsx_runtime2 = require("react/jsx-runtime");
1274
- var useDebunce = (value, onDebouncedChange) => {
1275
- const timerRef = import_react2.default.useRef(null);
1276
- import_react2.default.useEffect(() => {
1277
- timerRef.current = setTimeout(() => {
1278
- onDebouncedChange(value);
1279
- }, 500);
1280
- return () => {
1281
- clearTimeout(timerRef.current);
1282
- };
1283
- }, [value]);
1284
- };
1285
- var SearchInput = ({ onChange }) => {
1286
- const [q, setQ] = import_react2.default.useState("");
1287
- useDebunce(q, onChange);
1288
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1289
- import_ui2.Input,
1290
- {
1291
- placeholder: "Start typing file name...",
1292
- value: q,
1293
- onChange: (e) => {
1294
- setQ(e.target.value);
1295
- }
1296
- }
1297
- );
1298
- };
1299
- var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1300
- const onCategoryPick = (val) => {
1301
- onChange(__spreadProps(__spreadValues({}, value), {
1302
- category: val
1303
- }));
1304
- };
1305
- const onSearchTermChange = (q) => {
1306
- onChange(__spreadProps(__spreadValues({}, value), {
1307
- keyword: q
1308
- }));
1309
- };
1310
- if (allowedFileCategory) {
1311
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "r-spacing-bottom-sm", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }) });
1312
- }
1313
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1314
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }),
1315
- /* @__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: [
1316
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1317
- "button",
1318
- {
1319
- type: "button",
1320
- disabled: fetching,
1321
- className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === "" ? "r-tab-button-active" : ""}`,
1322
- onClick: () => onCategoryPick(""),
1323
- children: "All"
1324
- }
1325
- ),
1326
- fileCategoriesOptions().map((category) => {
1327
- const [key, label] = category;
1328
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1329
- "button",
1330
- {
1331
- type: "button",
1332
- disabled: fetching,
1333
- className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === key ? "r-tab-button-active" : ""}`,
1334
- onClick: () => onCategoryPick(key),
1335
- children: label
1336
- },
1337
- key
1338
- );
1339
- })
1340
- ] }) })
1341
- ] });
1342
- };
1343
- var FileSearch_default = FileSearch;
1344
-
1345
- // src/FilePicker/FileList.js
1346
- var import_react3 = __toESM(require("react"));
1347
- var import_ui3 = __toESM(require_dist());
1348
-
1349
- // src/FilePicker/utils.js
1350
- function fileSizeFormatter(size) {
1351
- if (size < 1024) {
1352
- return `${size} B`;
1353
- }
1354
- if (size < 1024 * 1024) {
1355
- return `${(size / 1024).toFixed(2)} kB`;
1356
- }
1357
- if (size < 1024 * 1024 * 1024) {
1358
- return `${(size / 1024 / 1024).toFixed(2)} MB`;
1359
- }
1360
- return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
1361
- }
1362
-
1363
- // src/FilePicker/FileList.js
1364
- var import_jsx_runtime3 = require("react/jsx-runtime");
1365
- var DeleteIcon = (props) => {
1366
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1367
- "svg",
1368
- __spreadProps(__spreadValues({
1369
- width: "24",
1370
- height: "25",
1371
- viewBox: "0 0 24 25",
1372
- fill: "none",
1373
- xmlns: "http://www.w3.org/2000/svg",
1374
- className: "r-file-input-delete-icon"
1375
- }, props), {
1376
- children: [
1377
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Delete" }),
1378
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1379
- "path",
1380
- {
1381
- d: "M3 6.5H5H21",
1382
- stroke: "currentColor",
1383
- strokeWidth: "2",
1384
- strokeLinecap: "round",
1385
- strokeLinejoin: "round"
1386
- }
1387
- ),
1388
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1389
- "path",
1390
- {
1391
- 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",
1392
- stroke: "currentColor",
1393
- strokeWidth: "2",
1394
- strokeLinecap: "round",
1395
- strokeLinejoin: "round"
1396
- }
1397
- ),
1398
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1399
- "path",
1400
- {
1401
- d: "M10 11.5V17.5",
1402
- stroke: "currentColor",
1403
- strokeWidth: "2",
1404
- strokeLinecap: "round",
1405
- strokeLinejoin: "round"
1406
- }
1407
- ),
1408
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1409
- "path",
1410
- {
1411
- d: "M14 11.5V17.5",
1412
- stroke: "currentColor",
1413
- strokeWidth: "2",
1414
- strokeLinecap: "round",
1415
- strokeLinejoin: "round"
1416
- }
1417
- )
1418
- ]
1419
- })
1420
- );
1421
- };
1422
- var CopyIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1423
- "svg",
1424
- __spreadProps(__spreadValues({
1425
- xmlns: "http://www.w3.org/2000/svg",
1426
- width: "24",
1427
- height: "25",
1428
- viewBox: "0 0 24 25",
1429
- fill: "none",
1430
- className: "r-file-input-copy-icon"
1431
- }, props), {
1432
- children: [
1433
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Copy file URL" }),
1434
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1435
- "path",
1436
- {
1437
- 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",
1438
- stroke: "black",
1439
- strokeWidth: "2",
1440
- strokeLinecap: "round",
1441
- strokeLinejoin: "round"
1442
- }
1443
- ),
1444
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1445
- "path",
1446
- {
1447
- 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",
1448
- stroke: "black",
1449
- strokeWidth: "2",
1450
- strokeLinecap: "round",
1451
- strokeLinejoin: "round"
1452
- }
1453
- )
1454
- ]
1455
- })
1456
- );
1457
- var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
1458
- year: "numeric",
1459
- month: "long",
1460
- day: "numeric",
1461
- hour: "numeric",
1462
- minute: "numeric",
1463
- second: "numeric"
1464
- });
1465
- var FileList = ({
1466
- files,
1467
- fetching,
1468
- selected,
1469
- allowDelete,
1470
- onMore,
1471
- onSelect,
1472
- onDelete
1473
- }) => {
1474
- const showLoadMore = !fetching && onMore;
1475
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "r-reset", children: [
1476
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { className: "r-table", children: [
1477
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
1478
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Name" }),
1479
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Type" }),
1480
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Size" }),
1481
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Uploaded" })
1482
- ] }) }),
1483
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1484
- "tr",
1485
- {
1486
- className: (0, import_ui3.cn)(
1487
- "r-file-input-file-row",
1488
- (selected == null ? void 0 : selected.id) === file.id ? "r-file-input-file-row-active" : ""
1489
- ),
1490
- onClick: () => onSelect(file.id),
1491
- children: [
1492
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1493
- "td",
1494
- {
1495
- style: {
1496
- width: "50%"
1497
- },
1498
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1499
- import_ui3.Stack,
1500
- {
1501
- className: "r-stack-align-center",
1502
- style: { gap: "0.5rem" },
1503
- children: [
1504
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1505
- import_ui3.Input,
1506
- {
1507
- type: "radio",
1508
- checked: (selected == null ? void 0 : selected.id) === file.id,
1509
- readOnly: true
1510
- }
1511
- ),
1512
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
1513
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1514
- CopyIcon,
1515
- {
1516
- onClick: (e) => {
1517
- e.stopPropagation();
1518
- navigator.clipboard.writeText(file.url);
1519
- }
1520
- }
1521
- ),
1522
- allowDelete && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1523
- DeleteIcon,
1524
- {
1525
- onClick: (event) => {
1526
- event.stopPropagation();
1527
- if (confirm("Are you sure?")) {
1528
- onDelete(file.id);
1529
- }
1530
- }
1531
- }
1532
- )
1533
- ]
1534
- }
1535
- )
1536
- }
1537
- ),
1538
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: toFileCategory(file.mimeType, "human") }),
1539
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: fileSizeFormatter(file.size) }),
1540
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: formatDate(file.createdAt) })
1541
- ]
1542
- },
1543
- file.id
1544
- )) })
1545
- ] }),
1546
- showLoadMore && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Button, { variant: "secondary", disabled: fetching, onClick: onMore, children: "Load more" })
1547
- ] });
1548
- };
1549
- var FileList_default = FileList;
1550
-
1551
- // src/FilePicker/FileInput.js
1552
- var import_react4 = __toESM(require("react"));
1553
- var import_ui4 = __toESM(require_dist());
1554
- var import_jsx_runtime4 = require("react/jsx-runtime");
1555
- var FileInput = ({ value, label, hint, onBrowse, onClear }) => {
1556
- var _a;
1557
- const filename = (_a = value == null ? void 0 : value.document) == null ? void 0 : _a.filename;
1558
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.FormGroup, { children: [
1559
- label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Label, { children: label }),
1560
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Stack, { className: "r-stack-justify-center", style: { gap: "0.5rem" }, children: [
1561
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1562
- import_ui4.Input,
1563
- {
1564
- disabled: true,
1565
- placeholder: filename ? filename : "No file selected"
1566
- }
1567
- ),
1568
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "primary", onClick: onBrowse, children: "Browse..." }),
1569
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "secondary", onClick: () => onClear(), children: "Clear" })
1570
- ] }),
1571
- hint && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Hint, { children: hint })
1572
- ] });
1573
- };
1574
- var FileInput_default = FileInput;
1575
-
1576
- // src/FilePicker/UploadProgress.js
1577
- var import_react5 = __toESM(require("react"));
1578
- var import_ui5 = __toESM(require_dist());
1579
- var import_jsx_runtime5 = require("react/jsx-runtime");
1580
- var UploadState = ({ upload }) => {
1581
- var _a, _b;
1582
- switch (upload.state.type) {
1583
- case "pending":
1584
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
1585
- fileSizeFormatter(0),
1586
- " / ",
1587
- fileSizeFormatter(upload.file.size || 0)
1588
- ] });
1589
- case "progress":
1590
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1591
- "div",
1592
- {
1593
- className: (0, import_ui5.cn)(
1594
- "r-reset",
1595
- "r-stack",
1596
- "r-stack-justify-beteen",
1597
- "r-stack-align-center"
1598
- ),
1599
- children: [
1600
- fileSizeFormatter(((_b = (_a = upload.state) == null ? void 0 : _a.payload) == null ? void 0 : _b.loaded) || 0),
1601
- " /",
1602
- " ",
1603
- fileSizeFormatter(upload.file.size || 0)
1604
- ]
1605
- }
1606
- );
1607
- case "uploaded":
1608
- case "completed":
1609
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
1610
- fileSizeFormatter(upload.file.size || 0),
1611
- " /",
1612
- " ",
1613
- fileSizeFormatter(upload.file.size || 0)
1614
- ] });
1615
- case "errored":
1616
- console.error({ upload });
1617
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: "Failed to upload" });
1618
- case "rejected":
1619
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: upload.state.payload.errors.join("; ") });
1620
- default:
1621
- console.error({ upload });
1622
- throw `Unknown state: ${upload.state}`;
1623
- }
1624
- };
1625
- var UploadName = ({ upload }) => {
1626
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "r-reset", children: upload.file.name });
1627
- };
1628
- var UploadProgress = ({ uploads }) => {
1629
- if (uploads.length === 0) {
1630
- return null;
1631
- }
1632
- 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)(
1633
- import_ui5.Stack,
1634
- {
1635
- className: (0, import_ui5.cn)(
1636
- "r-reset",
1637
- "r-stack-justify-beteen",
1638
- "r-stack-align-center",
1639
- "r-file-progress"
1640
- ),
1641
- children: [
1642
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadName, { upload }),
1643
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadState, { upload })
1644
- ]
1645
- },
1646
- upload.id
1647
- )) });
1648
- };
1649
- var UploadProgress_default = UploadProgress;
1650
-
1651
- // src/FilePicker/UploadFilesButton.js
1652
- var import_react6 = __toESM(require("react"));
1653
- var import_ui6 = __toESM(require_dist());
1654
- var import_jsx_runtime6 = require("react/jsx-runtime");
1655
- var UploadFilesButton = ({ allowedFileCategory, onSelect }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1656
- "div",
1657
- {
1658
- className: (0, import_ui6.cn)("r-reset", "r-spacing-both-sm", "r-file-input-upload-button"),
1659
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: (0, import_ui6.cn)("r-button", "r-button-secondary"), children: [
1660
- "Upload files...",
1661
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1662
- "input",
1663
- {
1664
- id: "r-files-input",
1665
- type: "file",
1666
- multiple: true,
1667
- accept: allowedFileCategory ? toMimeTypes(allowedFileCategory) : "",
1668
- onChange: (event) => {
1669
- const fileList = event.target.files;
1670
- const files = [];
1671
- for (let i = 0; i < fileList.length; i++) {
1672
- files[i] = fileList.item(i);
1673
- }
1674
- onSelect(files);
1675
- }
1676
- }
1677
- )
1678
- ] })
1679
- }
1680
- );
1681
- var UploadFilesButton_default = UploadFilesButton;
1682
-
1683
- // src/FilePicker/index.js
1684
- var import_jsx_runtime7 = require("react/jsx-runtime");
1685
- var FilePicker = ({
1686
- fileManager,
1687
- value: initialValue,
1688
- label,
1689
- hint,
1690
- fileCategory = null,
1691
- allowFilesDelete = true,
1692
- onChange
1693
- }) => {
1694
- var _a;
1695
- const allowedFileCategory = import_react7.default.useMemo(
1696
- () => sanitizeFileCategory(fileCategory),
1697
- [fileCategory]
1698
- );
1699
- const [state, setState] = import_react7.default.useState(
1700
- initialState(initialValue, allowedFileCategory)
1701
- );
1702
- const onFilesUpload = (files) => {
1703
- uploadFiles(fileManager, files, allowedFileCategory, setState);
1704
- };
1705
- const onBrowse = () => __async(void 0, null, function* () {
1706
- loadFiles(fileManager, state, setState);
1707
- });
1708
- const onClear = () => {
1709
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1710
- selected: null
1711
- }));
1712
- onChange(null);
1713
- };
1714
- const onSelectFile = () => {
1715
- if (state.selected) {
1716
- onChange(state.selected);
1717
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
1718
- } else {
1719
- alert("No file selected!");
1720
- }
1721
- };
1722
- const onClose = () => {
1723
- setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
1724
- };
1725
- const onSearchFiltersUpdate = (value) => __async(void 0, null, function* () {
1726
- searchFiles(fileManager, value, state, setState);
1727
- });
1728
- const onDeleteFile = (fileId) => __async(void 0, null, function* () {
1729
- deleteFile(fileManager, fileId, state, setState, onChange);
1730
- });
1731
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1732
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1733
- FileInput_default,
1734
- {
1735
- label,
1736
- hint,
1737
- value: initialValue,
1738
- onBrowse,
1739
- onClear
1740
- }
1741
- ),
1742
- state.open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1743
- Dialog_default,
1744
- {
1745
- disablePrimary: !state.selected,
1746
- onPrimary: onSelectFile,
1747
- onClose,
1748
- onDrop: onFilesUpload,
1749
- children: [
1750
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1751
- UploadFilesButton_default,
1752
- {
1753
- allowedFileCategory,
1754
- onSelect: onFilesUpload
1755
- }
1756
- ),
1757
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UploadProgress_default, { uploads: state.uploads }),
1758
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.H, { className: "r-spacing-top-sm", children: "Search" }),
1759
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1760
- FileSearch_default,
1761
- {
1762
- allowedFileCategory,
1763
- fetching: state.fetching,
1764
- value: state.files.filters,
1765
- onChange: onSearchFiltersUpdate
1766
- }
1767
- ),
1768
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1769
- FileList_default,
1770
- {
1771
- fetching: state.fetching,
1772
- files: state.files.list,
1773
- onMore: loadMoreFiles(fileManager, state, setState),
1774
- allowDelete: allowFilesDelete,
1775
- onDelete: onDeleteFile,
1776
- selected: (_a = state.selected) == null ? void 0 : _a.document,
1777
- onSelect: (fileId) => selectFile(fileId, setState)
1778
- }
1779
- )
1780
- ]
1781
- }
1782
- )
1783
- ] });
1784
- };
1785
- var FilePicker_default = FilePicker;
1786
-
1787
- // src/FileManager.js
1788
- var DOCUMENTS_QUERY = `
1789
- query($input: DocumentsInput!) {
1790
- documents(input: $input) {
1791
- list {
1792
- id
1793
- filename
1794
- mimeType
1795
- size
1796
- uploadStatus
1797
- url
1798
- createdAt
1799
- }
1800
- pagination {
1801
- cursor
1802
- }
1803
- }
1804
- }
1805
- `;
1806
- var CREATE_DOCUMENT_MUTATION = `
1807
- mutation($input: CreateDocumentInput!) {
1808
- createDocument(input: $input) {
1809
- document {
1810
- id
1811
- filename
1812
- mimeType
1813
- size
1814
- uploadStatus
1815
- url
1816
- createdAt
1817
- uploadUrl
1818
- }
1819
- errors {
1820
- key
1821
- message
1822
- codes {
1823
- key
1824
- placeholders
1825
- }
1826
- }
1827
- }
1828
- }
1829
- `;
1830
- var NOTIFY_UPLOADED_DOCUMENT_MUTATION = `
1831
- mutation($input: NotifyUploadedDocumentInput!) {
1832
- notifyUploadedDocument(input: $input) {
1833
- document {
1834
- id
1835
- filename
1836
- mimeType
1837
- size
1838
- uploadStatus
1839
- url
1840
- createdAt
1841
- }
1842
- errors {
1843
- key
1844
- message
1845
- codes {
1846
- key
1847
- placeholders
1848
- }
1849
- }
1850
- }
1851
- }
1852
- `;
1853
- var DELETE_DOCUMENT_MUTATION = `
1854
- mutation($input: DeleteDocumentInput!) {
1855
- deleteDocument(input: $input) {
1856
- document {
1857
- id
1858
- filename
1859
- mimeType
1860
- size
1861
- uploadStatus
1862
- url
1863
- createdAt
1864
- }
1865
- errors {
1866
- key
1867
- message
1868
- codes {
1869
- key
1870
- placeholders
1871
- }
1872
- }
1873
- }
1874
- }
1875
- `;
1876
- function uploadFile(file, document, progressCallback) {
1877
- return __async(this, null, function* () {
1878
- const xhr = new XMLHttpRequest();
1879
- return new Promise((resolve) => {
1880
- xhr.upload.addEventListener("progress", (event) => {
1881
- if (event.lengthComputable) {
1882
- progressCallback({
1883
- type: "progress",
1884
- payload: {
1885
- loaded: event.loaded,
1886
- total: event.total
1887
- }
1888
- });
1889
- }
1890
- });
1891
- xhr.addEventListener("loadend", (event) => {
1892
- if (xhr.readyState === 4 && xhr.status === 200) {
1893
- progressCallback({
1894
- type: "uploaded",
1895
- payload: {}
1896
- });
1897
- } else {
1898
- progressCallback({
1899
- type: "errored",
1900
- payload: {
1901
- errors: `ReadyState: ${xhr.readyState} - ${xhr.status} - ${event.type}: ${event.loaded} bytes transferred.`
1902
- }
1903
- });
1904
- }
1905
- resolve(xhr.readyState === 4 && xhr.status === 200);
1906
- });
1907
- xhr.withCredentials = false;
1908
- xhr.open("PUT", document.uploadUrl, true);
1909
- xhr.setRequestHeader("content-type", file.type);
1910
- const reader = new FileReader();
1911
- reader.onload = (event) => {
1912
- xhr.send(event.target.result);
1913
- };
1914
- reader.readAsArrayBuffer(file);
1915
- });
1916
- });
1917
- }
1918
- var FileManager = class {
1919
- constructor(url, headers) {
1920
- this.url = url;
1921
- this.headers = headers;
1922
- }
1923
- graphQLRequest(query, variables) {
1924
- return __async(this, null, function* () {
1925
- return fetch(this.url, {
1926
- method: "POST",
1927
- headers: Object.assign(
1928
- { "Content-Type": "application/json" },
1929
- this.headers
1930
- ),
1931
- body: JSON.stringify({
1932
- query,
1933
- variables
1934
- })
1935
- }).then((res) => res.json());
1936
- });
1937
- }
1938
- buildFilters(params) {
1939
- var _a, _b;
1940
- const filters = {
1941
- uploadStatus: "COMPLETED"
1942
- };
1943
- if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
1944
- filters.mimeTypes = params.mimeTypes;
1945
- }
1946
- if (((_b = params == null ? void 0 : params.excludeMimeTypes) == null ? void 0 : _b.length) > 0) {
1947
- filters.excludeMimeTypes = params.excludeMimeTypes;
1948
- }
1949
- if (params == null ? void 0 : params.keyword) {
1950
- filters.keyword = params.keyword;
1951
- }
1952
- return filters;
1953
- }
1954
- buildVariables(params) {
1955
- const variables = {
1956
- input: {
1957
- filters: this.buildFilters(params)
1958
- }
1959
- };
1960
- if (params.nextCursor) {
1961
- variables.input.pagination = { cursor: params.nextCursor };
1962
- }
1963
- return variables;
1964
- }
1965
- all() {
1966
- return __async(this, arguments, function* (params = {}) {
1967
- return this.graphQLRequest(
1968
- DOCUMENTS_QUERY,
1969
- this.buildVariables(params)
1970
- ).then((d) => {
1971
- return (d == null ? void 0 : d.data.documents) || {};
1972
- });
1973
- });
1974
- }
1975
- createAndUpload(fileInfo, progressCallback) {
1976
- return __async(this, null, function* () {
1977
- const { file, id } = fileInfo;
1978
- const { document, errors } = yield this.create({
1979
- filename: file.name,
1980
- mime_type: file.type,
1981
- size: file.size
1982
- });
1983
- if (errors) {
1984
- progressCallback(id, {
1985
- type: "errored",
1986
- payload: {
1987
- errors
1988
- }
1989
- });
1990
- return;
1991
- }
1992
- const result = yield uploadFile(
1993
- file,
1994
- document,
1995
- (state) => progressCallback(id, state)
1996
- );
1997
- if (result) {
1998
- const notify = yield this.notifyUploaded(document.id);
1999
- if (notify.errors) {
2000
- progressCallback(id, {
2001
- type: "errored",
2002
- payload: {
2003
- errors
2004
- }
2005
- });
2006
- return;
2007
- }
2008
- progressCallback(id, {
2009
- type: "completed",
2010
- payload: {
2011
- document: notify.document
2012
- }
2013
- });
2014
- }
2015
- });
2016
- }
2017
- create(params) {
2018
- return __async(this, null, function* () {
2019
- return this.graphQLRequest(CREATE_DOCUMENT_MUTATION, {
2020
- input: {
2021
- document: {
2022
- filename: params.filename,
2023
- mime_type: params.mime_type,
2024
- size: params.size
2025
- }
2026
- }
2027
- }).then((d) => {
2028
- var _a;
2029
- return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.createDocument) || {};
2030
- });
2031
- });
2032
- }
2033
- notifyUploaded(id) {
2034
- return __async(this, null, function* () {
2035
- return this.graphQLRequest(NOTIFY_UPLOADED_DOCUMENT_MUTATION, {
2036
- input: {
2037
- id
2038
- }
2039
- }).then((d) => {
2040
- var _a;
2041
- return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.notifyUploadedDocument) || {};
2042
- });
2043
- });
2044
- }
2045
- destroy(id) {
2046
- return __async(this, null, function* () {
2047
- return this.graphQLRequest(DELETE_DOCUMENT_MUTATION, {
2048
- input: {
2049
- id
2050
- }
2051
- }).then((d) => {
2052
- var _a;
2053
- return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.deleteDocument) || {};
2054
- });
2055
- });
2056
- }
2057
- };
2058
- // Annotate the CommonJS export names for ESM import in node:
2059
- 0 && (module.exports = {
2060
- FileManager,
2061
- FilePicker
2062
- });