@apia/uploader-component 4.0.46

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,1590 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { Box, getVariant, Textarea, Input, Select } from '@apia/theme';
3
+ import { getLabel, parseAsSize, arrayOrArray, toBoolean } from '@apia/util';
4
+ import React, { createContext, useContext, forwardRef, useCallback, useEffect, useMemo, createElement } from 'react';
5
+ import { Permissions as Permissions$1, CollapsiblePanel, FileCard, Dropzone, SimpleButton, ApiaUtil, DateInput, AutocompleteController, Autocomplete, IconButton, RequiredMark, NumberInput, SwitchCard } from '@apia/components';
6
+ import { observer } from 'mobx-react-lite';
7
+ import { ApiaMonDocModal2 } from '@apia/api';
8
+ import { Tree } from '@apia/tree2-component';
9
+ import { FilePicker } from '@apia/uploader-controller';
10
+ import { makeObservable, action, observable } from 'mobx';
11
+ import { FileIcon, Icon } from '@apia/icons';
12
+
13
+ function makeDocTypeTooltip(api, docTypes) {
14
+ const docTypesInfo = docTypes || getTooltipsToShow(api);
15
+ return /* @__PURE__ */ jsx(
16
+ Box,
17
+ {
18
+ className: "docTypes__tooltipWrapper",
19
+ ...getVariant("layout.common.components.uploader.tooltip"),
20
+ children: docTypesInfo.map((currentDocType) => /* @__PURE__ */ jsxs(Box, { children: [
21
+ /* @__PURE__ */ jsx(Box, { className: "head", as: "strong", children: currentDocType.label }),
22
+ /* @__PURE__ */ jsxs(Box, { children: [
23
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
24
+ window.LBL_ALLOWED_EXTENSIONS,
25
+ " "
26
+ ] }),
27
+ /* @__PURE__ */ jsxs(Box, { as: "span", children: [
28
+ currentDocType.extensions.length > 0 ? currentDocType.extensions.join(", ") : getLabel("lblAllDcTypeAcc").text,
29
+ "."
30
+ ] })
31
+ ] }),
32
+ /* @__PURE__ */ jsxs(Box, { children: [
33
+ /* @__PURE__ */ jsxs(Box, { as: "strong", children: [
34
+ window.LBL_MAX_SIZE,
35
+ " "
36
+ ] }),
37
+ /* @__PURE__ */ jsx(Box, { as: "span", children: parseAsSize(currentDocType.maxSize) })
38
+ ] })
39
+ ] }, currentDocType.id))
40
+ }
41
+ );
42
+ }
43
+ function buildExtensionsArray(ext) {
44
+ return (ext ?? "").split(";").filter((current) => current !== "").map((current) => `.${current}`);
45
+ }
46
+ function addDocTypeInfoToArray(arr, docType) {
47
+ arr.push({
48
+ extensions: buildExtensionsArray(docType.docExts),
49
+ id: docType.id,
50
+ label: docType.title,
51
+ maxSize: docType.maxSize
52
+ });
53
+ }
54
+ function getTooltipsToShow(api) {
55
+ try {
56
+ const hasOneClickUpload = api.props.modalConfig.oneClickUpload;
57
+ const docTypes = api.state.allowedTypes;
58
+ const docTypesInfo = [];
59
+ const generic = docTypes.find((c) => String(c.id) === "1");
60
+ if (generic) {
61
+ addDocTypeInfoToArray(docTypesInfo, generic);
62
+ } else if (hasOneClickUpload) {
63
+ const docType = docTypes[0];
64
+ addDocTypeInfoToArray(docTypesInfo, docType);
65
+ } else {
66
+ docTypes.forEach((docType) => {
67
+ addDocTypeInfoToArray(docTypesInfo, docType);
68
+ });
69
+ }
70
+ return docTypesInfo;
71
+ } catch (e) {
72
+ return [];
73
+ }
74
+ }
75
+
76
+ const FileUploadContext = createContext(
77
+ void 0
78
+ );
79
+ const FileUploadProvider = ({
80
+ store,
81
+ children
82
+ }) => {
83
+ return /* @__PURE__ */ jsx(FileUploadContext.Provider, { value: store, children });
84
+ };
85
+ const useFileUploadContext = () => {
86
+ const context = useContext(FileUploadContext);
87
+ if (context === void 0) {
88
+ throw new Error("There is no FileUploadContext");
89
+ }
90
+ return context;
91
+ };
92
+
93
+ const Permissions = observer(() => {
94
+ const controller = useFileUploadContext();
95
+ const modalConfig = controller.modalConfig;
96
+ const state = controller.state;
97
+ return /* @__PURE__ */ jsx(
98
+ Permissions$1,
99
+ {
100
+ everyonePermissionsValue: state.permissions.allowAllType,
101
+ onChangeEveryonePermissions: (ev) => {
102
+ state.permissions.allowAllType = ev;
103
+ },
104
+ onChangePools: (pools) => {
105
+ controller.state.permissions.pools = pools;
106
+ },
107
+ onChangeUsers: (users) => {
108
+ controller.state.permissions.users = users;
109
+ },
110
+ permissions: controller.state.permissions,
111
+ collapsePermissions: modalConfig.collapsePermissions,
112
+ disabled: state.isReadonly
113
+ }
114
+ );
115
+ });
116
+
117
+ const FilesList = observer(
118
+ forwardRef(({ iconsSize, ...props }, ref) => {
119
+ const controller = useFileUploadContext();
120
+ const files = controller.inProgressFiles;
121
+ const fromDirectoryFile = controller.state.fromDirectoryFile;
122
+ const handleClose = useCallback(
123
+ (name) => {
124
+ controller.clearFile(name);
125
+ },
126
+ [controller]
127
+ );
128
+ return /* @__PURE__ */ jsx(
129
+ CollapsiblePanel,
130
+ {
131
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("lblPrevDocsToAdd").text }),
132
+ id: "selectedFiles",
133
+ collapseIconToRight: true,
134
+ closedIcon: "ArrowUpThin",
135
+ openIcon: "ArrowDownThin",
136
+ rememberCollapsedState: false,
137
+ children: /* @__PURE__ */ jsxs(
138
+ Box,
139
+ {
140
+ ...props,
141
+ as: "ul",
142
+ className: "filesList",
143
+ ...getVariant("layout.common.filesList"),
144
+ ref,
145
+ children: [
146
+ !fromDirectoryFile ? files.map((c) => {
147
+ return /* @__PURE__ */ jsx(
148
+ FileCard,
149
+ {
150
+ name: c.name,
151
+ iconsSize,
152
+ handleClose,
153
+ className: "fileList__modal"
154
+ }
155
+ );
156
+ }) : /* @__PURE__ */ jsx(
157
+ FileCard,
158
+ {
159
+ name: fromDirectoryFile.docName,
160
+ className: "fileList__modal",
161
+ handleClose: () => {
162
+ controller.clearPartialState();
163
+ controller.clearDirectoryFile();
164
+ }
165
+ }
166
+ ),
167
+ files.length === 0 && !fromDirectoryFile && getLabel("lblNoUpType").text
168
+ ]
169
+ }
170
+ )
171
+ }
172
+ );
173
+ })
174
+ );
175
+ var FilesList$1 = React.memo(FilesList);
176
+
177
+ const AddFileSection = observer(() => {
178
+ const controller = useFileUploadContext();
179
+ const modalConfig = controller.modalConfig;
180
+ const handleOnChange = (e) => {
181
+ const newFiles = Array.from(e);
182
+ controller.addFiles(newFiles);
183
+ };
184
+ const filePicker = new FilePicker(controller.api);
185
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
186
+ /* @__PURE__ */ jsx(Box, { className: "uploader__dropzone_description_section", children: /* @__PURE__ */ jsxs(Box, { className: "uploader__dropzone", children: [
187
+ controller.conf?.versionFile && /* @__PURE__ */ jsx("strong", { children: getLabel("lblNameMustBe", {
188
+ text: { TOK1: controller.conf?.versionFile.docName ?? "" }
189
+ }).text }),
190
+ /* @__PURE__ */ jsx(
191
+ Dropzone,
192
+ {
193
+ progress: controller.progress,
194
+ className: "dropzoneModal",
195
+ messageError: controller.state.fileReqError ? getLabel("msgReqField").text : void 0,
196
+ onChange: handleOnChange
197
+ }
198
+ ),
199
+ (modalConfig.allowDocumentsMonitor || modalConfig.allowPickFromDirectories) && !controller.conf?.versionFile && /* @__PURE__ */ jsxs(Box, { className: "uploader__dropzone_actions", children: [
200
+ modalConfig.allowPickFromDirectories && /* @__PURE__ */ jsx(
201
+ SimpleButton,
202
+ {
203
+ variant: "outline",
204
+ onClick: () => {
205
+ let modal = null;
206
+ const handleSelection = () => {
207
+ const firstElement = filePicker.selectedItems.values().next().value;
208
+ if (firstElement?.id)
209
+ controller.api.pickFileById(
210
+ firstElement.state.nodeProps.id
211
+ );
212
+ modal?.close();
213
+ };
214
+ modal = ApiaUtil.instance.modals.open({
215
+ title: getLabel("btnSelDcFrmTree").text,
216
+ children: /* @__PURE__ */ jsx(
217
+ Tree,
218
+ {
219
+ id: controller.api.id,
220
+ isMultiple: false,
221
+ onNodeDoubleClick: handleSelection,
222
+ store: filePicker
223
+ }
224
+ ),
225
+ onConfirm: handleSelection,
226
+ onCancel: () => modal?.close()
227
+ });
228
+ },
229
+ children: getLabel("btnSelDcFrmTree").text
230
+ }
231
+ ),
232
+ modalConfig.allowDocumentsMonitor && modalConfig.monitorId && /* @__PURE__ */ jsx(
233
+ SimpleButton,
234
+ {
235
+ variant: "outline",
236
+ onClick: () => new ApiaMonDocModal2().openModal({
237
+ monitorProperties: {
238
+ docTypeId: controller.docTypes.map((d) => d.id),
239
+ docTypeSel: controller.selectedDocTypeId ?? "1",
240
+ monDocId: controller.api.props.modalConfig.monitorId ?? 1
241
+ }
242
+ }).then((res) => {
243
+ if (res[0]?.row?.id)
244
+ controller.api.pickFileById(res[0].row.id);
245
+ }),
246
+ children: getLabel("btnMonDoc").text
247
+ }
248
+ )
249
+ ] })
250
+ ] }) }),
251
+ /* @__PURE__ */ jsx(FilesList$1, {}),
252
+ /* @__PURE__ */ jsxs(Box, { className: "uploader__dropzone_description_section", children: [
253
+ /* @__PURE__ */ jsxs("label", { children: [
254
+ /* @__PURE__ */ jsx("span", { children: getLabel("lblDes").text }),
255
+ /* @__PURE__ */ jsx(
256
+ Textarea,
257
+ {
258
+ disabled: controller.state.isReadonly,
259
+ value: controller.description,
260
+ onChange: (e) => {
261
+ controller.setDescription(e.target.value);
262
+ }
263
+ }
264
+ )
265
+ ] }),
266
+ /* @__PURE__ */ jsxs("label", { children: [
267
+ /* @__PURE__ */ jsx("span", { children: getLabel("lblExpDate").text }),
268
+ /* @__PURE__ */ jsx(
269
+ DateInput,
270
+ {
271
+ disabled: controller.state.isReadonly,
272
+ value: controller.state.docExpDate,
273
+ onChange: (d) => {
274
+ controller.state.docExpDate = d ?? void 0;
275
+ }
276
+ }
277
+ )
278
+ ] })
279
+ ] })
280
+ ] });
281
+ });
282
+
283
+ const UploaderFileHeader = observer(() => {
284
+ const controller = useFileUploadContext();
285
+ const docTypes = controller.docTypes.map((c) => ({
286
+ label: c.title,
287
+ value: String(c.id)
288
+ }));
289
+ const selectedDocTypeId = controller.selectedDocTypeId;
290
+ useEffect(() => {
291
+ handler.setValue(selectedDocTypeId, { force: true });
292
+ }, [selectedDocTypeId]);
293
+ const properties = {
294
+ disabled: controller.state.fromDirectoryFile || controller.conf?.versionFile ? true : false,
295
+ caseInsensitive: true,
296
+ options: docTypes,
297
+ onChange(id) {
298
+ controller.changeDocType(id);
299
+ }
300
+ };
301
+ const handler = useMemo(() => {
302
+ return new AutocompleteController(properties);
303
+ }, []);
304
+ return /* @__PURE__ */ jsxs("label", { children: [
305
+ /* @__PURE__ */ jsx("span", { children: getLabel("lblDocType").text }),
306
+ /* @__PURE__ */ jsxs(Box, { className: "uploader__file_selection", children: [
307
+ /* @__PURE__ */ jsx(Autocomplete, { handler, properties }),
308
+ /* @__PURE__ */ jsx(
309
+ IconButton,
310
+ {
311
+ variant: "outline",
312
+ className: "uploader__file_infoBtn",
313
+ icon: "Info",
314
+ size: "Xl",
315
+ iconSize: 20,
316
+ onMouseEnter: (e) => {
317
+ ApiaUtil.instance.tooltips.open({
318
+ attachToElement: () => e.target,
319
+ children: makeDocTypeTooltip(
320
+ controller.api,
321
+ arrayOrArray(controller.selectedDocType).map((c) => ({
322
+ extensions: c.docExts.split(";"),
323
+ id: c.id,
324
+ label: c.title,
325
+ maxSize: c.maxSize
326
+ }))
327
+ )
328
+ });
329
+ }
330
+ }
331
+ )
332
+ ] })
333
+ ] });
334
+ });
335
+
336
+ const MetadataLabel = observer(
337
+ forwardRef(
338
+ ({ metadata, i }, ref) => {
339
+ const controller = useFileUploadContext();
340
+ return /* @__PURE__ */ jsxs(
341
+ Box,
342
+ {
343
+ tabIndex: i === 0 ? 0 : -1,
344
+ className: "metadata__render_container",
345
+ ref: metadata.free !== "Y" ? ref : null,
346
+ children: [
347
+ /* @__PURE__ */ jsx(RequiredMark, { isRequired: metadata.required === "Y" }),
348
+ metadata.free === "Y" ? /* @__PURE__ */ jsxs(Fragment, { children: [
349
+ /* @__PURE__ */ jsx(
350
+ Input,
351
+ {
352
+ value: metadata.title,
353
+ disabled: controller.state.isReadonly,
354
+ tabIndex: i === 0 ? 0 : -1,
355
+ ref,
356
+ className: "metadata__field",
357
+ onChange: (e) => {
358
+ metadata.title = e.target.value;
359
+ metadata.labelErrorMessage = "";
360
+ }
361
+ }
362
+ ),
363
+ metadata.labelErrorMessage && /* @__PURE__ */ jsx(Box, { as: "span", className: "errorRequired", children: metadata.labelErrorMessage })
364
+ ] }) : /* @__PURE__ */ jsx("span", { children: metadata.title })
365
+ ]
366
+ }
367
+ );
368
+ }
369
+ )
370
+ );
371
+
372
+ const MetadataField = observer(
373
+ forwardRef(({ metadata }, ref) => {
374
+ let component = null;
375
+ const controller = useFileUploadContext();
376
+ if (metadata.type === "D") {
377
+ component = /* @__PURE__ */ jsx(
378
+ DateInput,
379
+ {
380
+ disabled: controller.state.isReadonly,
381
+ className: "metadata__field",
382
+ value: metadata.value,
383
+ tabIndex: -1,
384
+ ref,
385
+ onChange: (e) => {
386
+ metadata.value = e;
387
+ metadata.errorMessage = "";
388
+ }
389
+ }
390
+ );
391
+ } else if (metadata.type === "N") {
392
+ component = /* @__PURE__ */ jsx(
393
+ NumberInput,
394
+ {
395
+ value: metadata.value,
396
+ disabled: controller.state.isReadonly,
397
+ className: "metadata__field",
398
+ tabIndex: -1,
399
+ ref,
400
+ onChange: (e) => {
401
+ if (e.error) {
402
+ metadata.errorMessage = getLabel("msgMustBeNum").text;
403
+ } else {
404
+ metadata.errorMessage = "";
405
+ }
406
+ metadata.value = e.value;
407
+ }
408
+ }
409
+ );
410
+ } else {
411
+ component = /* @__PURE__ */ jsx(
412
+ Input,
413
+ {
414
+ value: metadata.value,
415
+ disabled: controller.state.isReadonly,
416
+ tabIndex: -1,
417
+ ref,
418
+ className: "metadata__field",
419
+ onChange: (e) => {
420
+ metadata.value = e.target.value;
421
+ metadata.errorMessage = "";
422
+ }
423
+ }
424
+ );
425
+ }
426
+ return /* @__PURE__ */ jsxs(Box, { className: "metadata__render_container", children: [
427
+ /* @__PURE__ */ jsx(
428
+ RequiredMark,
429
+ {
430
+ isRequired: metadata.required === "Y" || metadata.free === "Y"
431
+ }
432
+ ),
433
+ component,
434
+ metadata.errorMessage && /* @__PURE__ */ jsx(Box, { as: "span", className: "errorRequired", children: metadata.errorMessage })
435
+ ] });
436
+ })
437
+ );
438
+
439
+ var __defProp = Object.defineProperty;
440
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
441
+ var __publicField = (obj, key, value) => {
442
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
443
+ return value;
444
+ };
445
+ let MetadataTable$1 = class MetadataTable {
446
+ constructor() {
447
+ __publicField(this, "activeCell", null);
448
+ __publicField(this, "lastSelectedIndex", null);
449
+ __publicField(this, "selectedIndices", []);
450
+ __publicField(this, "cellRefs", {});
451
+ __publicField(this, "onDelete");
452
+ __publicField(this, "component", observer(() => {
453
+ const controller = useFileUploadContext();
454
+ const modalConfig = controller.modalConfig;
455
+ const columns = [
456
+ { name: "metadataName", label: getLabel("lblTit").text },
457
+ { name: "metadataValue", label: getLabel("lblValue").text }
458
+ ];
459
+ const metadata = controller.allMetadata;
460
+ const isRowSelectable = (rowIndex) => metadata[rowIndex].free === "Y";
461
+ this.onDelete = () => {
462
+ controller.deleteMetadata(this.selectedIndices);
463
+ const offset = controller.state.metadata.metadataArray.length;
464
+ const newLength = metadata.length - 1;
465
+ if (newLength - offset > 0) {
466
+ this.selectedIndices = [newLength - 1];
467
+ this.setActiveCell({ row: newLength - 1, col: 0 });
468
+ this.setLastSelectedIndex(newLength - 1);
469
+ this.focusCell(newLength - 1, 0);
470
+ } else {
471
+ this.selectedIndices = [];
472
+ this.setLastSelectedIndex(newLength - 1);
473
+ this.focusCell(newLength - 1, 0);
474
+ }
475
+ };
476
+ return /* @__PURE__ */ jsxs(
477
+ CollapsiblePanel,
478
+ {
479
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("titMetadata").text }),
480
+ id: "metadata",
481
+ collapseIconToRight: true,
482
+ closedIcon: "ArrowUpThin",
483
+ openIcon: "ArrowDownThin",
484
+ "aria-label": getLabel("titMetadata").text,
485
+ collapsed: modalConfig.collapseMetadata,
486
+ children: [
487
+ (metadata.length > 0 || controller.state.metadata.isFreeMetadata) && /* @__PURE__ */ jsxs(
488
+ Box,
489
+ {
490
+ className: "metadata__container",
491
+ tabIndex: 0,
492
+ onKeyDown: (e) => this.handleKeyDown(e, columns, metadata.length, isRowSelectable),
493
+ children: [
494
+ /* @__PURE__ */ jsx(Box, { className: "metadata__table_container", children: /* @__PURE__ */ jsxs(
495
+ Box,
496
+ {
497
+ as: "table",
498
+ role: "table",
499
+ "aria-label": "Metadata Table",
500
+ "aria-describedby": "metadata-table-description",
501
+ children: [
502
+ /* @__PURE__ */ jsx("thead", { role: "rowgroup", children: /* @__PURE__ */ jsx("tr", { role: "row", children: columns.map((col) => /* @__PURE__ */ jsx("th", { role: "columnheader", scope: "col", children: col.label }, col.name)) }) }),
503
+ /* @__PURE__ */ jsx("tbody", { role: "rowgroup", children: metadata.map((c, rowIndex) => {
504
+ const isRowSelected = this.selectedIndices?.includes(rowIndex);
505
+ return /* @__PURE__ */ jsx(
506
+ "tr",
507
+ {
508
+ role: "row",
509
+ onClick: (e) => {
510
+ e.stopPropagation();
511
+ this.handleRowClick(
512
+ rowIndex,
513
+ e,
514
+ isRowSelectable(rowIndex)
515
+ );
516
+ },
517
+ className: `${isRowSelected ? "selected" : ""}`,
518
+ children: columns.map((col, colIndex) => /* @__PURE__ */ jsx(
519
+ "td",
520
+ {
521
+ role: "cell",
522
+ style: {
523
+ cursor: !isRowSelectable(rowIndex) ? "not-allowed" : "default"
524
+ },
525
+ onClick: (e) => {
526
+ e.stopPropagation();
527
+ this.handleRowClick(
528
+ rowIndex,
529
+ e,
530
+ isRowSelectable(rowIndex),
531
+ colIndex
532
+ );
533
+ },
534
+ children: colIndex === 0 ? /* @__PURE__ */ jsx(
535
+ MetadataLabel,
536
+ {
537
+ i: rowIndex,
538
+ metadata: metadata[rowIndex],
539
+ ref: (el) => this.updateCellRef(
540
+ `cell-${rowIndex}-${colIndex}`,
541
+ el
542
+ )
543
+ }
544
+ ) : /* @__PURE__ */ jsx(
545
+ MetadataField,
546
+ {
547
+ metadata: metadata[rowIndex],
548
+ ref: (el) => this.updateCellRef(
549
+ `cell-${rowIndex}-${colIndex}`,
550
+ el
551
+ )
552
+ }
553
+ )
554
+ },
555
+ col.name
556
+ ))
557
+ },
558
+ c.id
559
+ );
560
+ }) })
561
+ ]
562
+ }
563
+ ) }),
564
+ metadata.length < 1 && /* @__PURE__ */ jsx(Box, { children: getLabel("lblNoMetadataForThisDocType").text }),
565
+ controller.state.metadata.isFreeMetadata && /* @__PURE__ */ jsxs(Box, { className: "metadata__actions", children: [
566
+ /* @__PURE__ */ jsx(
567
+ IconButton,
568
+ {
569
+ disabled: controller.state.isReadonly,
570
+ icon: "Plus",
571
+ ...getVariant("outline"),
572
+ className: "addMetadata",
573
+ onClick: () => {
574
+ controller.addMetadata();
575
+ setTimeout(() => {
576
+ const newRowI = metadata.length;
577
+ const newField = document.querySelector(
578
+ "tr:last-child .metadata__field"
579
+ );
580
+ if (newField) {
581
+ newField.scrollIntoView({
582
+ behavior: "smooth",
583
+ block: "nearest",
584
+ inline: "nearest"
585
+ });
586
+ newField.focus();
587
+ }
588
+ this.selectedIndices = [newRowI];
589
+ this.setActiveCell({ row: newRowI, col: 0 });
590
+ this.setLastSelectedIndex(newRowI);
591
+ const container = document.querySelector(
592
+ ".uploader__content"
593
+ );
594
+ if (container) {
595
+ container.scrollTo({
596
+ top: container.scrollHeight,
597
+ behavior: "smooth"
598
+ });
599
+ }
600
+ }, 0);
601
+ },
602
+ type: "button",
603
+ "aria-label": "Add Metadata",
604
+ "aria-description": "Adds a new metadata row to the table"
605
+ }
606
+ ),
607
+ /* @__PURE__ */ jsx(
608
+ IconButton,
609
+ {
610
+ disabled: controller.state.isReadonly || this.selectedIndices.length === 0,
611
+ icon: "Trash",
612
+ ...getVariant("outline-danger"),
613
+ onClick: () => this.onDelete && this.onDelete(),
614
+ type: "button",
615
+ className: "deleteMetadata",
616
+ "aria-label": "Delete Metadata",
617
+ "aria-description": "Deletes the selected metadata row"
618
+ }
619
+ )
620
+ ] })
621
+ ]
622
+ }
623
+ ),
624
+ metadata.length < 1 && !controller.state.metadata.isFreeMetadata && /* @__PURE__ */ jsx(Fragment, { children: getLabel("lblNoMetadataForThisDocType").text })
625
+ ]
626
+ }
627
+ );
628
+ }));
629
+ makeObservable(this, {
630
+ activeCell: observable,
631
+ lastSelectedIndex: observable,
632
+ selectedIndices: observable,
633
+ cellRefs: observable,
634
+ setActiveCell: action,
635
+ setLastSelectedIndex: action,
636
+ setSelectedIndices: action,
637
+ updateCellRef: action,
638
+ handleRowClick: action,
639
+ handleKeyDown: action
640
+ });
641
+ }
642
+ setActiveCell(cell) {
643
+ this.activeCell = cell;
644
+ }
645
+ setLastSelectedIndex(index) {
646
+ this.lastSelectedIndex = index;
647
+ }
648
+ setSelectedIndices(indices) {
649
+ this.selectedIndices = indices;
650
+ }
651
+ updateCellRef(key, el) {
652
+ this.cellRefs[key] = el;
653
+ }
654
+ // Helper: returns an inclusive range between two indices.
655
+ getRange(start, end) {
656
+ const range = [];
657
+ const min = Math.min(start, end);
658
+ const max = Math.max(start, end);
659
+ for (let i = min; i <= max; i++) {
660
+ range.push(i);
661
+ }
662
+ return range;
663
+ }
664
+ focusCell(rowI, colI) {
665
+ const cellKey = `cell-${rowI}-${colI}`;
666
+ const cellEl = this.cellRefs[cellKey];
667
+ cellEl?.focus();
668
+ cellEl?.scrollIntoView({
669
+ behavior: "smooth",
670
+ block: "nearest",
671
+ inline: "nearest"
672
+ });
673
+ }
674
+ // Modified handleRowClick: now accepts an optional colIndex.
675
+ handleRowClick(index, e, isSelectable = true, colIndex) {
676
+ const newCol = colIndex !== void 0 ? colIndex : 0;
677
+ if (isSelectable) {
678
+ if (e && e.ctrlKey) {
679
+ if (this.selectedIndices.includes(index)) {
680
+ this.selectedIndices = this.selectedIndices.filter(
681
+ (i) => i !== index
682
+ );
683
+ } else {
684
+ this.selectedIndices.push(index);
685
+ }
686
+ this.lastSelectedIndex = index;
687
+ this.activeCell = { row: index, col: newCol };
688
+ } else if (e && e.shiftKey && this.lastSelectedIndex !== null) {
689
+ const range = this.getRange(this.lastSelectedIndex, index);
690
+ this.selectedIndices = Array.from(
691
+ /* @__PURE__ */ new Set([...this.selectedIndices, ...range])
692
+ );
693
+ this.lastSelectedIndex = index;
694
+ this.activeCell = { row: index, col: newCol };
695
+ } else {
696
+ this.selectedIndices = [index];
697
+ this.lastSelectedIndex = index;
698
+ this.activeCell = { row: index, col: newCol };
699
+ }
700
+ } else {
701
+ this.activeCell = { row: index, col: newCol };
702
+ }
703
+ this.focusCell(index, newCol);
704
+ }
705
+ // Handle key navigation.
706
+ // isRowSelectable is a predicate function that returns true if a given row is selectable.
707
+ handleKeyDown(e, columns, listLength, isRowSelectable) {
708
+ if (listLength === 0)
709
+ return;
710
+ if (this.selectedIndices.length > 0 && e.key === "Delete" || e.key === "Del" || e.key === "Supr") {
711
+ e.preventDefault();
712
+ if (this.onDelete) {
713
+ this.onDelete();
714
+ }
715
+ return;
716
+ }
717
+ const maxColIndex = columns.length - 1;
718
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
719
+ e.preventDefault();
720
+ const currentRow = this.lastSelectedIndex !== null ? this.lastSelectedIndex : 0;
721
+ let newRow = currentRow;
722
+ if (e.key === "ArrowDown") {
723
+ newRow = (currentRow + 1) % listLength;
724
+ } else if (e.key === "ArrowUp") {
725
+ newRow = (currentRow - 1 + listLength) % listLength;
726
+ }
727
+ if (isRowSelectable(newRow)) {
728
+ if (e.shiftKey) {
729
+ this.selectedIndices = Array.from(
730
+ /* @__PURE__ */ new Set([...this.selectedIndices, newRow])
731
+ );
732
+ } else {
733
+ this.selectedIndices = [newRow];
734
+ }
735
+ this.lastSelectedIndex = newRow;
736
+ } else {
737
+ this.lastSelectedIndex = newRow;
738
+ }
739
+ const newCol = this.activeCell ? this.activeCell.col : 0;
740
+ this.activeCell = { row: newRow, col: newCol };
741
+ const cellKey = `cell-${newRow}-${newCol}`;
742
+ const cellEl = this.cellRefs[cellKey];
743
+ cellEl?.focus();
744
+ cellEl?.scrollIntoView({
745
+ behavior: "smooth",
746
+ block: "nearest",
747
+ inline: "nearest"
748
+ });
749
+ } else if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
750
+ e.preventDefault();
751
+ let currentCell = this.activeCell;
752
+ if (!currentCell) {
753
+ const row = this.lastSelectedIndex !== null ? this.lastSelectedIndex : 0;
754
+ currentCell = { row, col: 0 };
755
+ }
756
+ if (e.key === "ArrowLeft") {
757
+ const newCol = currentCell.col - 1;
758
+ if (newCol >= 0 && this.cellRefs[`cell-${currentCell.row}-${newCol}`]) {
759
+ this.activeCell = { row: currentCell.row, col: newCol };
760
+ } else {
761
+ let found = false;
762
+ let target = null;
763
+ for (let r = currentCell.row + 1; r < listLength; r++) {
764
+ for (let c = currentCell.col - 1; c >= 0; c--) {
765
+ if (this.cellRefs[`cell-${r}-${c}`]) {
766
+ target = { row: r, col: c };
767
+ found = true;
768
+ break;
769
+ }
770
+ }
771
+ if (found)
772
+ break;
773
+ }
774
+ if (found && target) {
775
+ this.activeCell = target;
776
+ } else {
777
+ this.activeCell = { row: currentCell.row, col: 0 };
778
+ }
779
+ }
780
+ } else if (e.key === "ArrowRight") {
781
+ let newCol = currentCell.col + 1;
782
+ if (newCol > maxColIndex || !this.cellRefs[`cell-${currentCell.row}-${newCol}`]) {
783
+ newCol = maxColIndex;
784
+ }
785
+ this.activeCell = { row: currentCell.row, col: newCol };
786
+ }
787
+ if (this.activeCell) {
788
+ const cellKey = `cell-${this.activeCell.row}-${this.activeCell.col}`;
789
+ const cellEl = this.cellRefs[cellKey];
790
+ cellEl?.focus();
791
+ cellEl?.scrollIntoView({
792
+ behavior: "smooth",
793
+ block: "nearest",
794
+ inline: "nearest"
795
+ });
796
+ }
797
+ }
798
+ }
799
+ reset() {
800
+ this.activeCell = null;
801
+ this.lastSelectedIndex = null;
802
+ this.selectedIndices = [];
803
+ this.cellRefs = {};
804
+ }
805
+ };
806
+
807
+ const Directory = observer(() => {
808
+ const controller = useFileUploadContext();
809
+ const modalConfig = controller.modalConfig;
810
+ if (controller.state.isReadonly)
811
+ return null;
812
+ return /* @__PURE__ */ jsxs(
813
+ CollapsiblePanel,
814
+ {
815
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("lblDocFolders").text }),
816
+ id: "direcotry",
817
+ collapseIconToRight: true,
818
+ closedIcon: "ArrowUpThin",
819
+ openIcon: "ArrowDownThin",
820
+ className: "uploader__directory",
821
+ collapsed: modalConfig.collapseDirectories,
822
+ children: [
823
+ /* @__PURE__ */ jsx(
824
+ IconButton,
825
+ {
826
+ className: "uploader__directory__clear-directory",
827
+ icon: "Close",
828
+ title: "",
829
+ onClick: () => {
830
+ controller.directories.selectedItems.clear();
831
+ controller.state.docFolder = void 0;
832
+ }
833
+ }
834
+ ),
835
+ /* @__PURE__ */ jsx(
836
+ Tree,
837
+ {
838
+ id: controller.api.id,
839
+ isMultiple: false,
840
+ onSelect: (nodes) => {
841
+ const node = nodes.values().next().value;
842
+ if (node && node.state.nodeProps.canWrite)
843
+ controller.state.docFolder = Number(node.id);
844
+ },
845
+ store: controller.directories
846
+ }
847
+ )
848
+ ]
849
+ }
850
+ );
851
+ });
852
+
853
+ const Metadata = new MetadataTable$1();
854
+ const UploaderContent = observer(() => {
855
+ const controller = useFileUploadContext();
856
+ const modalConfig = controller.modalConfig;
857
+ return /* @__PURE__ */ jsxs(
858
+ Box,
859
+ {
860
+ className: "uploader__container",
861
+ ...getVariant("layout.common.components.uploader.defaultView"),
862
+ children: [
863
+ /* @__PURE__ */ jsx(UploaderFileHeader, {}),
864
+ /* @__PURE__ */ jsxs(Box, { className: "uploader__content", children: [
865
+ /* @__PURE__ */ jsx(AddFileSection, {}),
866
+ modalConfig.showPermissions && /* @__PURE__ */ jsx(Permissions, {}),
867
+ modalConfig.showDirectoriesStructure && /* @__PURE__ */ jsx(Directory, {}),
868
+ modalConfig.showMetadata && /* @__PURE__ */ jsx(Metadata.component, {})
869
+ ] })
870
+ ]
871
+ }
872
+ );
873
+ });
874
+
875
+ function openUploaderModal(c) {
876
+ ApiaUtil.instance.modals.open({
877
+ children: /* @__PURE__ */ jsx(FileUploadProvider, { store: c, children: /* @__PURE__ */ jsx(UploaderContent, {}) }),
878
+ size: "fileModal",
879
+ noHeader: true,
880
+ initialFocusGetter(ref) {
881
+ return ref.querySelector(".dropzone");
882
+ },
883
+ onConfirm: async () => {
884
+ const isValid = await c.confirm();
885
+ if (isValid) {
886
+ c.onCloseModal();
887
+ return true;
888
+ }
889
+ const dropzone = document.querySelector(".dropzoneModal");
890
+ if (dropzone && c.state.fileReqError) {
891
+ dropzone.focus();
892
+ } else {
893
+ document.querySelector(
894
+ ".metadata__table_container .metadata__field:has(+ .errorRequired)"
895
+ )?.focus();
896
+ }
897
+ return false;
898
+ },
899
+ onCancel() {
900
+ c.onCloseModal();
901
+ },
902
+ onExited() {
903
+ c.onCloseModal();
904
+ },
905
+ onClose() {
906
+ c.onCloseModal();
907
+ }
908
+ });
909
+ }
910
+
911
+ const FileIconRenderer = observer(({ node }) => {
912
+ return /* @__PURE__ */ jsx(FileIcon, { iconSize: "sm", docName: node.state.label });
913
+ });
914
+
915
+ const FolderIconRenderer = observer(({ node }) => {
916
+ return node.state.isExpanded ? /* @__PURE__ */ jsx(Icon, { title: "", name: "FolderOpen" }) : /* @__PURE__ */ jsx(Icon, { title: "", name: "FolderClosed" });
917
+ });
918
+
919
+ const LoadMoreRenderer = observer(({ node }) => {
920
+ return /* @__PURE__ */ jsx(
921
+ SimpleButton,
922
+ {
923
+ isLoading: node.state.nodeProps.isLoadingMore,
924
+ tabIndex: -1,
925
+ variant: "inherit-sm",
926
+ children: node.state.label
927
+ }
928
+ );
929
+ });
930
+
931
+ const LockedFolderIconRenderer = observer(() => {
932
+ return /* @__PURE__ */ jsx(Box, { sx: { "& *": { color: "palette.error.main" } }, children: /* @__PURE__ */ jsx(Icon, { title: "", name: "Locked" }) });
933
+ });
934
+
935
+ const DeleteDocument = (api, f, props) => {
936
+ return {
937
+ children: /* @__PURE__ */ jsx(Box, { children: getLabel("btnDel").text }),
938
+ key: "7",
939
+ onClick: async () => {
940
+ const file = api.getDocument(f.docId);
941
+ if (await ApiaUtil.instance.dialogs.confirm({
942
+ children: (
943
+ // !window.langId &&
944
+ Object.values(api.state.translatedFiles.get(file.docId) ?? {}).length > 0 ? getLabel("msgDelFileTrans").text : window.MSG_CONFIG_DELETE_DOCUMENT_FILE_INPUT_NAME.replace(
945
+ "<TOK>",
946
+ file.docName ?? file.name ?? "NONAME"
947
+ )
948
+ ),
949
+ title: window.BTN_FILE_ERASE_LBL
950
+ })) {
951
+ await api.ajaxDeleteDocument(file.docId, props?.langId);
952
+ }
953
+ }
954
+ };
955
+ };
956
+
957
+ const DownloadDocument = (api, file) => {
958
+ return {
959
+ children: /* @__PURE__ */ jsx(Box, { children: getLabel("lblDownFile").text }),
960
+ key: "3",
961
+ onClick: () => {
962
+ api.checkWebDavLock(file.docId);
963
+ api.downloadDocument(file.docId);
964
+ }
965
+ };
966
+ };
967
+
968
+ const EditDocument = (api, file) => {
969
+ return {
970
+ children: /* @__PURE__ */ jsx(Box, { children: getLabel("lblEdit").text }),
971
+ key: "2",
972
+ onClick: () => {
973
+ api.editDocument(file.docId);
974
+ }
975
+ };
976
+ };
977
+
978
+ const LockDocument = (api, file) => {
979
+ return {
980
+ icon: (file.isLocked || toBoolean(file.lock) || file.locked) && "Check",
981
+ children: /* @__PURE__ */ jsx(
982
+ Box,
983
+ {
984
+ sx: {
985
+ display: "flex",
986
+ alignItems: "center",
987
+ gap: 3
988
+ },
989
+ children: file.isLocked || toBoolean(file.lock) || file.locked ? getLabel("lblDocLockedBy", {
990
+ text: { TOK1: file.lockingUser || file?.lockedBy || "" }
991
+ }).text : getLabel("btnLock").text
992
+ }
993
+ ),
994
+ key: "5",
995
+ onClick: () => {
996
+ api.lockDocument(file.docId);
997
+ }
998
+ };
999
+ };
1000
+
1001
+ function getUploaderShownMenuOptions({
1002
+ showDownload,
1003
+ showEdition,
1004
+ showLock,
1005
+ showVersion,
1006
+ showDelete,
1007
+ showTranslate
1008
+ }, file) {
1009
+ const showEditOption = showEdition !== false && file.canEdit !== false && Number(file?.docId) >= 0 && !window.IN_MONITOR;
1010
+ const showLockOption = showLock !== false && file.canWrite !== false && Number(file?.docId) >= 0 && !window.IN_MONITOR;
1011
+ const showDownloadOption = showDownload !== false;
1012
+ const showVersionOption = showVersion !== false && file.canWrite !== false && Number(file?.docId) >= 0 && !window.IN_MONITOR;
1013
+ const showDeleteOption = showDelete !== false && file.canWrite !== false && !window.IN_MONITOR;
1014
+ const showTranslateOption = showTranslate !== false && file.canWrite !== false && !window.IN_MONITOR;
1015
+ return {
1016
+ showEditOption,
1017
+ showLockOption,
1018
+ showDownloadOption,
1019
+ showVersionOption,
1020
+ showDeleteOption,
1021
+ showTranslateOption
1022
+ };
1023
+ }
1024
+
1025
+ const VersionTable = ({
1026
+ data,
1027
+ api,
1028
+ file
1029
+ }) => {
1030
+ return /* @__PURE__ */ jsx(
1031
+ CollapsiblePanel,
1032
+ {
1033
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("sbtDocVer").text }),
1034
+ id: "versions_infoModal",
1035
+ collapseIconToRight: true,
1036
+ closedIcon: "ArrowUpThin",
1037
+ openIcon: "ArrowDownThin",
1038
+ defaultCollapsed: true,
1039
+ children: /* @__PURE__ */ jsx(Box, { className: "doc_info_table_container", children: /* @__PURE__ */ jsxs("table", { className: "doc_info_table versions_table", children: [
1040
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
1041
+ /* @__PURE__ */ jsx("th", { children: getLabel("lblVer").text }),
1042
+ /* @__PURE__ */ jsx("th", { children: getLabel("lblUsu").text }),
1043
+ /* @__PURE__ */ jsx("th", { children: getLabel("lblDate").text })
1044
+ ] }) }),
1045
+ /* @__PURE__ */ jsx("tbody", { children: data.map((version, index) => /* @__PURE__ */ jsxs("tr", { children: [
1046
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(
1047
+ SimpleButton,
1048
+ {
1049
+ variant: "link",
1050
+ onClick: () => {
1051
+ api.downloadVersion(file.docId, version.verNumber);
1052
+ },
1053
+ children: version.verNumber
1054
+ }
1055
+ ) }),
1056
+ /* @__PURE__ */ jsx("td", { children: version.verUser }),
1057
+ /* @__PURE__ */ jsx("td", { children: version.verDate })
1058
+ ] }, index)) })
1059
+ ] }) })
1060
+ }
1061
+ );
1062
+ };
1063
+
1064
+ const PermissionsInfo = ({ data }) => {
1065
+ return /* @__PURE__ */ jsxs(
1066
+ CollapsiblePanel,
1067
+ {
1068
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("lblPer").text }),
1069
+ id: "permissions_infoModal",
1070
+ collapseIconToRight: true,
1071
+ closedIcon: "ArrowUpThin",
1072
+ openIcon: "ArrowDownThin",
1073
+ className: "uploader__permissions",
1074
+ defaultCollapsed: true,
1075
+ children: [
1076
+ /* @__PURE__ */ jsxs(Box, { className: "allPermissions", children: [
1077
+ /* @__PURE__ */ jsx("span", { children: getLabel("lblTod").text }),
1078
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: data.allPoolPermission, children: [
1079
+ /* @__PURE__ */ jsx("option", { value: "M", children: getLabel("lblPerMod").text }),
1080
+ /* @__PURE__ */ jsx("option", { value: "R", children: getLabel("lblPerVer").text }),
1081
+ /* @__PURE__ */ jsx("option", { value: "", children: getLabel("lblAccessDenied").text })
1082
+ ] })
1083
+ ] }),
1084
+ /* @__PURE__ */ jsx(Box, { className: "permissions__list", children: /* @__PURE__ */ jsxs(Box, { as: "ul", children: [
1085
+ arrayOrArray(data.permissions?.user).map((c) => {
1086
+ return /* @__PURE__ */ jsx(Box, { as: "li", children: /* @__PURE__ */ jsx(
1087
+ SwitchCard,
1088
+ {
1089
+ label: c.name,
1090
+ align: "right",
1091
+ icon: "User2",
1092
+ value: c.permType === "M" ? true : false,
1093
+ switchProps: { disabled: true }
1094
+ }
1095
+ ) }, c.id);
1096
+ }),
1097
+ arrayOrArray(data.permissions?.pool).map((c) => {
1098
+ return /* @__PURE__ */ jsx(Box, { as: "li", children: /* @__PURE__ */ jsx(
1099
+ SwitchCard,
1100
+ {
1101
+ label: c.name,
1102
+ align: "right",
1103
+ icon: "Groups",
1104
+ value: c.permType === "M" ? true : false,
1105
+ switchProps: { disabled: true }
1106
+ }
1107
+ ) }, c.id);
1108
+ })
1109
+ ] }) })
1110
+ ]
1111
+ }
1112
+ );
1113
+ };
1114
+
1115
+ const InfoTable = ({
1116
+ data,
1117
+ docId
1118
+ }) => {
1119
+ return /* @__PURE__ */ jsx(Box, { as: "table", variant: "layout.common.tables.information", children: /* @__PURE__ */ jsxs("tbody", { children: [
1120
+ /* @__PURE__ */ jsxs("tr", { children: [
1121
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1122
+ getLabel("lblDocType").text,
1123
+ ":"
1124
+ ] }) }),
1125
+ /* @__PURE__ */ jsx("td", { children: data.type })
1126
+ ] }),
1127
+ /* @__PURE__ */ jsxs("tr", { children: [
1128
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1129
+ getLabel("lblDocName").text,
1130
+ ":"
1131
+ ] }) }),
1132
+ /* @__PURE__ */ jsx("td", { children: data.name })
1133
+ ] }),
1134
+ /* @__PURE__ */ jsxs("tr", { children: [
1135
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1136
+ getLabel("lblDes").text,
1137
+ ":"
1138
+ ] }) }),
1139
+ /* @__PURE__ */ jsx("td", { children: data.description })
1140
+ ] }),
1141
+ /* @__PURE__ */ jsxs("tr", { children: [
1142
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1143
+ getLabel("lblExpDate").text,
1144
+ ":"
1145
+ ] }) }),
1146
+ /* @__PURE__ */ jsx("td", { children: data.expirationDate })
1147
+ ] }),
1148
+ data.folderPath && /* @__PURE__ */ jsxs("tr", { children: [
1149
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1150
+ getLabel("lblDir").text,
1151
+ ":"
1152
+ ] }) }),
1153
+ /* @__PURE__ */ jsx("td", { children: data.folderPath })
1154
+ ] }),
1155
+ /* @__PURE__ */ jsxs("tr", { children: [
1156
+ /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsxs("span", { children: [
1157
+ getLabel("lblDwnLink").text,
1158
+ ":"
1159
+ ] }) }),
1160
+ Number(docId) > 0 && /* @__PURE__ */ jsxs(Box, { as: "td", className: "table__buttons", children: [
1161
+ /* @__PURE__ */ jsx(
1162
+ IconButton,
1163
+ {
1164
+ icon: "Download",
1165
+ size: "Lg",
1166
+ onClick: () => {
1167
+ window.open(data.downloadLink, "_blank");
1168
+ }
1169
+ }
1170
+ ),
1171
+ /* @__PURE__ */ jsx(
1172
+ IconButton,
1173
+ {
1174
+ icon: "Copy",
1175
+ size: "Lg",
1176
+ title: getLabel("lblCpyLink").text,
1177
+ onClick: () => {
1178
+ navigator.clipboard.writeText(data.downloadLink).then(() => {
1179
+ ApiaUtil.instance.notifications.notify({
1180
+ message: getLabel("lblCopiedLink").text,
1181
+ type: "success"
1182
+ });
1183
+ console.log("Download link copied to clipboard");
1184
+ }).catch((err) => {
1185
+ console.error("Failed to copy download link:", err);
1186
+ });
1187
+ }
1188
+ }
1189
+ )
1190
+ ] })
1191
+ ] })
1192
+ ] }) });
1193
+ };
1194
+
1195
+ const MetadataTable = ({
1196
+ data
1197
+ }) => {
1198
+ return /* @__PURE__ */ jsx(
1199
+ CollapsiblePanel,
1200
+ {
1201
+ label: /* @__PURE__ */ jsx("span", { children: getLabel("titMetadata").text }),
1202
+ id: "metadata_infoModal",
1203
+ collapseIconToRight: true,
1204
+ closedIcon: "ArrowUpThin",
1205
+ openIcon: "ArrowDownThin",
1206
+ defaultCollapsed: true,
1207
+ children: /* @__PURE__ */ jsx(Box, { className: "doc_info_table_container", children: /* @__PURE__ */ jsxs("table", { className: "doc_info_table", children: [
1208
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
1209
+ /* @__PURE__ */ jsx("th", { children: getLabel("lblTit").text }),
1210
+ /* @__PURE__ */ jsx("th", { children: getLabel("lblVal").text })
1211
+ ] }) }),
1212
+ /* @__PURE__ */ jsx("tbody", { children: data.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
1213
+ /* @__PURE__ */ jsx("td", { children: item.title }),
1214
+ /* @__PURE__ */ jsx("td", { children: item.value })
1215
+ ] }, index)) })
1216
+ ] }) })
1217
+ }
1218
+ );
1219
+ };
1220
+
1221
+ const DocInfoModal = (api, file) => {
1222
+ return {
1223
+ children: /* @__PURE__ */ jsx(Box, { children: getLabel("btnInfo").text }),
1224
+ key: "1",
1225
+ onClick: async () => {
1226
+ const data = {
1227
+ ...parseDocumentInfo(await api.getDocumentInfo({ docId: file.docId }))
1228
+ };
1229
+ ApiaUtil.instance.modals.open({
1230
+ children: /* @__PURE__ */ jsx(DocModalComponent, { data, file, api }),
1231
+ size: "flex",
1232
+ title: getLabel("btnInfo").text
1233
+ });
1234
+ }
1235
+ };
1236
+ };
1237
+ const DocModalComponent = ({
1238
+ data,
1239
+ file,
1240
+ api
1241
+ }) => {
1242
+ return /* @__PURE__ */ jsxs(Box, { ...getVariant("layout.common.components.uploader.infoModal"), children: [
1243
+ /* @__PURE__ */ jsx(InfoTable, { data, docId: file.docId }),
1244
+ /* @__PURE__ */ jsx(PermissionsInfo, { data }),
1245
+ data.versions.length > 0 && /* @__PURE__ */ jsx(VersionTable, { data: data.versions, api, file }),
1246
+ data.metadata.length > 0 && /* @__PURE__ */ jsx(MetadataTable, { data: data.metadata })
1247
+ ] });
1248
+ };
1249
+ function parseDocumentInfo(data) {
1250
+ if (!data)
1251
+ throw new Error("There is no data in DocumentInfoModal");
1252
+ const { general } = data.function.data;
1253
+ return {
1254
+ docId: general.docId,
1255
+ allPoolPermission: general.docAllPoolPerm,
1256
+ description: general.docDesc,
1257
+ downloadLink: general.docDwnExternal,
1258
+ expirationDate: general.docExpDate ?? "",
1259
+ metadata: arrayOrArray(data.function.metadatas?.metadata),
1260
+ name: general.docName,
1261
+ permissions: data.function.data?.permissions,
1262
+ type: general.docTypeLabel,
1263
+ versions: arrayOrArray(data.function.data?.versions?.version),
1264
+ folderPath: data.function.data.general.docFolderPath
1265
+ };
1266
+ }
1267
+
1268
+ const VersionDocument = (api, file) => {
1269
+ return {
1270
+ children: /* @__PURE__ */ jsx(Box, { children: getLabel("lblUploadNewVersion").text }),
1271
+ key: "6",
1272
+ onClick: async () => {
1273
+ if (!api.modalConfig.oneClickUpload) {
1274
+ api.onVersionUpload(file);
1275
+ return;
1276
+ }
1277
+ const input = document.createElement("input");
1278
+ input.type = "file";
1279
+ input.multiple = true;
1280
+ input.style.display = "none";
1281
+ const cleanup = () => {
1282
+ input.removeEventListener("change", onChange);
1283
+ if (input.parentNode)
1284
+ input.parentNode.removeChild(input);
1285
+ };
1286
+ const onChange = (e) => {
1287
+ try {
1288
+ const target = e.target;
1289
+ if (target && target.files && target.files.length > 0) {
1290
+ const newFiles = Array.from(target.files);
1291
+ api.onVersionUpload(file, { newFiles });
1292
+ }
1293
+ } finally {
1294
+ cleanup();
1295
+ }
1296
+ };
1297
+ input.addEventListener("change", onChange);
1298
+ document.body.appendChild(input);
1299
+ if (api.modalConfig.oneClickUpload) {
1300
+ const checkLock = await api.checkLockDocument(file.docId, true);
1301
+ const isLocked = await api.checkWebDavLock(file.docId);
1302
+ if (checkLock === true && isLocked) {
1303
+ input.click();
1304
+ }
1305
+ } else {
1306
+ input.click();
1307
+ }
1308
+ }
1309
+ };
1310
+ };
1311
+
1312
+ function openUploaderMenu(anchor, uploaderApi, props, file, langId) {
1313
+ const {
1314
+ showDeleteOption,
1315
+ showDownloadOption,
1316
+ showEditOption,
1317
+ showLockOption,
1318
+ showTranslateOption,
1319
+ showVersionOption
1320
+ } = getUploaderShownMenuOptions(props, file);
1321
+ ApiaUtil.instance.menu.open({
1322
+ items: [
1323
+ DocInfoModal(uploaderApi, file),
1324
+ showEditOption && EditDocument(uploaderApi, file),
1325
+ showDownloadOption && DownloadDocument(uploaderApi, file),
1326
+ /**
1327
+ * Lock version and delete section
1328
+ */
1329
+ showLockOption || showVersionOption || showDeleteOption ? "separator" : null,
1330
+ showLockOption && LockDocument(uploaderApi, file),
1331
+ showVersionOption && VersionDocument(uploaderApi, file),
1332
+ showDeleteOption && DeleteDocument(uploaderApi, file, {
1333
+ langId: langId ? Number(langId) : void 0
1334
+ }),
1335
+ /**
1336
+ * Sign and translation section
1337
+ */
1338
+ showTranslateOption ? "separator" : null,
1339
+ showTranslateOption && TranslateDocument(uploaderApi, file)
1340
+ ].filter(Boolean),
1341
+ menuProps: {
1342
+ anchorRef: {
1343
+ current: anchor.closest("button")
1344
+ }
1345
+ }
1346
+ });
1347
+ }
1348
+
1349
+ const TranslateDocument = (api, file) => {
1350
+ const translationsCount = [
1351
+ ...api.state.translatedFiles.get(file.docId)?.values() ?? []
1352
+ ].length;
1353
+ return {
1354
+ children: /* @__PURE__ */ jsxs(Box, { children: [
1355
+ getLabel("btnTrans").text,
1356
+ " (",
1357
+ translationsCount,
1358
+ ")"
1359
+ ] }),
1360
+ key: "9",
1361
+ onClick: () => {
1362
+ ApiaUtil.instance.modals.open({
1363
+ title: getLabel("titTra").text,
1364
+ children: /* @__PURE__ */ jsx(TranslateDocumentModal, { api, file }),
1365
+ initialFocusGetter(ref) {
1366
+ return ref.querySelector(".dropzone");
1367
+ }
1368
+ });
1369
+ }
1370
+ };
1371
+ };
1372
+ const TranslateDocumentModal = observer(
1373
+ ({ api, file }) => {
1374
+ const langs = Object.entries(api.langs ?? {}).map(([key, value]) => ({
1375
+ id: key,
1376
+ title: String(value)
1377
+ }));
1378
+ const translateFileMap = api.state.translatedFiles.get(file.docId);
1379
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 3 }, children: [
1380
+ /* @__PURE__ */ jsx(Box, { sx: { fontWeight: "bold" }, children: getLabel("lblTranslatesForFile", {
1381
+ text: { TOK1: file.docName ?? "" }
1382
+ }).text }),
1383
+ langs.map((c) => {
1384
+ const translatedFile = translateFileMap?.get(Number(c.id));
1385
+ return /* @__PURE__ */ jsxs(Box, { children: [
1386
+ /* @__PURE__ */ jsx("span", { children: c.title }),
1387
+ translateFileMap && translatedFile ? /* @__PURE__ */ jsx(
1388
+ FileCard,
1389
+ {
1390
+ name: translatedFile.docName ?? "",
1391
+ width: "100%",
1392
+ additionalButtons: [
1393
+ {
1394
+ icon: "Download",
1395
+ size: "Lg",
1396
+ iconSize: 20,
1397
+ onClick: (e) => {
1398
+ e.stopPropagation();
1399
+ api.checkWebDavLock(translatedFile.docId);
1400
+ api.downloadDocument(translatedFile.docId);
1401
+ }
1402
+ },
1403
+ {
1404
+ icon: "Ellipsis",
1405
+ size: "Lg",
1406
+ iconSize: 20,
1407
+ onClick: (e) => {
1408
+ e.stopPropagation();
1409
+ openUploaderMenu(
1410
+ e.target,
1411
+ api,
1412
+ {
1413
+ showTranslate: false,
1414
+ showEdition: false,
1415
+ showLock: true,
1416
+ showDelete: true,
1417
+ showDownload: true,
1418
+ showVersion: false
1419
+ },
1420
+ translatedFile,
1421
+ c.id
1422
+ );
1423
+ },
1424
+ onDoubleClick: (e) => {
1425
+ e.stopPropagation();
1426
+ }
1427
+ }
1428
+ ]
1429
+ }
1430
+ ) : /* @__PURE__ */ jsx(
1431
+ Dropzone,
1432
+ {
1433
+ onClick: (ev) => {
1434
+ if (!api.modalConfig.oneClickUpload) {
1435
+ ev.preventDefault();
1436
+ api.onTranslateUpload({
1437
+ langId: Number(c.id),
1438
+ translatingFile: file
1439
+ });
1440
+ }
1441
+ },
1442
+ onChange: (e) => {
1443
+ api.onTranslateUpload(
1444
+ {
1445
+ langId: Number(c.id),
1446
+ translatingFile: file
1447
+ },
1448
+ e
1449
+ );
1450
+ }
1451
+ }
1452
+ )
1453
+ ] });
1454
+ })
1455
+ ] });
1456
+ }
1457
+ );
1458
+
1459
+ const UploadedFiles = observer(
1460
+ ({
1461
+ uploaderApi,
1462
+ hideDropzone,
1463
+ openContextMenu
1464
+ }) => {
1465
+ const existingFiles = uploaderApi.filesArray;
1466
+ const handleFileClick = (e, file) => {
1467
+ if (e.ctrlKey) {
1468
+ uploaderApi.state.selectedFiles = uploaderApi.state.selectedFiles.filter((id) => id !== file.docId);
1469
+ } else {
1470
+ if (!uploaderApi.state.selectedFiles.includes(file.docId)) {
1471
+ uploaderApi.state.selectedFiles.push(file.docId);
1472
+ }
1473
+ }
1474
+ };
1475
+ const handleInfoButton = useCallback(
1476
+ (ev) => ApiaUtil.instance.tooltips.open({
1477
+ attachToElement: () => ev.target,
1478
+ children: makeDocTypeTooltip(uploaderApi)
1479
+ }),
1480
+ [uploaderApi]
1481
+ );
1482
+ return /* @__PURE__ */ jsxs(
1483
+ Box,
1484
+ {
1485
+ sx: {
1486
+ p: 4,
1487
+ display: "flex",
1488
+ flexDirection: "column",
1489
+ gap: 4
1490
+ },
1491
+ children: [
1492
+ !hideDropzone && /* @__PURE__ */ jsx(
1493
+ Dropzone,
1494
+ {
1495
+ progress: uploaderApi.state.progress,
1496
+ className: "dropzone__uploadedfiles",
1497
+ onClick: (ev) => {
1498
+ if (!uploaderApi.modalConfig.oneClickUpload) {
1499
+ ev.preventDefault();
1500
+ uploaderApi.onStartUpload();
1501
+ }
1502
+ },
1503
+ onChange: (e) => {
1504
+ uploaderApi.onStartUpload(e);
1505
+ },
1506
+ handleInfoButton: (e) => handleInfoButton(e)
1507
+ }
1508
+ ),
1509
+ /* @__PURE__ */ jsxs(Box, { className: "uploadedFiles__container", children: [
1510
+ existingFiles.length > 0 && /* @__PURE__ */ jsx(
1511
+ Box,
1512
+ {
1513
+ ...getVariant("layout.common.components.uploader.filesList"),
1514
+ className: "uploadedFiles",
1515
+ children: uploaderApi.filesArray.map((c) => {
1516
+ return /* @__PURE__ */ createElement(
1517
+ FileCard,
1518
+ {
1519
+ ...Number(c.docId) >= 0 ? {
1520
+ onDropFiles: (files) => {
1521
+ uploaderApi.onVersionUpload(
1522
+ uploaderApi.state.files[c.docId],
1523
+ { newFiles: files }
1524
+ );
1525
+ }
1526
+ } : {},
1527
+ className: `${uploaderApi.state.selectedFiles.find((current) => current === c.docId) ? "selected" : ""}`,
1528
+ key: c.docId,
1529
+ name: c.docName ?? "",
1530
+ width: "100%",
1531
+ onClick: (e) => handleFileClick(e, c),
1532
+ onDoubleClick: () => {
1533
+ uploaderApi.downloadDocument(c.docId);
1534
+ },
1535
+ additionalButtons: [
1536
+ {
1537
+ icon: "Download",
1538
+ size: "Lg",
1539
+ iconSize: 20,
1540
+ onClick: (e) => {
1541
+ e.stopPropagation();
1542
+ uploaderApi.downloadDocument(c.docId);
1543
+ }
1544
+ },
1545
+ {
1546
+ icon: "Ellipsis",
1547
+ size: "Lg",
1548
+ iconSize: 20,
1549
+ onClick: (e) => {
1550
+ e.stopPropagation();
1551
+ (openContextMenu ? openContextMenu : openUploaderMenu)(
1552
+ e.target,
1553
+ uploaderApi,
1554
+ {
1555
+ showEdition: toBoolean(window.IS_EDITION_ALLOWED),
1556
+ showTranslate: uploaderApi.context.allowTranslation
1557
+ },
1558
+ c
1559
+ );
1560
+ },
1561
+ onDoubleClick: (e) => {
1562
+ e.stopPropagation();
1563
+ }
1564
+ }
1565
+ ]
1566
+ }
1567
+ );
1568
+ })
1569
+ }
1570
+ ),
1571
+ /* @__PURE__ */ jsx(
1572
+ SimpleButton,
1573
+ {
1574
+ variant: "outline-sm",
1575
+ className: "download_Button",
1576
+ onClick: () => {
1577
+ uploaderApi.downloadMultipleDocuments();
1578
+ },
1579
+ children: getLabel("btnDow").text
1580
+ }
1581
+ )
1582
+ ] })
1583
+ ]
1584
+ }
1585
+ );
1586
+ }
1587
+ );
1588
+
1589
+ export { AddFileSection, DeleteDocument, Directory, DocInfoModal, DownloadDocument, EditDocument, FileIconRenderer, FileUploadProvider, FolderIconRenderer, InfoTable, LoadMoreRenderer, LockDocument, LockedFolderIconRenderer, MetadataTable$1 as MetadataTable, Permissions, PermissionsInfo, TranslateDocument, TranslateDocumentModal, UploadedFiles, UploaderContent, UploaderFileHeader, VersionDocument, VersionTable, getUploaderShownMenuOptions, makeDocTypeTooltip, openUploaderMenu, openUploaderModal, parseDocumentInfo, useFileUploadContext };
1590
+ //# sourceMappingURL=index.js.map