@geotab/zenith 3.18.0 → 3.19.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.
Files changed (89) hide show
  1. package/README.md +9 -0
  2. package/dist/chart/accessibleChart/accessibleChartTable.d.ts +1 -1
  3. package/dist/chart/accessibleChart/accessibleChartTable.js +29 -6
  4. package/dist/chart/accessibleChart/interfaces.d.ts +8 -2
  5. package/dist/chart/barChart.d.ts +3 -1
  6. package/dist/chart/barChart.js +5 -3
  7. package/dist/chart/lineChart.d.ts +3 -1
  8. package/dist/chart/lineChart.js +5 -3
  9. package/dist/chart/pieChart.d.ts +3 -1
  10. package/dist/chart/pieChart.js +5 -3
  11. package/dist/chart/utils/isEmptyDataPoint.d.ts +1 -0
  12. package/dist/chart/utils/isEmptyDataPoint.js +5 -0
  13. package/dist/dataGrid/columns/mainColumn/mainColumnWrapper.d.ts +2 -0
  14. package/dist/dataGrid/columns/mainColumn/mainColumnWrapper.js +2 -2
  15. package/dist/fileUpload/components/filePreview.d.ts +15 -0
  16. package/dist/fileUpload/components/filePreview.js +272 -0
  17. package/dist/fileUpload/components/previewableFile.d.ts +16 -0
  18. package/dist/fileUpload/components/previewableFile.js +48 -0
  19. package/dist/fileUpload/components/resolveFileActions.d.ts +10 -0
  20. package/dist/fileUpload/components/resolveFileActions.js +11 -0
  21. package/dist/fileUpload/components/uploadedFilesSection.d.ts +9 -1
  22. package/dist/fileUpload/components/uploadedFilesSection.js +91 -16
  23. package/dist/fileUpload/components/useFilePreview.d.ts +12 -0
  24. package/dist/fileUpload/components/useFilePreview.js +85 -0
  25. package/dist/fileUpload/fileUpload.d.ts +1 -1
  26. package/dist/fileUpload/fileUpload.js +63 -2
  27. package/dist/fileUpload/fileUploadType.d.ts +35 -0
  28. package/dist/filtersBar/components/filtersBarSearch/filtersBarSearch.d.ts +1 -1
  29. package/dist/formSection/components/formSectionCard.js +1 -1
  30. package/dist/icons/iconEngine.d.ts +3 -0
  31. package/dist/icons/iconEngine.js +12 -0
  32. package/dist/index.css +74 -2
  33. package/dist/index.d.ts +3 -1
  34. package/dist/index.js +12 -10
  35. package/dist/inputAdornments/inputAdornments.d.ts +3 -1
  36. package/dist/inputAdornments/inputAdornments.js +2 -2
  37. package/dist/lineChartMini/lineChartMini.d.ts +3 -1
  38. package/dist/lineChartMini/lineChartMini.js +5 -3
  39. package/dist/modal/modal.d.ts +2 -0
  40. package/dist/primaryIcon/primaryIcon.d.ts +3 -1
  41. package/dist/primaryIcon/primaryIcon.js +3 -3
  42. package/dist/searchInputRaw/searchInputRaw.js +4 -2
  43. package/dist/searchInputRaw/types.d.ts +2 -0
  44. package/dist/textInputRaw/textInputRaw.js +1 -1
  45. package/dist/textInputRaw/types.d.ts +2 -0
  46. package/esm/chart/accessibleChart/accessibleChartTable.d.ts +1 -1
  47. package/esm/chart/accessibleChart/accessibleChartTable.js +29 -6
  48. package/esm/chart/accessibleChart/interfaces.d.ts +8 -2
  49. package/esm/chart/barChart.d.ts +3 -1
  50. package/esm/chart/barChart.js +5 -3
  51. package/esm/chart/lineChart.d.ts +3 -1
  52. package/esm/chart/lineChart.js +5 -3
  53. package/esm/chart/pieChart.d.ts +3 -1
  54. package/esm/chart/pieChart.js +5 -3
  55. package/esm/chart/utils/isEmptyDataPoint.d.ts +1 -0
  56. package/esm/chart/utils/isEmptyDataPoint.js +1 -0
  57. package/esm/dataGrid/columns/mainColumn/mainColumnWrapper.d.ts +2 -0
  58. package/esm/dataGrid/columns/mainColumn/mainColumnWrapper.js +2 -2
  59. package/esm/fileUpload/components/filePreview.d.ts +15 -0
  60. package/esm/fileUpload/components/filePreview.js +263 -0
  61. package/esm/fileUpload/components/previewableFile.d.ts +16 -0
  62. package/esm/fileUpload/components/previewableFile.js +43 -0
  63. package/esm/fileUpload/components/resolveFileActions.d.ts +10 -0
  64. package/esm/fileUpload/components/resolveFileActions.js +7 -0
  65. package/esm/fileUpload/components/uploadedFilesSection.d.ts +9 -1
  66. package/esm/fileUpload/components/uploadedFilesSection.js +91 -16
  67. package/esm/fileUpload/components/useFilePreview.d.ts +12 -0
  68. package/esm/fileUpload/components/useFilePreview.js +81 -0
  69. package/esm/fileUpload/fileUpload.d.ts +1 -1
  70. package/esm/fileUpload/fileUpload.js +63 -2
  71. package/esm/fileUpload/fileUploadType.d.ts +35 -0
  72. package/esm/filtersBar/components/filtersBarSearch/filtersBarSearch.d.ts +1 -1
  73. package/esm/formSection/components/formSectionCard.js +1 -1
  74. package/esm/icons/iconEngine.d.ts +3 -0
  75. package/esm/icons/iconEngine.js +8 -0
  76. package/esm/index.d.ts +3 -1
  77. package/esm/index.js +1 -0
  78. package/esm/inputAdornments/inputAdornments.d.ts +3 -1
  79. package/esm/inputAdornments/inputAdornments.js +2 -2
  80. package/esm/lineChartMini/lineChartMini.d.ts +3 -1
  81. package/esm/lineChartMini/lineChartMini.js +5 -3
  82. package/esm/modal/modal.d.ts +2 -0
  83. package/esm/primaryIcon/primaryIcon.d.ts +3 -1
  84. package/esm/primaryIcon/primaryIcon.js +3 -3
  85. package/esm/searchInputRaw/searchInputRaw.js +4 -2
  86. package/esm/searchInputRaw/types.d.ts +2 -0
  87. package/esm/textInputRaw/textInputRaw.js +1 -1
  88. package/esm/textInputRaw/types.d.ts +2 -0
  89. package/package.json +1 -1
@@ -0,0 +1,263 @@
1
+ import { injectString } from "../../utils/localization/translationsDictionary";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from "react";
4
+ import { Modal } from "../../modal/modal";
5
+ import { TextIconButton } from "../../textIconButton/textIconButton";
6
+ import { ButtonType } from "../../button/buttonType";
7
+ import { SvgIconSize } from "../../svgIcon/svgIconSize";
8
+ import { IconArrowLeft } from "../../icons/iconArrowLeft";
9
+ import { IconDownload } from "../../icons/iconDownload";
10
+ import { IconOpen } from "../../icons/iconOpen";
11
+ import { zen } from "../../utils/zen";
12
+ import { Waiting } from "../../waiting/waiting";
13
+ injectString("cs", "Loading", "Na\u010D\xEDt\xE1n\xED");
14
+ injectString("da-DK", "Loading", "Indl\xE6ser");
15
+ injectString("de", "Loading", "Wird geladen");
16
+ injectString("en", "Loading", "Loading");
17
+ injectString("es", "Loading", "Cargando");
18
+ injectString("fi-FI", "Loading", "Ladataan");
19
+ injectString("fr", "Loading", "Chargement en cours");
20
+ injectString("fr-FR", "Loading", "En cours de chargement");
21
+ injectString("hu-HU", "Loading", "Bet\xF6lt\xE9s");
22
+ injectString("id", "Loading", "Memuat");
23
+ injectString("it", "Loading", "Caricamento in corso");
24
+ injectString("ja", "Loading", "\u8AAD\u307F\u8FBC\u307F\u4E2D");
25
+ injectString("ko-KR", "Loading", "\uB85C\uB4DC \uC911");
26
+ injectString("ms", "Loading", "Memuatkan");
27
+ injectString("nb-NO", "Loading", "Laster");
28
+ injectString("nl", "Loading", "Laden");
29
+ injectString("pl", "Loading", "\u0141adowanie");
30
+ injectString("pt-BR", "Loading", "Carregando");
31
+ injectString("pt-PT", "Loading", "A carregar");
32
+ injectString("sk-SK", "Loading", "Na\u010D\xEDtanie");
33
+ injectString("sv", "Loading", "Laddar");
34
+ injectString("th", "Loading", "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14");
35
+ injectString("tr", "Loading", "Y\xFCkleniyor");
36
+ injectString("zh-Hans", "Loading", "\u6B63\u5728\u52A0\u8F7D");
37
+ injectString("zh-TW", "Loading", "\u8F09\u5165\u4E2D");
38
+ injectString("ro-RO", "Loading", "Se \xEEncarc\u0103");
39
+ injectString("ar-001", "Loading", "\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u062D\u0645\u064A\u0644");
40
+ injectString("lt-LT", "Loading", "\u012Ekeliama");
41
+ injectString("lv-LV", "Loading", "Iel\u0101d\u0113");
42
+ injectString("ka-GE", "Loading", "\u10E9\u10D0\u10E2\u10D5\u10D8\u10E0\u10D7\u10D5\u10D0");
43
+ injectString("el-GR", "Loading", "\u03A6\u03CC\u03C1\u03C4\u03C9\u03C3\u03B7");
44
+ injectString("et-EE", "Loading", "Laadimine");
45
+ injectString("bg-BG", "Loading", "\u0417\u0430\u0440\u0435\u0436\u0434\u0430\u043D\u0435");
46
+ injectString("cs", "Back", "Zp\u011Bt");
47
+ injectString("da-DK", "Back", "Tilbage");
48
+ injectString("de", "Back", "Zur\xFCck");
49
+ injectString("en", "Back", "Back");
50
+ injectString("es", "Back", "Regresar");
51
+ injectString("fi-FI", "Back", "Takaisin");
52
+ injectString("fr", "Back", "Retour");
53
+ injectString("fr-FR", "Back", "Retour");
54
+ injectString("hu-HU", "Back", "Vissza");
55
+ injectString("id", "Back", "Kembali");
56
+ injectString("it", "Back", "Indietro");
57
+ injectString("ja", "Back", "\u623B\u308B");
58
+ injectString("ko-KR", "Back", "\uB4A4\uB85C");
59
+ injectString("ms", "Back", "Kembali");
60
+ injectString("nb-NO", "Back", "Tilbake");
61
+ injectString("nl", "Back", "Terug");
62
+ injectString("pl", "Back", "Wstecz");
63
+ injectString("pt-BR", "Back", "Voltar");
64
+ injectString("pt-PT", "Back", "Voltar");
65
+ injectString("sk-SK", "Back", "Sp\xE4\u0165");
66
+ injectString("sv", "Back", "Tillbaka");
67
+ injectString("th", "Back", "\u0E01\u0E25\u0E31\u0E1A");
68
+ injectString("tr", "Back", "Geri");
69
+ injectString("zh-Hans", "Back", "\u8FD4\u56DE");
70
+ injectString("zh-TW", "Back", "\u8FD4\u56DE");
71
+ injectString("ro-RO", "Back", "\xCEnapoi");
72
+ injectString("ar-001", "Back", "\u0631\u062C\u0648\u0639");
73
+ injectString("lt-LT", "Back", "Atgal");
74
+ injectString("lv-LV", "Back", "Atpaka\u013C");
75
+ injectString("ka-GE", "Back", "\u10E3\u10D9\u10D0\u10DC");
76
+ injectString("el-GR", "Back", "\u03A0\u03AF\u03C3\u03C9");
77
+ injectString("et-EE", "Back", "Tagasi");
78
+ injectString("bg-BG", "Back", "\u041D\u0430\u0437\u0430\u0434");
79
+ injectString("en", "Open in new tab", "Open in new tab");
80
+ injectString("cs", "Download", "St\xE1hnout");
81
+ injectString("da-DK", "Download", "Download");
82
+ injectString("de", "Download", "Herunterladen");
83
+ injectString("en", "Download", "Download");
84
+ injectString("es", "Download", "Descargar");
85
+ injectString("fi-FI", "Download", "Lataa");
86
+ injectString("fr", "Download", "T\xE9l\xE9charger");
87
+ injectString("fr-FR", "Download", "T\xE9l\xE9charger");
88
+ injectString("hu-HU", "Download", "Let\xF6lt\xE9s");
89
+ injectString("id", "Download", "Unduh");
90
+ injectString("it", "Download", "Scaricare");
91
+ injectString("ja", "Download", "\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9");
92
+ injectString("ko-KR", "Download", "\uB2E4\uC6B4\uB85C\uB4DC");
93
+ injectString("ms", "Download", "Muat Turun");
94
+ injectString("nb-NO", "Download", "Last ned");
95
+ injectString("nl", "Download", "Downloaden");
96
+ injectString("pl", "Download", "Pobierz");
97
+ injectString("pt-BR", "Download", "Download");
98
+ injectString("pt-PT", "Download", "Download");
99
+ injectString("sk-SK", "Download", "Stiahni");
100
+ injectString("sv", "Download", "Ladda ned");
101
+ injectString("th", "Download", "\u0E14\u0E32\u0E27\u0E19\u0E4C\u0E42\u0E2B\u0E25\u0E14");
102
+ injectString("tr", "Download", "\u0130ndir");
103
+ injectString("zh-Hans", "Download", "\u4E0B\u8F7D");
104
+ injectString("zh-TW", "Download", "\u4E0B\u8F09");
105
+ injectString("ro-RO", "Download", "Desc\u0103rca\u021Bi");
106
+ injectString("ar-001", "Download", "\u062A\u0646\u0632\u064A\u0644");
107
+ injectString("lt-LT", "Download", "Atsisi\u0173sti");
108
+ injectString("lv-LV", "Download", "Lejupiel\u0101d\u0113t");
109
+ injectString("ka-GE", "Download", "\u10E9\u10D0\u10DB\u10DD\u10E2\u10D5\u10D8\u10E0\u10D7\u10D5\u10D0");
110
+ injectString("el-GR", "Download", "\u039B\u03AE\u03C8\u03B7");
111
+ injectString("et-EE", "Download", "Laadi alla");
112
+ injectString("bg-BG", "Download", "\u0418\u0437\u0442\u0435\u0433\u043B\u044F\u043D\u0435");
113
+ const PreviewBody = ({
114
+ fileName,
115
+ kind,
116
+ url,
117
+ translate
118
+ }) => _jsxs("div", {
119
+ className: "zen-file-upload__preview-body",
120
+ children: [url ? kind === "pdf" ? _jsx("iframe", {
121
+ className: "zen-file-upload__preview-pdf",
122
+ src: url,
123
+ title: fileName
124
+ }) : _jsx("img", {
125
+ className: "zen-file-upload__preview-image",
126
+ src: url,
127
+ alt: fileName
128
+ }) : _jsx(Waiting, {
129
+ isLoading: true,
130
+ delay: 0,
131
+ hideOverlay: true
132
+ }), _jsx("span", {
133
+ className: "zen-visually-hidden",
134
+ role: "status",
135
+ children: url ? "" : translate("Loading")
136
+ })]
137
+ });
138
+ const InlinePreview = ({
139
+ analyticsBase,
140
+ fileName,
141
+ kind,
142
+ url,
143
+ disabled,
144
+ onClose,
145
+ onOpenInNewTab,
146
+ onDownload,
147
+ translate
148
+ }) => {
149
+ const backButtonRef = useRef(null);
150
+ // Activating View unmounts the focused row button, so focus would fall back to the page body. Move it into the preview
151
+ // once, as soon as the preview opens (while the bytes are still pending), so the keyboard user lands on Back. The effect
152
+ // runs on mount only, never on URL resolution, and closing still restores focus to the View button.
153
+ useEffect(() => {
154
+ var _a;
155
+ (_a = backButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
156
+ }, []);
157
+ return _jsxs("section", {
158
+ className: "zen-file-upload__preview-inline",
159
+ "aria-label": fileName,
160
+ children: [_jsxs("div", {
161
+ className: "zen-file-upload__preview-header",
162
+ children: [_jsx(TextIconButton, {
163
+ icon: IconArrowLeft,
164
+ iconSize: SvgIconSize.Bigger,
165
+ type: ButtonType.TertiaryBlack,
166
+ ref: backButtonRef,
167
+ onClick: onClose,
168
+ dataAnalyticsId: `${analyticsBase}-preview-back`,
169
+ ariaLabel: `${translate("Back")} ${fileName}`
170
+ }), _jsx("span", {
171
+ className: "zen-file-upload__preview-title",
172
+ children: fileName
173
+ }), _jsx(TextIconButton, {
174
+ icon: IconOpen,
175
+ iconSize: SvgIconSize.Bigger,
176
+ type: ButtonType.TertiaryBlack,
177
+ onClick: onOpenInNewTab,
178
+ dataAnalyticsId: `${analyticsBase}-preview-open-in-new-tab`,
179
+ disabled: disabled || !url,
180
+ ariaLabel: `${translate("Open in new tab")} ${fileName}`
181
+ }), onDownload && _jsx(TextIconButton, {
182
+ icon: IconDownload,
183
+ iconSize: SvgIconSize.Bigger,
184
+ type: ButtonType.TertiaryBlack,
185
+ onClick: onDownload,
186
+ dataAnalyticsId: `${analyticsBase}-preview-download`,
187
+ disabled: disabled,
188
+ ariaLabel: `${translate("Download")} ${fileName}`
189
+ })]
190
+ }), _jsx(PreviewBody, {
191
+ fileName: fileName,
192
+ kind: kind,
193
+ url: url,
194
+ translate: translate
195
+ })]
196
+ });
197
+ };
198
+ export const FilePreview = ({
199
+ analyticsBase,
200
+ preview,
201
+ onClose,
202
+ onDownload,
203
+ disabled = false,
204
+ translate
205
+ }) => {
206
+ if (!preview) {
207
+ return null;
208
+ }
209
+ const {
210
+ file,
211
+ fileName,
212
+ kind,
213
+ url,
214
+ mode
215
+ } = preview;
216
+ const handleDownload = onDownload ? () => onDownload(file) : undefined;
217
+ const handleOpenInNewTab = () => {
218
+ var _a;
219
+ return url && ((_a = zen.open) === null || _a === void 0 ? void 0 : _a.call(zen, url, "_blank", "noopener"));
220
+ };
221
+ if (mode === "modal") {
222
+ return _jsxs(Modal, {
223
+ isOpen: true,
224
+ onClose: onClose,
225
+ title: fileName,
226
+ closeOnClickOutside: true,
227
+ maxWidth: "800px",
228
+ children: [_jsx(PreviewBody, {
229
+ fileName: fileName,
230
+ kind: kind,
231
+ url: url,
232
+ translate: translate
233
+ }), _jsx(Modal.SecondaryButton, {
234
+ icon: IconOpen,
235
+ dataAnalyticsId: `${analyticsBase}-preview-open-in-new-tab`,
236
+ onClick: handleOpenInNewTab,
237
+ disabled: disabled || !url,
238
+ title: `${translate("Open in new tab")} ${fileName}`,
239
+ children: translate("Open in new tab")
240
+ }), handleDownload && _jsx(Modal.PrimaryButton, {
241
+ icon: IconDownload,
242
+ dataAnalyticsId: `${analyticsBase}-preview-download`,
243
+ onClick: handleDownload,
244
+ disabled: disabled,
245
+ title: `${translate("Download")} ${fileName}`,
246
+ children: translate("Download")
247
+ })]
248
+ });
249
+ }
250
+ // Inline: rendered in place inside the host container (for example a modal), so no second modal is stacked.
251
+ // Keyed by file so a different file always starts with focus on its own Back button.
252
+ return _jsx(InlinePreview, {
253
+ analyticsBase: analyticsBase,
254
+ fileName: fileName,
255
+ kind: kind,
256
+ url: url,
257
+ disabled: disabled,
258
+ onClose: onClose,
259
+ onOpenInNewTab: handleOpenInNewTab,
260
+ onDownload: handleDownload,
261
+ translate: translate
262
+ }, file.id);
263
+ };
@@ -0,0 +1,16 @@
1
+ import { IUploadedFile, TFilePreviewMode } from "../fileUploadType";
2
+ export type TPreviewKind = "image" | "pdf";
3
+ export interface IPreviewState {
4
+ file: IUploadedFile;
5
+ fileName: string;
6
+ kind: TPreviewKind;
7
+ /** undefined while the URL is still being resolved */
8
+ url?: string;
9
+ mode: TFilePreviewMode;
10
+ }
11
+ export declare const getPreviewKind: (file: IUploadedFile) => TPreviewKind | null;
12
+ /**
13
+ * The MIME type the preview bytes are labelled with. It is derived from the file kind (and the file's own metadata),
14
+ * never from the Blob the consumer returned, so bytes labelled `text/html` can never be rendered as a web page.
15
+ */
16
+ export declare const getPreviewMimeType: (file: IUploadedFile, kind: TPreviewKind) => string;
@@ -0,0 +1,43 @@
1
+ const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"];
2
+ const IMAGE_MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
3
+ const IMAGE_MIME_BY_EXTENSION = {
4
+ png: "image/png",
5
+ jpg: "image/jpeg",
6
+ jpeg: "image/jpeg",
7
+ gif: "image/gif",
8
+ webp: "image/webp"
9
+ };
10
+ export const getPreviewKind = (file) => {
11
+ var _a, _b;
12
+ const mimeType = (_a = file.type) === null || _a === void 0 ? void 0 : _a.toLowerCase();
13
+ if (mimeType === "application/pdf") {
14
+ return "pdf";
15
+ }
16
+ if (mimeType && IMAGE_MIME_TYPES.includes(mimeType)) {
17
+ return "image";
18
+ }
19
+ const extension = (_b = file.name.split(".").pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase();
20
+ if (extension === "pdf") {
21
+ return "pdf";
22
+ }
23
+ if (extension && IMAGE_EXTENSIONS.includes(extension)) {
24
+ return "image";
25
+ }
26
+ return null;
27
+ };
28
+ /**
29
+ * The MIME type the preview bytes are labelled with. It is derived from the file kind (and the file's own metadata),
30
+ * never from the Blob the consumer returned, so bytes labelled `text/html` can never be rendered as a web page.
31
+ */
32
+ export const getPreviewMimeType = (file, kind) => {
33
+ var _a, _b;
34
+ if (kind === "pdf") {
35
+ return "application/pdf";
36
+ }
37
+ const mimeType = (_a = file.type) === null || _a === void 0 ? void 0 : _a.toLowerCase();
38
+ if (mimeType && IMAGE_MIME_TYPES.includes(mimeType)) {
39
+ return mimeType;
40
+ }
41
+ const extension = (_b = file.name.split(".").pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase();
42
+ return (extension && IMAGE_MIME_BY_EXTENSION[extension]) || "image/png";
43
+ };
@@ -0,0 +1,10 @@
1
+ import { IFileUpload } from "../fileUploadType";
2
+ type TActionProps = Pick<IFileUpload, "id" | "dataAnalyticsId" | "showViewButton" | "showDownloadButton" | "onView" | "getPreviewBlob" | "onDownload">;
3
+ /** An action button is only shown when it is switched on and the consumer provided something for it to do. */
4
+ /** Which action buttons are shown, and the base for their `data-analytics-id` (defaults to the component id). */
5
+ export declare const resolveFileActions: ({ id, dataAnalyticsId, showViewButton, showDownloadButton, onView, getPreviewBlob, onDownload }: TActionProps) => {
6
+ analyticsBase: string;
7
+ canView: boolean;
8
+ canDownload: boolean;
9
+ };
10
+ export {};
@@ -0,0 +1,7 @@
1
+ /** An action button is only shown when it is switched on and the consumer provided something for it to do. */
2
+ /** Which action buttons are shown, and the base for their `data-analytics-id` (defaults to the component id). */
3
+ export const resolveFileActions = ({ id, dataAnalyticsId, showViewButton, showDownloadButton, onView, getPreviewBlob, onDownload }) => ({
4
+ analyticsBase: dataAnalyticsId !== null && dataAnalyticsId !== void 0 ? dataAnalyticsId : id,
5
+ canView: !!showViewButton && !!(onView || getPreviewBlob),
6
+ canDownload: !!showDownloadButton && !!onDownload
7
+ });
@@ -8,6 +8,14 @@ interface IUploadedFilesSectionProps {
8
8
  handleRemoveFile: (fileId: string, index: number) => void;
9
9
  translate: (key: string) => string;
10
10
  removeButtonRefs: RefObject<Map<number, HTMLButtonElement>>;
11
+ /** Base for `data-analytics-id` on the action buttons */
12
+ analyticsBase?: string;
13
+ viewButtonRefs?: RefObject<Map<string, HTMLButtonElement>>;
14
+ showRemoveButton?: boolean;
15
+ showViewButton?: boolean;
16
+ showDownloadButton?: boolean;
17
+ handleViewFile?: (file: IUploadedFile) => void;
18
+ handleDownloadFile?: (file: IUploadedFile) => void;
11
19
  }
12
- export declare const UploadedFilesSection: ({ id, uploadedFiles, disabled, isUploading, handleRemoveFile, translate, removeButtonRefs }: IUploadedFilesSectionProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const UploadedFilesSection: ({ id, uploadedFiles, disabled, isUploading, handleRemoveFile, translate, removeButtonRefs, analyticsBase, viewButtonRefs, showRemoveButton, showViewButton, showDownloadButton, handleViewFile, handleDownloadFile }: IUploadedFilesSectionProps) => import("react/jsx-runtime").JSX.Element;
13
21
  export {};
@@ -6,10 +6,13 @@ import { IconExcel } from "../../icons/iconExcel";
6
6
  import { IconPDF } from "../../icons/iconPDF";
7
7
  import { IconDocument } from "../../icons/iconDocument";
8
8
  import { IconClose } from "../../icons/iconClose";
9
+ import { IconEye } from "../../icons/iconEye";
10
+ import { IconDownload } from "../../icons/iconDownload";
9
11
  import { Banner } from "../../banner/banner";
10
12
  import { TextIconButton } from "../../textIconButton/textIconButton";
11
13
  import { ButtonType } from "../../button/buttonType";
12
14
  import { SvgIconSize } from "../../svgIcon/svgIconSize";
15
+ import { getPreviewKind } from "./previewableFile";
13
16
  injectString("cs", "Uploaded", "Uploaded");
14
17
  injectString("da-DK", "Uploaded", "Uploadet");
15
18
  injectString("de", "Uploaded", "Uploaded");
@@ -43,6 +46,40 @@ injectString("ka-GE", "Uploaded", "\u10D0\u10E2\u10D5\u10D8\u10E0\u10D7\u10E3\u1
43
46
  injectString("el-GR", "Uploaded", "\u0391\u03BD\u03B5\u03B2\u03AC\u03C3\u03C4\u03B7\u03BA\u03B5");
44
47
  injectString("et-EE", "Uploaded", "\xDCles laaditud");
45
48
  injectString("bg-BG", "Uploaded", "\u041A\u0430\u0447\u0435\u043D\u043E");
49
+ injectString("en", "View", "View");
50
+ injectString("cs", "Download", "St\xE1hnout");
51
+ injectString("da-DK", "Download", "Download");
52
+ injectString("de", "Download", "Herunterladen");
53
+ injectString("en", "Download", "Download");
54
+ injectString("es", "Download", "Descargar");
55
+ injectString("fi-FI", "Download", "Lataa");
56
+ injectString("fr", "Download", "T\xE9l\xE9charger");
57
+ injectString("fr-FR", "Download", "T\xE9l\xE9charger");
58
+ injectString("hu-HU", "Download", "Let\xF6lt\xE9s");
59
+ injectString("id", "Download", "Unduh");
60
+ injectString("it", "Download", "Scaricare");
61
+ injectString("ja", "Download", "\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9");
62
+ injectString("ko-KR", "Download", "\uB2E4\uC6B4\uB85C\uB4DC");
63
+ injectString("ms", "Download", "Muat Turun");
64
+ injectString("nb-NO", "Download", "Last ned");
65
+ injectString("nl", "Download", "Downloaden");
66
+ injectString("pl", "Download", "Pobierz");
67
+ injectString("pt-BR", "Download", "Download");
68
+ injectString("pt-PT", "Download", "Download");
69
+ injectString("sk-SK", "Download", "Stiahni");
70
+ injectString("sv", "Download", "Ladda ned");
71
+ injectString("th", "Download", "\u0E14\u0E32\u0E27\u0E19\u0E4C\u0E42\u0E2B\u0E25\u0E14");
72
+ injectString("tr", "Download", "\u0130ndir");
73
+ injectString("zh-Hans", "Download", "\u4E0B\u8F7D");
74
+ injectString("zh-TW", "Download", "\u4E0B\u8F09");
75
+ injectString("ro-RO", "Download", "Desc\u0103rca\u021Bi");
76
+ injectString("ar-001", "Download", "\u062A\u0646\u0632\u064A\u0644");
77
+ injectString("lt-LT", "Download", "Atsisi\u0173sti");
78
+ injectString("lv-LV", "Download", "Lejupiel\u0101d\u0113t");
79
+ injectString("ka-GE", "Download", "\u10E9\u10D0\u10DB\u10DD\u10E2\u10D5\u10D8\u10E0\u10D7\u10D5\u10D0");
80
+ injectString("el-GR", "Download", "\u039B\u03AE\u03C8\u03B7");
81
+ injectString("et-EE", "Download", "Laadi alla");
82
+ injectString("bg-BG", "Download", "\u0418\u0437\u0442\u0435\u0433\u043B\u044F\u043D\u0435");
46
83
  injectString("cs", "Remove", "Odebrat");
47
84
  injectString("da-DK", "Remove", "Fjern");
48
85
  injectString("de", "Remove", "Entfernen");
@@ -105,7 +142,14 @@ export const UploadedFilesSection = ({
105
142
  isUploading,
106
143
  handleRemoveFile,
107
144
  translate,
108
- removeButtonRefs
145
+ removeButtonRefs,
146
+ analyticsBase = id,
147
+ viewButtonRefs,
148
+ showRemoveButton = true,
149
+ showViewButton = false,
150
+ showDownloadButton = false,
151
+ handleViewFile,
152
+ handleDownloadFile
109
153
  }) => _jsxs("div", {
110
154
  className: "zen-file-upload__uploaded",
111
155
  children: [_jsx("span", {
@@ -119,6 +163,8 @@ export const UploadedFilesSection = ({
119
163
  const FileIcon = getFileIcon(file);
120
164
  const hasError = file.hasError || !!file.errorMessage;
121
165
  const fileItemClasses = classNames(["zen-file-upload__file-item", hasError ? "zen-file-upload__file-item--error" : ""]);
166
+ const canView = showViewButton && !!handleViewFile && !hasError && getPreviewKind(file) !== null;
167
+ const canDownload = showDownloadButton && !!handleDownloadFile && !hasError;
122
168
  const fileNameClasses = classNames(["zen-file-upload__file-name", hasError ? "zen-file-upload__file-name--error" : ""]);
123
169
  return _jsxs("li", {
124
170
  className: "zen-file-upload__file-list-item",
@@ -139,21 +185,50 @@ export const UploadedFilesSection = ({
139
185
  className: fileNameClasses,
140
186
  children: file.name
141
187
  })]
142
- }), _jsx(TextIconButton, {
143
- ref: el => {
144
- if (el) {
145
- removeButtonRefs.current.set(index, el);
146
- } else {
147
- removeButtonRefs.current.delete(index);
148
- }
149
- },
150
- icon: IconClose,
151
- iconSize: SvgIconSize.Bigger,
152
- type: ButtonType.TertiaryBlack,
153
- className: "zen-file-upload__remove-button",
154
- onClick: () => handleRemoveFile(file.id, index),
155
- ariaLabel: `${translate("Remove")} ${file.name}`,
156
- disabled: disabled || isUploading
188
+ }), (canView || canDownload || showRemoveButton) && _jsxs("div", {
189
+ className: "zen-file-upload__file-actions",
190
+ children: [canView && _jsx(TextIconButton, {
191
+ ref: el => {
192
+ if (el) {
193
+ viewButtonRefs === null || viewButtonRefs === void 0 ? void 0 : viewButtonRefs.current.set(file.id, el);
194
+ } else {
195
+ viewButtonRefs === null || viewButtonRefs === void 0 ? void 0 : viewButtonRefs.current.delete(file.id);
196
+ }
197
+ },
198
+ icon: IconEye,
199
+ iconSize: SvgIconSize.Bigger,
200
+ type: ButtonType.TertiaryBlack,
201
+ className: "zen-file-upload__view-button",
202
+ dataAnalyticsId: `${analyticsBase}-view`,
203
+ onClick: () => handleViewFile(file),
204
+ ariaLabel: `${translate("View")} ${file.name}`,
205
+ disabled: disabled || isUploading
206
+ }), canDownload && _jsx(TextIconButton, {
207
+ icon: IconDownload,
208
+ iconSize: SvgIconSize.Bigger,
209
+ type: ButtonType.TertiaryBlack,
210
+ className: "zen-file-upload__download-button",
211
+ dataAnalyticsId: `${analyticsBase}-download`,
212
+ onClick: () => handleDownloadFile(file),
213
+ ariaLabel: `${translate("Download")} ${file.name}`,
214
+ disabled: disabled || isUploading
215
+ }), showRemoveButton && _jsx(TextIconButton, {
216
+ ref: el => {
217
+ if (el) {
218
+ removeButtonRefs.current.set(index, el);
219
+ } else {
220
+ removeButtonRefs.current.delete(index);
221
+ }
222
+ },
223
+ icon: IconClose,
224
+ iconSize: SvgIconSize.Bigger,
225
+ type: ButtonType.TertiaryBlack,
226
+ className: "zen-file-upload__remove-button",
227
+ dataAnalyticsId: `${analyticsBase}-remove`,
228
+ onClick: () => handleRemoveFile(file.id, index),
229
+ ariaLabel: `${translate("Remove")} ${file.name}`,
230
+ disabled: disabled || isUploading
231
+ })]
157
232
  })]
158
233
  })]
159
234
  }, file.id);
@@ -0,0 +1,12 @@
1
+ import { RefObject } from "react";
2
+ import { IFileUpload, IUploadedFile } from "../fileUploadType";
3
+ import { IPreviewState } from "./previewableFile";
4
+ interface IUseFilePreviewProps extends Pick<IFileUpload, "onView" | "getPreviewBlob" | "previewMode"> {
5
+ viewButtonRefs: RefObject<Map<string, HTMLButtonElement>>;
6
+ }
7
+ export declare const useFilePreview: ({ onView, getPreviewBlob, previewMode, viewButtonRefs }: IUseFilePreviewProps) => {
8
+ preview: IPreviewState | null;
9
+ handleViewFile: (file: IUploadedFile) => Promise<void>;
10
+ handleClosePreview: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,81 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { zen } from "../../utils/zen";
3
+ import { getPreviewKind, getPreviewMimeType } from "./previewableFile";
4
+ export const useFilePreview = ({ onView, getPreviewBlob, previewMode = "modal", viewButtonRefs }) => {
5
+ const [previewFile, setPreviewFile] = useState(null);
6
+ const [previewUrl, setPreviewUrl] = useState(undefined);
7
+ // Incremented on every open and every close, so a slow getPreviewBlob() from an earlier request can never
8
+ // overwrite or close a newer preview, even when the same file is closed and reopened.
9
+ const requestTokenRef = useRef(0);
10
+ const openFileIdRef = useRef(null);
11
+ // The object URL Zenith created for the open preview. It is the only URL the preview and Open in new tab use.
12
+ const objectUrlRef = useRef(null);
13
+ const revokeObjectUrl = useCallback(() => {
14
+ if (objectUrlRef.current) {
15
+ URL.revokeObjectURL(objectUrlRef.current);
16
+ objectUrlRef.current = null;
17
+ }
18
+ }, []);
19
+ // On unmount: invalidate any pending getPreviewBlob() request first, so it cannot resolve later, pass the token check,
20
+ // create an object URL nothing would ever revoke, or set state on a component that is gone. Then revoke the current URL.
21
+ useEffect(() => () => {
22
+ requestTokenRef.current += 1;
23
+ openFileIdRef.current = null;
24
+ revokeObjectUrl();
25
+ }, [revokeObjectUrl]);
26
+ // Single close path: invalidates in-flight requests and returns focus to the View button that opened the preview.
27
+ // Inline mode unmounts that button, so focus must be restored on every close, including failed requests.
28
+ const closePreview = useCallback(() => {
29
+ var _a;
30
+ const closedId = openFileIdRef.current;
31
+ requestTokenRef.current += 1;
32
+ openFileIdRef.current = null;
33
+ revokeObjectUrl();
34
+ setPreviewFile(null);
35
+ setPreviewUrl(undefined);
36
+ if (closedId) {
37
+ (_a = zen.requestAnimationFrame) === null || _a === void 0 ? void 0 : _a.call(zen, () => { var _a; return (_a = viewButtonRefs.current.get(closedId)) === null || _a === void 0 ? void 0 : _a.focus(); });
38
+ }
39
+ }, [viewButtonRefs, revokeObjectUrl]);
40
+ const handleViewFile = useCallback(async (file) => {
41
+ if (onView) {
42
+ onView(file);
43
+ return;
44
+ }
45
+ const kind = getPreviewKind(file);
46
+ if (!getPreviewBlob || !kind) {
47
+ return;
48
+ }
49
+ requestTokenRef.current += 1;
50
+ const token = requestTokenRef.current;
51
+ openFileIdRef.current = file.id;
52
+ // A newer request supersedes the previous preview, so its object URL is released straight away
53
+ revokeObjectUrl();
54
+ setPreviewUrl(undefined);
55
+ setPreviewFile(file);
56
+ try {
57
+ const data = await getPreviewBlob(file);
58
+ if (requestTokenRef.current !== token) {
59
+ return;
60
+ }
61
+ if (data) {
62
+ // Always re-label the bytes from the file kind, never trust the type the consumer's Blob carries
63
+ const blob = new Blob([data], { type: getPreviewMimeType(file, kind) });
64
+ objectUrlRef.current = URL.createObjectURL(blob);
65
+ setPreviewUrl(objectUrlRef.current);
66
+ }
67
+ else {
68
+ // Nothing to preview: close instead of showing the loading state forever
69
+ closePreview();
70
+ }
71
+ }
72
+ catch (_a) {
73
+ if (requestTokenRef.current === token) {
74
+ closePreview();
75
+ }
76
+ }
77
+ }, [onView, getPreviewBlob, closePreview, revokeObjectUrl]);
78
+ const kind = previewFile ? getPreviewKind(previewFile) : null;
79
+ const preview = previewFile && kind ? { file: previewFile, fileName: previewFile.name, kind, url: previewUrl, mode: previewMode } : null;
80
+ return { preview, handleViewFile, handleClosePreview: closePreview };
81
+ };
@@ -1,6 +1,6 @@
1
1
  import { IFileUpload } from "./fileUploadType";
2
2
  import "./fileUpload.less";
3
3
  export declare const FileUpload: {
4
- ({ id, className, size, supportedFormatsText, accept, allowMultiple, value, isUploading, disabled, showTemplateSection, showUploadedSection, templateDownload, onChange }: IFileUpload): import("react/jsx-runtime").JSX.Element;
4
+ ({ id, className, size, supportedFormatsText, accept, allowMultiple, value, isUploading, disabled, showTemplateSection, showUploadedSection, templateDownload, dataAnalyticsId, showRemoveButton, showViewButton, showDownloadButton, onView, onDownload, getPreviewBlob, previewMode, onChange }: IFileUpload): import("react/jsx-runtime").JSX.Element;
5
5
  displayName: string;
6
6
  };