@raketa-builder/file-input 0.6.0 → 1.0.1

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