@raketa-builder/file-input 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1946 @@
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 = ["application/zip", "application/x-rar-compressed"];
865
+ var MIME_TYPES = IMAGE.concat(VIDEO).concat(DOCUMENT).concat(AUDIO).concat(ARCHIVE);
866
+ var MAPPING = {
867
+ video: VIDEO,
868
+ document: DOCUMENT,
869
+ image: IMAGE,
870
+ audio: AUDIO,
871
+ archive: ARCHIVE,
872
+ other: []
873
+ };
874
+ var FILE_CATEGORIES = {
875
+ document: "Document",
876
+ archive: "Archive",
877
+ image: "Image",
878
+ video: "Video",
879
+ audio: "Audio",
880
+ other: "Other"
881
+ };
882
+ function toMimeTypes(fileCategory) {
883
+ return MAPPING[fileCategory] || [];
884
+ }
885
+ function toExcludedMimeTypes(fileCategory) {
886
+ if (fileCategory === "other") {
887
+ return MIME_TYPES;
888
+ }
889
+ return [];
890
+ }
891
+ function toFileCategory(mimeType, format = "robot") {
892
+ let fileCategory = null;
893
+ Object.keys(FILE_CATEGORIES).forEach((key) => {
894
+ if (fileCategory) {
895
+ return;
896
+ }
897
+ if (MAPPING[key].find((mt) => mt === mimeType)) {
898
+ fileCategory = key;
899
+ }
900
+ });
901
+ if (!fileCategory) {
902
+ fileCategory = "other";
903
+ }
904
+ if (format === "human") {
905
+ return FILE_CATEGORIES[fileCategory] || fileCategory;
906
+ } else {
907
+ return fileCategory;
908
+ }
909
+ }
910
+ function fileCategoriesOptions() {
911
+ return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
912
+ }
913
+ function sanitizeFileCategory(fileCategory) {
914
+ if (fileCategory === "other") {
915
+ return null;
916
+ }
917
+ if (Object.keys(FILE_CATEGORIES).includes(fileCategory)) {
918
+ return fileCategory;
919
+ }
920
+ return null;
921
+ }
922
+
923
+ // src/FilePicker/stateManagement.js
924
+ function mimeTypes(category) {
925
+ return toMimeTypes(category);
926
+ }
927
+ function excludeMimeTypes(category) {
928
+ return toExcludedMimeTypes(category);
929
+ }
930
+ function initialState(initialSelected, initialCategory) {
931
+ return {
932
+ open: false,
933
+ fetching: false,
934
+ selected: initialSelected,
935
+ uploads: [],
936
+ files: {
937
+ initial: true,
938
+ list: [],
939
+ nextCursor: null,
940
+ filters: {
941
+ keyword: "",
942
+ category: initialCategory || ""
943
+ }
944
+ }
945
+ };
946
+ }
947
+ function initialUploadState(file, allowedMimeTypes) {
948
+ if (allowedMimeTypes.length === 0 || allowedMimeTypes.includes(file.type)) {
949
+ return {
950
+ type: "pending",
951
+ payload: {}
952
+ };
953
+ }
954
+ return {
955
+ type: "rejected",
956
+ payload: {
957
+ errors: [`Files of type "${file.type}" are not supported.`]
958
+ }
959
+ };
960
+ }
961
+ function uploadFiles(fileManager, files, allowedFileCategory, setState) {
962
+ const allowedMimeTypes = toMimeTypes(allowedFileCategory);
963
+ const fileUploads = files.map((file) => ({
964
+ file,
965
+ id: (Math.random() * 1e6).toFixed(0),
966
+ state: initialUploadState(file, allowedMimeTypes)
967
+ }));
968
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
969
+ uploads: [...currentState.uploads, ...fileUploads]
970
+ }));
971
+ fileUploads.filter((fu) => fu.state.type === "pending").forEach(
972
+ (fileUpload) => fileManager.createAndUpload(
973
+ fileUpload,
974
+ (tmpId, newState) => setState((currentState) => {
975
+ if (newState.type === "completed") {
976
+ if (currentState.files.list.find(
977
+ (file) => file.id === newState.payload.document.id
978
+ )) {
979
+ return currentState;
980
+ }
981
+ return __spreadProps(__spreadValues({}, currentState), {
982
+ uploads: currentState.uploads.filter(
983
+ (upload) => upload.id !== tmpId
984
+ ),
985
+ files: __spreadProps(__spreadValues({}, currentState.files), {
986
+ list: [
987
+ __spreadValues({}, newState.payload.document),
988
+ ...currentState.files.list
989
+ ]
990
+ })
991
+ });
992
+ } else {
993
+ const newUploads = currentState.uploads.map((upload) => {
994
+ if (upload.id === tmpId) {
995
+ return __spreadProps(__spreadValues({}, upload), { state: newState });
996
+ } else {
997
+ return upload;
998
+ }
999
+ });
1000
+ return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
1001
+ }
1002
+ })
1003
+ )
1004
+ );
1005
+ }
1006
+ function loadFiles(fileManager, state, setState) {
1007
+ return __async(this, null, function* () {
1008
+ if (state.files.initial) {
1009
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1010
+ open: true,
1011
+ fetching: true
1012
+ }));
1013
+ const resp = yield fileManager.all({
1014
+ mimeTypes: mimeTypes(state.files.filters.category),
1015
+ excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
1016
+ });
1017
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1018
+ fetching: false,
1019
+ files: {
1020
+ initial: false,
1021
+ list: resp.list || [],
1022
+ nextCursor: resp.pagination.cursor,
1023
+ filters: {
1024
+ keyword: "",
1025
+ category: ""
1026
+ }
1027
+ }
1028
+ }));
1029
+ } else {
1030
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1031
+ open: true
1032
+ }));
1033
+ }
1034
+ });
1035
+ }
1036
+ function searchFiles(fileManager, filters, state, setState) {
1037
+ return __async(this, null, function* () {
1038
+ if ((filters.keyword !== state.files.filters.keyword || filters.category !== state.files.filters.category) && !state.fetching) {
1039
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1040
+ fetching: true
1041
+ }));
1042
+ const resp = yield fileManager.all({
1043
+ nextCursor: null,
1044
+ keyword: filters.keyword,
1045
+ mimeTypes: mimeTypes(filters.category),
1046
+ excludeMimeTypes: excludeMimeTypes(filters.category)
1047
+ });
1048
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1049
+ fetching: false,
1050
+ files: {
1051
+ list: [...resp.list],
1052
+ nextCursor: resp.pagination.cursor,
1053
+ filters: {
1054
+ keyword: filters.keyword,
1055
+ category: filters.category
1056
+ }
1057
+ }
1058
+ }));
1059
+ } else {
1060
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1061
+ fetching: false,
1062
+ files: __spreadProps(__spreadValues({}, currentState.files), {
1063
+ filters: {
1064
+ keyword: filters.keyword,
1065
+ category: filters.category
1066
+ }
1067
+ })
1068
+ }));
1069
+ }
1070
+ });
1071
+ }
1072
+ function deleteFile(fileManager, fileId, state, setState, onChange) {
1073
+ return __async(this, null, function* () {
1074
+ var _a, _b;
1075
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1076
+ fetching: true
1077
+ }));
1078
+ const response = yield fileManager.destroy(fileId);
1079
+ let removeFromList = false;
1080
+ let removeSelected = false;
1081
+ if (response.errors) {
1082
+ alert(`Something went wrong while deleting document#${fileId}`);
1083
+ }
1084
+ if (!response.errors && response.document) {
1085
+ removeFromList = true;
1086
+ if (fileId === ((_b = (_a = state.selected) == null ? void 0 : _a.document) == null ? void 0 : _b.id)) {
1087
+ removeSelected = true;
1088
+ }
1089
+ }
1090
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1091
+ fetching: false,
1092
+ selected: removeSelected ? null : currentState.selected,
1093
+ files: __spreadProps(__spreadValues({}, currentState.files), {
1094
+ list: currentState.files.list.filter((f) => f.id !== fileId)
1095
+ })
1096
+ }));
1097
+ if (removeSelected) {
1098
+ onChange(null);
1099
+ }
1100
+ });
1101
+ }
1102
+ function selectFile(fileId, setState) {
1103
+ setState((currentState) => {
1104
+ const file = currentState.files.list.find((f) => f.id === fileId);
1105
+ let newSelected = null;
1106
+ if (file) {
1107
+ newSelected = {
1108
+ document: file,
1109
+ uri: `raketacloud://documents/${file.id}`
1110
+ };
1111
+ }
1112
+ return __spreadProps(__spreadValues({}, currentState), {
1113
+ selected: newSelected
1114
+ });
1115
+ });
1116
+ }
1117
+ function loadMoreFiles(fileManager, state, setState) {
1118
+ if (!state.files.nextCursor) {
1119
+ return null;
1120
+ }
1121
+ return function loadMore() {
1122
+ return __async(this, null, function* () {
1123
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1124
+ fetching: true
1125
+ }));
1126
+ const resp = yield fileManager.all({
1127
+ nextCursor: state.files.nextCursor,
1128
+ keyword: state.files.filters.keyword,
1129
+ mimeTypes: mimeTypes(state.files.filters.category),
1130
+ excludeMimeTypes: excludeMimeTypes(state.files.filters.category)
1131
+ });
1132
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1133
+ fetching: false,
1134
+ files: {
1135
+ list: [...currentState.files.list, ...resp.list],
1136
+ nextCursor: resp.pagination.cursor,
1137
+ filters: __spreadValues({}, currentState.files.filters)
1138
+ }
1139
+ }));
1140
+ });
1141
+ };
1142
+ }
1143
+
1144
+ // src/FilePicker/Dialog.js
1145
+ var import_react = __toESM(require("react"));
1146
+ var import_react_dropzone = require("react-dropzone");
1147
+ var import_ui = __toESM(require_dist());
1148
+ var import_jsx_runtime = require("react/jsx-runtime");
1149
+ var DropZone = ({ children, onDrop }) => {
1150
+ const onFilesDrop = (0, import_react.useCallback)(
1151
+ (acceptedFiles) => {
1152
+ onDrop(acceptedFiles);
1153
+ },
1154
+ [onDrop]
1155
+ );
1156
+ const { getRootProps, getInputProps, isDragActive } = (0, import_react_dropzone.useDropzone)({
1157
+ onDropAccepted: onFilesDrop,
1158
+ noClick: true
1159
+ });
1160
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1161
+ "div",
1162
+ __spreadProps(__spreadValues({
1163
+ className: (0, import_ui.cn)(
1164
+ "r-reset",
1165
+ "r-dropzone-modal",
1166
+ isDragActive ? "r-dropzone-modal-active" : ""
1167
+ )
1168
+ }, getRootProps()), {
1169
+ children: [
1170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", __spreadValues({}, getInputProps())),
1171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: isDragActive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { className: "r-fs-large", children: "Drop here" }) }),
1172
+ !isDragActive && children
1173
+ ]
1174
+ })
1175
+ );
1176
+ };
1177
+ var Dialog = ({
1178
+ disablePrimary = false,
1179
+ onClose,
1180
+ onPrimary,
1181
+ onDrop,
1182
+ children
1183
+ }) => {
1184
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1185
+ import_ui.Modal,
1186
+ {
1187
+ title: "Files",
1188
+ onClose,
1189
+ onDrop,
1190
+ customWrapper: DropZone,
1191
+ FooterContent: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1193
+ import_ui.Button,
1194
+ {
1195
+ type: "button",
1196
+ variant: "primary",
1197
+ disabled: disablePrimary,
1198
+ onClick: onPrimary,
1199
+ children: "Select"
1200
+ }
1201
+ ),
1202
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Button, { type: "button", variant: "secondary", onClick: onClose, children: "Cancel" })
1203
+ ] }),
1204
+ children
1205
+ }
1206
+ );
1207
+ };
1208
+ var Dialog_default = Dialog;
1209
+
1210
+ // src/FilePicker/FileSearch.js
1211
+ var import_react2 = __toESM(require("react"));
1212
+ var import_ui2 = __toESM(require_dist());
1213
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1214
+ var useDebunce = (value, onDebouncedChange) => {
1215
+ const timerRef = import_react2.default.useRef(null);
1216
+ import_react2.default.useEffect(() => {
1217
+ timerRef.current = setTimeout(() => {
1218
+ onDebouncedChange(value);
1219
+ }, 500);
1220
+ return () => {
1221
+ clearTimeout(timerRef.current);
1222
+ };
1223
+ }, [value]);
1224
+ };
1225
+ var SearchInput = ({ onChange }) => {
1226
+ const [q, setQ] = import_react2.default.useState("");
1227
+ useDebunce(q, onChange);
1228
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1229
+ import_ui2.Input,
1230
+ {
1231
+ placeholder: "Start typing file name...",
1232
+ value: q,
1233
+ onChange: (e) => {
1234
+ setQ(e.target.value);
1235
+ }
1236
+ }
1237
+ );
1238
+ };
1239
+ var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1240
+ const onCategoryPick = (val) => {
1241
+ onChange(__spreadProps(__spreadValues({}, value), {
1242
+ category: val
1243
+ }));
1244
+ };
1245
+ const onSearchTermChange = (q) => {
1246
+ onChange(__spreadProps(__spreadValues({}, value), {
1247
+ keyword: q
1248
+ }));
1249
+ };
1250
+ if (allowedFileCategory) {
1251
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "r-spacing-bottom-sm", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }) });
1252
+ }
1253
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1254
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SearchInput, { onChange: onSearchTermChange }),
1255
+ /* @__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: [
1256
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1257
+ "button",
1258
+ {
1259
+ disabled: fetching,
1260
+ className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === "" ? "r-tab-button-active" : ""}`,
1261
+ onClick: () => onCategoryPick(""),
1262
+ children: "All"
1263
+ }
1264
+ ),
1265
+ fileCategoriesOptions().map((category) => {
1266
+ const [key, label] = category;
1267
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1268
+ "button",
1269
+ {
1270
+ disabled: fetching,
1271
+ className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === key ? "r-tab-button-active" : ""}`,
1272
+ onClick: () => onCategoryPick(key),
1273
+ children: label
1274
+ },
1275
+ key
1276
+ );
1277
+ })
1278
+ ] }) })
1279
+ ] });
1280
+ };
1281
+ var FileSearch_default = FileSearch;
1282
+
1283
+ // src/FilePicker/FileList.js
1284
+ var import_react3 = __toESM(require("react"));
1285
+ var import_ui3 = __toESM(require_dist());
1286
+
1287
+ // src/FilePicker/utils.js
1288
+ function fileSizeFormatter(size) {
1289
+ if (size < 1024) {
1290
+ return `${size} B`;
1291
+ }
1292
+ if (size < 1024 * 1024) {
1293
+ return `${(size / 1024).toFixed(2)} kB`;
1294
+ }
1295
+ if (size < 1024 * 1024 * 1024) {
1296
+ return `${(size / 1024 / 1024).toFixed(2)} MB`;
1297
+ }
1298
+ return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
1299
+ }
1300
+
1301
+ // src/FilePicker/FileList.js
1302
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1303
+ var DeleteIcon = (props) => {
1304
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1305
+ "svg",
1306
+ __spreadProps(__spreadValues({
1307
+ width: "24",
1308
+ height: "25",
1309
+ viewBox: "0 0 24 25",
1310
+ fill: "none",
1311
+ xmlns: "http://www.w3.org/2000/svg",
1312
+ className: "r-file-input-delete-icon"
1313
+ }, props), {
1314
+ children: [
1315
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1316
+ "path",
1317
+ {
1318
+ d: "M3 6.5H5H21",
1319
+ stroke: "currentColor",
1320
+ strokeWidth: "2",
1321
+ strokeLinecap: "round",
1322
+ strokeLinejoin: "round"
1323
+ }
1324
+ ),
1325
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1326
+ "path",
1327
+ {
1328
+ 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",
1329
+ stroke: "currentColor",
1330
+ strokeWidth: "2",
1331
+ strokeLinecap: "round",
1332
+ strokeLinejoin: "round"
1333
+ }
1334
+ ),
1335
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1336
+ "path",
1337
+ {
1338
+ d: "M10 11.5V17.5",
1339
+ stroke: "currentColor",
1340
+ strokeWidth: "2",
1341
+ strokeLinecap: "round",
1342
+ strokeLinejoin: "round"
1343
+ }
1344
+ ),
1345
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1346
+ "path",
1347
+ {
1348
+ d: "M14 11.5V17.5",
1349
+ stroke: "currentColor",
1350
+ strokeWidth: "2",
1351
+ strokeLinecap: "round",
1352
+ strokeLinejoin: "round"
1353
+ }
1354
+ )
1355
+ ]
1356
+ })
1357
+ );
1358
+ };
1359
+ var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
1360
+ year: "numeric",
1361
+ month: "long",
1362
+ day: "numeric"
1363
+ });
1364
+ var FileList = ({
1365
+ files,
1366
+ fetching,
1367
+ selected,
1368
+ onMore,
1369
+ onSelect,
1370
+ onDelete
1371
+ }) => {
1372
+ const showLoadMore = !fetching && onMore;
1373
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "r-reset", children: [
1374
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { className: "r-table", children: [
1375
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
1376
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Name" }),
1377
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Type" }),
1378
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Size" }),
1379
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: "Uploaded" })
1380
+ ] }) }),
1381
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1382
+ "tr",
1383
+ {
1384
+ className: (0, import_ui3.cn)(
1385
+ "r-file-input-file-row",
1386
+ (selected == null ? void 0 : selected.id) === file.id ? "r-file-input-file-row-active" : ""
1387
+ ),
1388
+ onClick: () => onSelect(file.id),
1389
+ children: [
1390
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1391
+ "td",
1392
+ {
1393
+ style: {
1394
+ width: "50%"
1395
+ },
1396
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1397
+ import_ui3.Stack,
1398
+ {
1399
+ className: "r-stack-align-center",
1400
+ style: { gap: "0.5rem" },
1401
+ children: [
1402
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1403
+ import_ui3.Input,
1404
+ {
1405
+ type: "radio",
1406
+ checked: (selected == null ? void 0 : selected.id) === file.id,
1407
+ readOnly: true
1408
+ }
1409
+ ),
1410
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
1411
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1412
+ DeleteIcon,
1413
+ {
1414
+ onClick: (event) => {
1415
+ event.stopPropagation();
1416
+ if (confirm("Are you sure?")) {
1417
+ onDelete(file.id);
1418
+ }
1419
+ }
1420
+ }
1421
+ )
1422
+ ]
1423
+ }
1424
+ )
1425
+ }
1426
+ ),
1427
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: toFileCategory(file.mimeType, "human") }),
1428
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: fileSizeFormatter(file.size) }),
1429
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: formatDate(file.createdAt) })
1430
+ ]
1431
+ },
1432
+ file.id
1433
+ )) })
1434
+ ] }),
1435
+ showLoadMore && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Button, { variant: "secondary", disabled: fetching, onClick: onMore, children: "Load more" })
1436
+ ] });
1437
+ };
1438
+ var FileList_default = FileList;
1439
+
1440
+ // src/FilePicker/FileInput.js
1441
+ var import_react4 = __toESM(require("react"));
1442
+ var import_ui4 = __toESM(require_dist());
1443
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1444
+ var FileInput = ({ value, label, hint, onBrowse, onClear }) => {
1445
+ var _a;
1446
+ const filename = (_a = value == null ? void 0 : value.document) == null ? void 0 : _a.filename;
1447
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.FormGroup, { children: [
1448
+ label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Label, { children: label }),
1449
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Stack, { className: "r-stack-justify-center", style: { gap: "0.5rem" }, children: [
1450
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1451
+ import_ui4.Input,
1452
+ {
1453
+ disabled: true,
1454
+ placeholder: filename ? filename : "No file selected"
1455
+ }
1456
+ ),
1457
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "primary", onClick: onBrowse, children: "Browse..." }),
1458
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Button, { type: "button", variant: "secondary", onClick: () => onClear(), children: "Clear" })
1459
+ ] }),
1460
+ hint && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Hint, { children: hint })
1461
+ ] });
1462
+ };
1463
+ var FileInput_default = FileInput;
1464
+
1465
+ // src/FilePicker/UploadProgress.js
1466
+ var import_react5 = __toESM(require("react"));
1467
+ var import_ui5 = __toESM(require_dist());
1468
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1469
+ var UploadState = ({ upload }) => {
1470
+ var _a, _b;
1471
+ switch (upload.state.type) {
1472
+ case "pending":
1473
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
1474
+ fileSizeFormatter(0),
1475
+ " / ",
1476
+ fileSizeFormatter(upload.file.size || 0)
1477
+ ] });
1478
+ case "progress":
1479
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1480
+ "div",
1481
+ {
1482
+ className: (0, import_ui5.cn)(
1483
+ "r-reset",
1484
+ "r-stack",
1485
+ "r-stack-justify-beteen",
1486
+ "r-stack-align-center"
1487
+ ),
1488
+ children: [
1489
+ fileSizeFormatter(((_b = (_a = upload.state) == null ? void 0 : _a.payload) == null ? void 0 : _b.loaded) || 0),
1490
+ " /",
1491
+ " ",
1492
+ fileSizeFormatter(upload.file.size || 0)
1493
+ ]
1494
+ }
1495
+ );
1496
+ case "uploaded":
1497
+ case "completed":
1498
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "r-reset", children: [
1499
+ fileSizeFormatter(upload.file.size || 0),
1500
+ " /",
1501
+ " ",
1502
+ fileSizeFormatter(upload.file.size || 0)
1503
+ ] });
1504
+ case "errored":
1505
+ console.error({ upload });
1506
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: "Failed to upload" });
1507
+ case "rejected":
1508
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_ui5.cn)("r-reset", "r-hint-error"), children: upload.state.payload.errors.join("; ") });
1509
+ default:
1510
+ console.error({ upload });
1511
+ throw `Unknown state: ${upload.state}`;
1512
+ }
1513
+ };
1514
+ var UploadName = ({ upload }) => {
1515
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "r-reset", children: upload.file.name });
1516
+ };
1517
+ var UploadProgress = ({ uploads }) => {
1518
+ if (uploads.length === 0) {
1519
+ return null;
1520
+ }
1521
+ 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)(
1522
+ import_ui5.Stack,
1523
+ {
1524
+ className: (0, import_ui5.cn)(
1525
+ "r-reset",
1526
+ "r-stack-justify-beteen",
1527
+ "r-stack-align-center",
1528
+ "r-file-progress"
1529
+ ),
1530
+ children: [
1531
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadName, { upload }),
1532
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UploadState, { upload })
1533
+ ]
1534
+ },
1535
+ upload.id
1536
+ )) });
1537
+ };
1538
+ var UploadProgress_default = UploadProgress;
1539
+
1540
+ // src/FilePicker/UploadFilesButton.js
1541
+ var import_react6 = __toESM(require("react"));
1542
+ var import_ui6 = __toESM(require_dist());
1543
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1544
+ var UploadFilesButton = ({ allowedFileCategory, onSelect }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1545
+ "div",
1546
+ {
1547
+ className: (0, import_ui6.cn)("r-reset", "r-spacing-both-sm", "r-file-input-upload-button"),
1548
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: (0, import_ui6.cn)("r-button", "r-button-secondary"), children: [
1549
+ "Upload files...",
1550
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1551
+ "input",
1552
+ {
1553
+ id: "r-files-input",
1554
+ type: "file",
1555
+ multiple: true,
1556
+ accept: allowedFileCategory ? toMimeTypes(allowedFileCategory) : "",
1557
+ onChange: (event) => {
1558
+ const fileList = event.target.files;
1559
+ const files = [];
1560
+ for (let i = 0; i < fileList.length; i++) {
1561
+ files[i] = fileList.item(i);
1562
+ }
1563
+ onSelect(files);
1564
+ }
1565
+ }
1566
+ )
1567
+ ] })
1568
+ }
1569
+ );
1570
+ var UploadFilesButton_default = UploadFilesButton;
1571
+
1572
+ // src/FilePicker/index.js
1573
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1574
+ var FilePicker = ({
1575
+ fileManager,
1576
+ value: initialValue,
1577
+ label,
1578
+ hint,
1579
+ fileCategory = null,
1580
+ onChange
1581
+ }) => {
1582
+ var _a;
1583
+ const allowedFileCategory = import_react7.default.useMemo(
1584
+ () => sanitizeFileCategory(fileCategory),
1585
+ [fileCategory]
1586
+ );
1587
+ const [state, setState] = import_react7.default.useState(
1588
+ initialState(initialValue, allowedFileCategory)
1589
+ );
1590
+ const onFilesUpload = (files) => {
1591
+ uploadFiles(fileManager, files, allowedFileCategory, setState);
1592
+ };
1593
+ const onBrowse = () => __async(void 0, null, function* () {
1594
+ loadFiles(fileManager, state, setState);
1595
+ });
1596
+ const onClear = () => {
1597
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), {
1598
+ selected: null
1599
+ }));
1600
+ onChange(null);
1601
+ };
1602
+ const onSelectFile = () => {
1603
+ if (state.selected) {
1604
+ onChange(state.selected);
1605
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
1606
+ } else {
1607
+ alert("No file selected!");
1608
+ }
1609
+ };
1610
+ const onClose = () => {
1611
+ setState((currentState) => __spreadProps(__spreadValues({}, currentState), { open: false }));
1612
+ };
1613
+ const onSearchFiltersUpdate = (value) => __async(void 0, null, function* () {
1614
+ searchFiles(fileManager, value, state, setState);
1615
+ });
1616
+ const onDeleteFile = (fileId) => __async(void 0, null, function* () {
1617
+ deleteFile(fileManager, fileId, state, setState, onChange);
1618
+ });
1619
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1620
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1621
+ FileInput_default,
1622
+ {
1623
+ label,
1624
+ hint,
1625
+ value: initialValue,
1626
+ onBrowse,
1627
+ onClear
1628
+ }
1629
+ ),
1630
+ state.open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1631
+ Dialog_default,
1632
+ {
1633
+ disablePrimary: !Boolean(state.selected),
1634
+ onPrimary: onSelectFile,
1635
+ onClose,
1636
+ onDrop: onFilesUpload,
1637
+ children: [
1638
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1639
+ UploadFilesButton_default,
1640
+ {
1641
+ allowedFileCategory,
1642
+ onSelect: onFilesUpload
1643
+ }
1644
+ ),
1645
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UploadProgress_default, { uploads: state.uploads }),
1646
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.H, { className: "r-spacing-top-sm", children: "Search" }),
1647
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1648
+ FileSearch_default,
1649
+ {
1650
+ allowedFileCategory,
1651
+ fetching: state.fetching,
1652
+ value: state.files.filters,
1653
+ onChange: onSearchFiltersUpdate
1654
+ }
1655
+ ),
1656
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1657
+ FileList_default,
1658
+ {
1659
+ fetching: state.fetching,
1660
+ files: state.files.list,
1661
+ onMore: loadMoreFiles(fileManager, state, setState),
1662
+ onDelete: onDeleteFile,
1663
+ selected: (_a = state.selected) == null ? void 0 : _a.document,
1664
+ onSelect: (fileId) => selectFile(fileId, setState)
1665
+ }
1666
+ )
1667
+ ]
1668
+ }
1669
+ )
1670
+ ] });
1671
+ };
1672
+ var FilePicker_default = FilePicker;
1673
+
1674
+ // src/FileManager.js
1675
+ var DOCUMENTS_QUERY = `
1676
+ query($input: DocumentsInput!) {
1677
+ documents(input: $input) {
1678
+ list {
1679
+ id
1680
+ filename
1681
+ mimeType
1682
+ size
1683
+ uploadStatus
1684
+ url
1685
+ createdAt
1686
+ }
1687
+ pagination {
1688
+ cursor
1689
+ }
1690
+ }
1691
+ }
1692
+ `;
1693
+ var CREATE_DOCUMENT_MUTATION = `
1694
+ mutation($input: CreateDocumentInput!) {
1695
+ createDocument(input: $input) {
1696
+ document {
1697
+ id
1698
+ filename
1699
+ mimeType
1700
+ size
1701
+ uploadStatus
1702
+ url
1703
+ createdAt
1704
+ uploadUrl
1705
+ }
1706
+ errors {
1707
+ key
1708
+ message
1709
+ codes {
1710
+ key
1711
+ placeholders
1712
+ }
1713
+ }
1714
+ }
1715
+ }
1716
+ `;
1717
+ var NOTIFY_UPLOADED_DOCUMENT_MUTATION = `
1718
+ mutation($input: NotifyUploadedDocumentInput!) {
1719
+ notifyUploadedDocument(input: $input) {
1720
+ document {
1721
+ id
1722
+ filename
1723
+ mimeType
1724
+ size
1725
+ uploadStatus
1726
+ url
1727
+ createdAt
1728
+ }
1729
+ errors {
1730
+ key
1731
+ message
1732
+ codes {
1733
+ key
1734
+ placeholders
1735
+ }
1736
+ }
1737
+ }
1738
+ }
1739
+ `;
1740
+ var DELETE_DOCUMENT_MUTATION = `
1741
+ mutation($input: DeleteDocumentInput!) {
1742
+ deleteDocument(input: $input) {
1743
+ document {
1744
+ id
1745
+ filename
1746
+ mimeType
1747
+ size
1748
+ uploadStatus
1749
+ url
1750
+ createdAt
1751
+ }
1752
+ errors {
1753
+ key
1754
+ message
1755
+ codes {
1756
+ key
1757
+ placeholders
1758
+ }
1759
+ }
1760
+ }
1761
+ }
1762
+ `;
1763
+ function uploadFile(file, document2, progressCallback) {
1764
+ return __async(this, null, function* () {
1765
+ const blob = new Blob([new Uint8Array(file.size + 20)]);
1766
+ const xhr = new XMLHttpRequest();
1767
+ return new Promise((resolve) => {
1768
+ xhr.upload.addEventListener("progress", (event) => {
1769
+ if (event.lengthComputable) {
1770
+ progressCallback({
1771
+ type: "progress",
1772
+ payload: {
1773
+ loaded: event.loaded,
1774
+ total: event.total
1775
+ }
1776
+ });
1777
+ }
1778
+ });
1779
+ xhr.addEventListener("loadend", (event) => {
1780
+ if (xhr.readyState === 4 && xhr.status === 200) {
1781
+ progressCallback({
1782
+ type: "uploaded",
1783
+ payload: {}
1784
+ });
1785
+ } else {
1786
+ progressCallback({
1787
+ type: "errored",
1788
+ payload: {
1789
+ errors: `ReadyState: ${xhr.readyState} - ${xhr.status} - ${event.type}: ${event.loaded} bytes transferred.`
1790
+ }
1791
+ });
1792
+ }
1793
+ resolve(xhr.readyState === 4 && xhr.status === 200);
1794
+ });
1795
+ xhr.withCredentials = false;
1796
+ xhr.open("PUT", document2.uploadUrl, true);
1797
+ xhr.setRequestHeader("content-type", file.type);
1798
+ xhr.send(blob);
1799
+ });
1800
+ });
1801
+ }
1802
+ var FileManager = class {
1803
+ constructor(url, headers) {
1804
+ this.url = url;
1805
+ this.headers = headers;
1806
+ }
1807
+ graphQLRequest(query, variables) {
1808
+ return __async(this, null, function* () {
1809
+ return fetch(this.url, {
1810
+ method: "POST",
1811
+ headers: Object.assign(
1812
+ { "Content-Type": "application/json" },
1813
+ this.headers
1814
+ ),
1815
+ body: JSON.stringify({
1816
+ query,
1817
+ variables
1818
+ })
1819
+ }).then((res) => res.json());
1820
+ });
1821
+ }
1822
+ buildFilters(params) {
1823
+ var _a, _b;
1824
+ let filters = {
1825
+ uploadStatus: "COMPLETED"
1826
+ };
1827
+ if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
1828
+ filters.mimeTypes = params.mimeTypes;
1829
+ }
1830
+ if (((_b = params == null ? void 0 : params.excludeMimeTypes) == null ? void 0 : _b.length) > 0) {
1831
+ filters.excludeMimeTypes = params.excludeMimeTypes;
1832
+ }
1833
+ if (params == null ? void 0 : params.keyword) {
1834
+ filters.keyword = params.keyword;
1835
+ }
1836
+ return filters;
1837
+ }
1838
+ buildVariables(params) {
1839
+ const variables = {
1840
+ input: {
1841
+ filters: this.buildFilters(params)
1842
+ }
1843
+ };
1844
+ if (params.nextCursor) {
1845
+ variables.input.pagination = { cursor: params.nextCursor };
1846
+ }
1847
+ return variables;
1848
+ }
1849
+ all() {
1850
+ return __async(this, arguments, function* (params = {}) {
1851
+ return this.graphQLRequest(
1852
+ DOCUMENTS_QUERY,
1853
+ this.buildVariables(params)
1854
+ ).then((d) => {
1855
+ return (d == null ? void 0 : d.data.documents) || {};
1856
+ });
1857
+ });
1858
+ }
1859
+ createAndUpload(fileInfo, progressCallback) {
1860
+ return __async(this, null, function* () {
1861
+ const { file, id } = fileInfo;
1862
+ const { document: document2, errors } = yield this.create({
1863
+ filename: file.name,
1864
+ mime_type: file.type,
1865
+ size: file.size
1866
+ });
1867
+ if (errors) {
1868
+ progressCallback(id, {
1869
+ type: "errored",
1870
+ payload: {
1871
+ errors
1872
+ }
1873
+ });
1874
+ return;
1875
+ }
1876
+ const result = yield uploadFile(
1877
+ file,
1878
+ document2,
1879
+ (state) => progressCallback(id, state)
1880
+ );
1881
+ if (result) {
1882
+ const notify = yield this.notifyUploaded(document2.id);
1883
+ if (notify.errors) {
1884
+ progressCallback(id, {
1885
+ type: "errored",
1886
+ payload: {
1887
+ errors
1888
+ }
1889
+ });
1890
+ return;
1891
+ }
1892
+ progressCallback(id, {
1893
+ type: "completed",
1894
+ payload: {
1895
+ document: notify.document
1896
+ }
1897
+ });
1898
+ }
1899
+ });
1900
+ }
1901
+ create(params) {
1902
+ return __async(this, null, function* () {
1903
+ return this.graphQLRequest(CREATE_DOCUMENT_MUTATION, {
1904
+ input: {
1905
+ document: {
1906
+ filename: params.filename,
1907
+ mime_type: params.mime_type,
1908
+ size: params.size
1909
+ }
1910
+ }
1911
+ }).then((d) => {
1912
+ var _a;
1913
+ return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.createDocument) || {};
1914
+ });
1915
+ });
1916
+ }
1917
+ notifyUploaded(id) {
1918
+ return __async(this, null, function* () {
1919
+ return this.graphQLRequest(NOTIFY_UPLOADED_DOCUMENT_MUTATION, {
1920
+ input: {
1921
+ id
1922
+ }
1923
+ }).then((d) => {
1924
+ var _a;
1925
+ return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.notifyUploadedDocument) || {};
1926
+ });
1927
+ });
1928
+ }
1929
+ destroy(id) {
1930
+ return __async(this, null, function* () {
1931
+ return this.graphQLRequest(DELETE_DOCUMENT_MUTATION, {
1932
+ input: {
1933
+ id
1934
+ }
1935
+ }).then((d) => {
1936
+ var _a;
1937
+ return ((_a = d == null ? void 0 : d.data) == null ? void 0 : _a.deleteDocument) || {};
1938
+ });
1939
+ });
1940
+ }
1941
+ };
1942
+ // Annotate the CommonJS export names for ESM import in node:
1943
+ 0 && (module.exports = {
1944
+ FileManager,
1945
+ FilePicker
1946
+ });