@oslokommune/punkt-elements 16.13.2 → 16.15.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 (157) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/calendar-Ch1dgnBo.js +656 -0
  3. package/dist/calendar-DkjXla0I.cjs +90 -0
  4. package/dist/{card-CQYxrtL0.cjs → card-C3POnP3O.cjs} +1 -1
  5. package/dist/{card-Bir3-pl2.js → card-CEDbo1t7.js} +2 -2
  6. package/dist/{checkbox-Cspxcvt_.js → checkbox-Bjp43NxA.js} +1 -1
  7. package/dist/{checkbox-BARDb9iV.cjs → checkbox-nTbihMxW.cjs} +1 -1
  8. package/dist/{combobox-CGbFTWq_.cjs → combobox-C4Q6kQEs.cjs} +1 -1
  9. package/dist/{combobox-BcdLZRDU.js → combobox-CL9BLuxt.js} +6 -6
  10. package/dist/components/fileupload/fileupload-base.d.ts +116 -0
  11. package/dist/components/fileupload/fileupload-operations.d.ts +4 -0
  12. package/dist/components/fileupload/fileupload-renderers.d.ts +28 -0
  13. package/dist/components/fileupload/fileupload-types.d.ts +70 -0
  14. package/dist/components/fileupload/fileupload.d.ts +25 -0
  15. package/dist/components/fileupload/fileupload.test.d.ts +0 -0
  16. package/dist/components/fileupload/index.d.ts +4 -0
  17. package/dist/components/index.d.ts +2 -0
  18. package/dist/components/input-wrapper/input-wrapper.d.ts +2 -0
  19. package/dist/controllers/focus-modality-controller.d.ts +31 -0
  20. package/dist/converters-Bffq_YDm.cjs +1 -0
  21. package/dist/converters-jauYkvNh.js +1378 -0
  22. package/dist/{datepicker-OVd8pmnZ.js → datepicker-BUK1Qanw.js} +22 -21
  23. package/dist/{datepicker-DpmlsnH_.cjs → datepicker-DYd3JCs_.cjs} +10 -10
  24. package/dist/docs/components/fileupload.d.ts +27 -0
  25. package/dist/fileupload-BRqioKSY.cjs +396 -0
  26. package/dist/fileupload-Bnl303X0.js +1372 -0
  27. package/dist/fileupload.d.ts +1 -0
  28. package/dist/{header-DWgPgGfS.cjs → header-Dps8o-ZY.cjs} +1 -1
  29. package/dist/{header-a6ztVNp3.js → header-T5O6sfCN.js} +3 -3
  30. package/dist/{helptext-CCBKKLus.js → helptext-C5rG4VkA.js} +2 -2
  31. package/dist/{helptext-D-3QfZv5.cjs → helptext-DQgStO4D.cjs} +1 -1
  32. package/dist/{input-element-Bw1s6NlF.js → input-element-CjebcQd1.js} +3 -3
  33. package/dist/{input-element-B1yxcfz4.cjs → input-element-FGcr5hGd.cjs} +1 -1
  34. package/dist/input-wrapper-B_XFi211.cjs +55 -0
  35. package/dist/{input-wrapper-YfTmpSSY.js → input-wrapper-DBpMVSxt.js} +41 -15
  36. package/dist/{listbox-DuBgTFvH.js → listbox-0NHJvNjz.js} +2 -2
  37. package/dist/{listbox-DCA2JoPV.cjs → listbox-CcThiNBY.cjs} +1 -1
  38. package/dist/{modal-CBEWrAi2.cjs → modal-B6591sWa.cjs} +1 -1
  39. package/dist/{modal-pPp8nia6.js → modal-DyIC3uhs.js} +1 -1
  40. package/dist/pkt-calendar.cjs +1 -1
  41. package/dist/pkt-calendar.js +1 -1
  42. package/dist/pkt-card.cjs +1 -1
  43. package/dist/pkt-card.js +1 -1
  44. package/dist/pkt-checkbox.cjs +1 -1
  45. package/dist/pkt-checkbox.js +1 -1
  46. package/dist/pkt-combobox.cjs +1 -1
  47. package/dist/pkt-combobox.js +1 -1
  48. package/dist/pkt-consent.cjs +1 -1
  49. package/dist/pkt-consent.js +1 -1
  50. package/dist/pkt-datepicker.cjs +1 -1
  51. package/dist/pkt-datepicker.js +1 -1
  52. package/dist/pkt-fileupload.cjs +1 -0
  53. package/dist/pkt-fileupload.js +2 -0
  54. package/dist/pkt-header.cjs +1 -1
  55. package/dist/pkt-header.js +1 -1
  56. package/dist/pkt-heading.cjs +1 -1
  57. package/dist/pkt-heading.js +1 -1
  58. package/dist/pkt-helptext.cjs +1 -1
  59. package/dist/pkt-helptext.js +1 -1
  60. package/dist/pkt-index.cjs +1 -1
  61. package/dist/pkt-index.js +25 -24
  62. package/dist/pkt-input-wrapper.cjs +1 -1
  63. package/dist/pkt-input-wrapper.js +1 -1
  64. package/dist/pkt-link.cjs +1 -1
  65. package/dist/pkt-link.js +1 -1
  66. package/dist/pkt-linkcard.cjs +1 -1
  67. package/dist/pkt-linkcard.js +1 -1
  68. package/dist/pkt-listbox.cjs +1 -1
  69. package/dist/pkt-listbox.js +1 -1
  70. package/dist/pkt-loader.cjs +1 -1
  71. package/dist/pkt-loader.js +1 -1
  72. package/dist/pkt-messagebox.cjs +1 -1
  73. package/dist/pkt-messagebox.js +1 -1
  74. package/dist/pkt-modal.cjs +1 -1
  75. package/dist/pkt-modal.js +1 -1
  76. package/dist/pkt-progressbar.cjs +1 -1
  77. package/dist/pkt-progressbar.js +1 -1
  78. package/dist/pkt-radiobutton.cjs +1 -1
  79. package/dist/pkt-radiobutton.js +1 -1
  80. package/dist/pkt-select.cjs +1 -1
  81. package/dist/pkt-select.js +1 -1
  82. package/dist/pkt-tabs.cjs +1 -1
  83. package/dist/pkt-tabs.js +1 -1
  84. package/dist/pkt-tag.cjs +1 -1
  85. package/dist/pkt-tag.js +1 -1
  86. package/dist/pkt-textarea.cjs +1 -1
  87. package/dist/pkt-textarea.js +1 -1
  88. package/dist/pkt-textinput.cjs +1 -1
  89. package/dist/pkt-textinput.js +1 -1
  90. package/dist/pkt-timepicker.cjs +1 -1
  91. package/dist/pkt-timepicker.js +1 -1
  92. package/dist/{progressbar-CdXtmOBb.cjs → progressbar-CrwpnIkv.cjs} +1 -1
  93. package/dist/{progressbar-Dy9AiYQz.js → progressbar-uC-0W6o4.js} +1 -1
  94. package/dist/{radiobutton-V_KPbup_.js → radiobutton-B-8-wWFf.js} +1 -1
  95. package/dist/{radiobutton-GOnpUbCW.cjs → radiobutton-DvXr7tDk.cjs} +1 -1
  96. package/dist/{select-C2i8sOk5.cjs → select-B75wzvyz.cjs} +1 -1
  97. package/dist/{select-BSAFd8Wa.js → select-D9B8Ighz.js} +3 -3
  98. package/dist/shared-types/fileupload.d.ts +73 -0
  99. package/dist/shared-types/index.d.ts +2 -0
  100. package/dist/shared-utils/fileupload/announcements.d.ts +11 -0
  101. package/dist/shared-utils/fileupload/filename.d.ts +13 -0
  102. package/dist/shared-utils/fileupload/focus-trap.d.ts +12 -0
  103. package/dist/shared-utils/fileupload/formats.d.ts +30 -0
  104. package/dist/shared-utils/fileupload/index.d.ts +15 -0
  105. package/dist/shared-utils/fileupload/navigation.d.ts +5 -0
  106. package/dist/shared-utils/fileupload/size.d.ts +12 -0
  107. package/dist/shared-utils/fileupload/transfers.d.ts +17 -0
  108. package/dist/shared-utils/fileupload/truncate.d.ts +13 -0
  109. package/dist/shared-utils/fileupload/validation.d.ts +24 -0
  110. package/dist/tests/component-registry.d.ts +2 -0
  111. package/dist/{textarea-DYOBhJrN.js → textarea-CIWXMaAD.js} +2 -2
  112. package/dist/{textarea-D7aGOyDf.cjs → textarea-CjqprL6Y.cjs} +1 -1
  113. package/dist/{textinput-DFh8_9cx.cjs → textinput-B0VWmVIF.cjs} +1 -1
  114. package/dist/{textinput-BUgntXnM.js → textinput-CxzAxM8E.js} +2 -2
  115. package/dist/{timepicker-BIfE7KKJ.cjs → timepicker-Cv9juQeB.cjs} +1 -1
  116. package/dist/{timepicker-DaSwn1FA.js → timepicker-DXrpg5C7.js} +2 -2
  117. package/package.json +2 -2
  118. package/src/components/fileupload/fileupload-base.ts +557 -0
  119. package/src/components/fileupload/fileupload-operations.ts +213 -0
  120. package/src/components/fileupload/fileupload-renderers.ts +769 -0
  121. package/src/components/fileupload/fileupload-types.ts +88 -0
  122. package/src/components/fileupload/fileupload.test.ts +949 -0
  123. package/src/components/fileupload/fileupload.ts +469 -0
  124. package/src/components/fileupload/index.ts +34 -0
  125. package/src/components/index.ts +16 -0
  126. package/src/components/input-wrapper/input-wrapper.ts +10 -3
  127. package/dist/calendar-BzEtOJla.js +0 -2031
  128. package/dist/calendar-E5jJLt8D.cjs +0 -90
  129. package/dist/input-wrapper-BRuVELpK.cjs +0 -54
  130. /package/dist/{booleanish-jJLlnr6-.cjs → booleanish-B5EFqFpJ.cjs} +0 -0
  131. /package/dist/{booleanish-BmcOU-43.js → booleanish-CRaKZ75t.js} +0 -0
  132. /package/dist/{consent-DeB_5sWH.js → consent-f_IGyHss.js} +0 -0
  133. /package/dist/{consent-hwu7pp3S.cjs → consent-zh2npq2K.cjs} +0 -0
  134. /package/dist/{dialog-polyfill.esm-1hPr0gl9.js → dialog-polyfill.esm-BmVHGRTX.js} +0 -0
  135. /package/dist/{dialog-polyfill.esm-D3Oinvk0.cjs → dialog-polyfill.esm-CXDsb3l-.cjs} +0 -0
  136. /package/dist/{heading-DiQLPxdf.js → heading-BxvE80bb.js} +0 -0
  137. /package/dist/{heading-BgSWIRii.cjs → heading-DRJTS27k.cjs} +0 -0
  138. /package/dist/{input-wrapper-Dwd-_sKm.cjs → input-wrapper-CYCCx8MP.cjs} +0 -0
  139. /package/dist/{input-wrapper-CDyHTR1V.js → input-wrapper-kw2y6Jp_.js} +0 -0
  140. /package/dist/{link-CyTCpI0k.cjs → link-B8zYc5WK.cjs} +0 -0
  141. /package/dist/{link-CKAFMz9j.js → link-CjJcwcxR.js} +0 -0
  142. /package/dist/{linkcard-BE4-FewK.cjs → linkcard-C4x-NJMi.cjs} +0 -0
  143. /package/dist/{linkcard-B0KOGaGj.js → linkcard-Ddh5R_L-.js} +0 -0
  144. /package/dist/{loader-CX2rsC01.cjs → loader-CGQXAuyM.cjs} +0 -0
  145. /package/dist/{loader-6kFZUErT.js → loader-DeizpX45.js} +0 -0
  146. /package/dist/{messagebox-Din9X53b.cjs → messagebox-Ccu29rDv.cjs} +0 -0
  147. /package/dist/{messagebox-Cwlg5sOr.js → messagebox-DqoPqo4K.js} +0 -0
  148. /package/dist/{pkt-options-controller-CXUGx134.cjs → pkt-options-controller-BPBb_O2K.cjs} +0 -0
  149. /package/dist/{pkt-options-controller-CRrI6WMk.js → pkt-options-controller-DbLrdRwH.js} +0 -0
  150. /package/dist/{repeat-Cepr3469.js → repeat-DV1O43YU.js} +0 -0
  151. /package/dist/{repeat-CqcDYBxr.cjs → repeat-DaDFvx86.cjs} +0 -0
  152. /package/dist/{tabs-Rc9N9HWa.js → tabs-4eWA7CsK.js} +0 -0
  153. /package/dist/{tabs-BfurI6C3.cjs → tabs-RnDtIFv3.cjs} +0 -0
  154. /package/dist/{tag-DLthw5b4.cjs → tag-DWtajZk6.cjs} +0 -0
  155. /package/dist/{tag-VwykmuQR.js → tag-hl59gziI.js} +0 -0
  156. /package/dist/{utils-CUqCKGvp.js → utils-BOOZ0ppt.js} +0 -0
  157. /package/dist/{utils-CjAbIttF.cjs → utils-CM67Oudc.cjs} +0 -0
@@ -0,0 +1,1372 @@
1
+ import { c as e, d as t, o as n, r, s as i, t as a } from "./element-cZ85T_aa.js";
2
+ import { t as o } from "./class-map-C8HuhNzZ.js";
3
+ import "./alert-ePJuDtmm.js";
4
+ import "./icon-Co72KtgF.js";
5
+ import { t as s } from "./if-defined-Cjj8qN-Z.js";
6
+ import { t as c } from "./converters-jauYkvNh.js";
7
+ import "./input-wrapper-DBpMVSxt.js";
8
+ import "./modal-DyIC3uhs.js";
9
+ import "./progressbar-uC-0W6o4.js";
10
+ //#region ../../shared-types/fileupload.ts
11
+ var l = {
12
+ dropZoneDragMultiple: "Dra filer hit for å laste dem opp eller",
13
+ dropZoneDragSingle: "Dra en fil hit for å laste den opp eller",
14
+ dropZoneDragMultipleThumbnail: "Dra bilder hit for å laste dem opp eller",
15
+ dropZoneDragSingleThumbnail: "Dra et bilde hit for å laste det opp eller",
16
+ dropZoneDragActiveMultiple: "Slipp filene her",
17
+ dropZoneDragActiveSingle: "Slipp filen her",
18
+ dropZoneDragActiveMultipleThumbnail: "Slipp bildene her",
19
+ dropZoneDragActiveSingleThumbnail: "Slipp bildet her",
20
+ dropZoneOpenFileDialogMultiple: "velg filer",
21
+ dropZoneOpenFileDialogSingle: "velg en fil",
22
+ dropZoneOpenFileDialogMultipleThumbnail: "velg fra kamerarull",
23
+ dropZoneOpenFileDialogSingleThumbnail: "velg fra kamerarull",
24
+ supportedFormatsPrefix: "Format:",
25
+ invalidFormatDefault: (e) => `Ugyldig filtype. Tillatte formater: ${e}`,
26
+ sizeTooLargeDefault: (e) => `Filen er for stor. Maks størrelse er ${e}.`,
27
+ requiredMissing: "Du må laste opp minst én fil.",
28
+ genericValidationRejection: "Filen ble avvist av validering.",
29
+ unknownFilename: "Ukjent fil",
30
+ fileLabel: (e) => e === 1 ? "fil" : "filer",
31
+ srFileAdded: (e) => `Filen «${e}» er lagt til`,
32
+ srFilesAdded: (e) => `${e} filer er lagt til`,
33
+ srFilesUploadedOfTotal: (e, t, n) => `${e} av ${t} ${n} lastet opp`,
34
+ srFilesFailedOfTotal: (e, t, n) => `Feil ved opplasting: ${e} av ${t} ${n} feilet`
35
+ };
36
+ //#endregion
37
+ //#region ../../shared-utils/fileupload/size.ts
38
+ function u(e) {
39
+ if (e == null || e === "") return;
40
+ if (typeof e == "number") return Number.isFinite(e) && e > 0 ? e : void 0;
41
+ let t = String(e).trim(), n = Number(t);
42
+ if (!Number.isNaN(n) && n > 0) return n;
43
+ let r = t.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB)$/i);
44
+ if (!r) {
45
+ console.warn(`PktFileUpload: Invalid maxFileSize format "${t}". Use format like "5MB", "500KB", "1GB", or bytes.`);
46
+ return;
47
+ }
48
+ let i = parseFloat(r[1]);
49
+ switch (r[2].toUpperCase()) {
50
+ case "B": return i;
51
+ case "KB": return i * 1024;
52
+ case "MB": return i * 1024 * 1024;
53
+ case "GB": return i * 1024 * 1024 * 1024;
54
+ default: return;
55
+ }
56
+ }
57
+ function d(e) {
58
+ return e < 1024 ? `${Math.round(e)} B` : e < 1024 * 1024 ? `${Math.round(e / 1024)} KB` : e < 1024 * 1024 * 1024 ? `${Math.round(e / (1024 * 1024))} MB` : `${Math.round(e / (1024 * 1024 * 1024))} GB`;
59
+ }
60
+ //#endregion
61
+ //#region ../../shared-utils/fileupload/formats.ts
62
+ function f(e) {
63
+ return Array.isArray(e) ? e.map((e) => String(e).trim().toLowerCase()).filter(Boolean) : [];
64
+ }
65
+ function p(e) {
66
+ return e ? e.split(",").map((e) => e.trim().toLowerCase()).filter(Boolean) : [];
67
+ }
68
+ function m(e, t, n) {
69
+ let r = e.toLowerCase().replace(/^\./, "");
70
+ if (r.includes("/")) {
71
+ if (r.endsWith("/*")) {
72
+ let e = r.replace("/*", "");
73
+ return n.startsWith(`${e}/`);
74
+ }
75
+ return n === r;
76
+ }
77
+ return t === r;
78
+ }
79
+ function h(e, t) {
80
+ let n = f(t);
81
+ if (n.length === 0) return !0;
82
+ let r = e.name.split(".").pop()?.toLowerCase() ?? "", i = e.type.toLowerCase();
83
+ return n.some((e) => m(e, r, i));
84
+ }
85
+ function g(e, t) {
86
+ let n = (e ?? "").trim();
87
+ if (n) return n;
88
+ let r = f(t);
89
+ return r.length === 0 ? "" : r.map((e) => e.includes("/") || e.startsWith(".") ? e : `.${e}`).join(", ");
90
+ }
91
+ function _(e) {
92
+ return e.includes("/") ? e : e.replace(/^\./, "").toUpperCase();
93
+ }
94
+ function v(e, t) {
95
+ let n = f(e);
96
+ if (n.length > 0) return n.map(_).join(", ");
97
+ let r = p(t);
98
+ return r.length > 0 ? r.map(_).join(", ") : "";
99
+ }
100
+ //#endregion
101
+ //#region ../../shared-utils/fileupload/validation.ts
102
+ function y(e, t, n) {
103
+ return ((e ?? "").trim() || t).replace(/\{(\w+)\}/g, (e, t) => n[t] ?? `{${t}}`);
104
+ }
105
+ function b(e, t) {
106
+ let n = f(t.allowedFormats);
107
+ if (n.length > 0 && !h(e, n)) {
108
+ let e = n.join(", "), r = `Ugyldig filtype. Tillatte formater: ${e}`;
109
+ return y(t.formatErrorMessage, r, { formats: e });
110
+ }
111
+ let r = u(t.maxFileSize);
112
+ if (r !== void 0 && e.size > r) {
113
+ let e = d(r), n = `Filen er for stor. Maks størrelse er ${e}.`;
114
+ return y(t.sizeErrorMessage, n, { maxSize: e });
115
+ }
116
+ if (t.onFileValidation) {
117
+ let n = t.onFileValidation(e);
118
+ if (n) return n;
119
+ }
120
+ return null;
121
+ }
122
+ function x(e) {
123
+ let t = e.file;
124
+ if (t?.type?.startsWith("image/")) return !0;
125
+ let n = e.attributes?.targetFilename || t?.name || "";
126
+ return /\.(jpe?g|png|gif|webp|heic|heif|bmp|svg)$/i.test(n);
127
+ }
128
+ //#endregion
129
+ //#region ../../shared-utils/fileupload/transfers.ts
130
+ function S(e) {
131
+ return typeof e == "number" ? "in-progress" : e === "error" ? "error" : "idle";
132
+ }
133
+ function C(e, t, n) {
134
+ let r = {
135
+ "in-progress": 0,
136
+ error: 1,
137
+ idle: 2
138
+ };
139
+ return e.map((e) => {
140
+ let r = t?.find((t) => t.fileId === e.fileId);
141
+ return {
142
+ ...e,
143
+ progress: r?.progress ?? (n === "form" ? "done" : "queued"),
144
+ errorMessage: r?.errorMessage,
145
+ showProgress: r?.showProgress,
146
+ lastProgress: r?.lastProgress
147
+ };
148
+ }).sort((e, t) => r[S(e.progress)] - r[S(t.progress)]);
149
+ }
150
+ //#endregion
151
+ //#region ../../shared-utils/fileupload/focus-trap.ts
152
+ function w(e) {
153
+ if (!e) return [];
154
+ let t = [
155
+ "a[href]:not([tabindex=\"-1\"])",
156
+ "button:not([disabled]):not([tabindex=\"-1\"])",
157
+ "input:not([disabled]):not([type=\"hidden\"]):not([tabindex=\"-1\"])",
158
+ "select:not([disabled]):not([tabindex=\"-1\"])",
159
+ "textarea:not([disabled]):not([tabindex=\"-1\"])",
160
+ "[tabindex]:not([tabindex=\"-1\"])"
161
+ ].join(", ");
162
+ return Array.from(e.querySelectorAll(t)).filter((e) => !e.hasAttribute("inert"));
163
+ }
164
+ function T(e, t) {
165
+ if (e.key !== "Tab") return !1;
166
+ let n = w(t);
167
+ if (n.length === 0) return e.preventDefault(), !0;
168
+ let r = n[0], i = n[n.length - 1], a = (t?.ownerDocument ?? document).activeElement, o = !!a && n.includes(a);
169
+ return e.shiftKey ? !o || a === r ? (e.preventDefault(), i.focus(), !0) : !1 : !o || a === i ? (e.preventDefault(), r.focus(), !0) : !1;
170
+ }
171
+ //#endregion
172
+ //#region ../../shared-utils/fileupload/truncate.ts
173
+ function E(e, t) {
174
+ return !t || t <= 0 || e.length <= t + 3 ? null : {
175
+ head: e.slice(0, e.length - t),
176
+ tail: e.slice(-t)
177
+ };
178
+ }
179
+ //#endregion
180
+ //#region ../../shared-utils/fileupload/navigation.ts
181
+ function D(e, t, n) {
182
+ return n <= 0 ? 0 : t === "prev" ? e <= 0 ? n - 1 : e - 1 : e >= n - 1 ? 0 : e + 1;
183
+ }
184
+ //#endregion
185
+ //#region ../../shared-utils/fileupload/announcements.ts
186
+ function O(e, t) {
187
+ let n = e.length;
188
+ if (n === 0 || !t || t.length === 0) return {
189
+ totalCount: n,
190
+ uploadedCount: 0,
191
+ failedCount: 0
192
+ };
193
+ let r = 0, i = 0;
194
+ for (let n of e) {
195
+ let e = t.find((e) => e.fileId === n.fileId);
196
+ e?.progress === "done" ? r++ : e?.progress === "error" && i++;
197
+ }
198
+ return {
199
+ totalCount: n,
200
+ uploadedCount: r,
201
+ failedCount: i
202
+ };
203
+ }
204
+ //#endregion
205
+ //#region ../../shared-utils/fileupload/filename.ts
206
+ function k(e, t = l.unknownFilename) {
207
+ return e.attributes?.targetFilename || e.file?.name || t;
208
+ }
209
+ //#endregion
210
+ //#region src/components/fileupload/fileupload-base.ts
211
+ var A = class extends a {
212
+ constructor(...e) {
213
+ super(...e), this.id = `pkt-fileupload-${crypto.randomUUID()}`, this.name = "files", this.label = "", this.helptext = "", this.required = !1, this.multiple = !1, this.disabled = !1, this.fullwidth = !1, this.uploadStrategy = "form", this.itemRenderer = "filename", this.accept = "", this.allowedFormats = [], this.formatErrorMessage = "", this.sizeErrorMessage = "", this.transfers = [], this.addCommentsEnabled = !1, this.renameFilesEnabled = !1, this.extraOperations = [], this.enableImagePreview = !1, this.hasError = !1, this.errorMessage = "", this.optionalTag = !1, this.requiredTag = !1, this.truncateTail = 4, this.files = [], this.isDragActive = !1, this.validationErrorMessage = null, this.addedAnnouncement = "", this.thumbnailUrls = {}, this.hasInitializedValue = !1, this.hasWarnedInvalidValueCombo = !1, this.thumbnailFileById = /* @__PURE__ */ new Map(), this.connectedForm = null, this.addedAnnouncementTimer = null, this.requiredSelectionMessage = l.requiredMissing, this.onNativeFileChange = (e) => {
214
+ let t = e.target;
215
+ this.addFiles(t.files ? Array.from(t.files) : []), this.uploadStrategy === "custom" && (t.value = "");
216
+ }, this.openFileDialog = (e) => {
217
+ e.preventDefault(), e.stopPropagation(), !this.disabled && this.querySelector(`#${this.id}-input`)?.click();
218
+ }, this.onDropZoneClick = (e) => {
219
+ this.disabled || e.target.closest(".pkt-fileupload__drop-zone__placeholder__title__open-file-dialog") || this.querySelector(`#${this.id}-input`)?.click();
220
+ }, this.onDragOver = (e) => {
221
+ e.preventDefault(), !this.disabled && (this.isDragActive = !0);
222
+ }, this.onDragLeave = () => {
223
+ this.isDragActive = !1;
224
+ }, this.onDrop = (e) => {
225
+ if (e.preventDefault(), this.isDragActive = !1, this.disabled) return;
226
+ let t = e.dataTransfer?.files ? Array.from(e.dataTransfer.files) : [];
227
+ this.addFiles(t);
228
+ }, this.onHostFormSubmit = (e) => {
229
+ !this.required || this.uploadStrategy !== "custom" || this.getCurrentFiles().length > 0 || (this.validationErrorMessage = this.requiredSelectionMessage, e.preventDefault());
230
+ };
231
+ }
232
+ get isControlled() {
233
+ return this.value !== void 0;
234
+ }
235
+ get hasEffectiveError() {
236
+ return !!this.validationErrorMessage || this.hasError || !!this.errorMessage.trim();
237
+ }
238
+ get effectiveErrorMessage() {
239
+ return this.validationErrorMessage ?? this.errorMessage ?? "";
240
+ }
241
+ get hasValidationError() {
242
+ return !!this.validationErrorMessage;
243
+ }
244
+ firstUpdated(e) {
245
+ super.firstUpdated?.(e), this.hasInitializedValue ||= (this.files = this.value ?? this.defaultValue ?? [], this.syncThumbnailUrls(this.files), !0), this.value !== void 0 && this.defaultValue !== void 0 && this.warnInvalidValueCombo();
246
+ }
247
+ willUpdate(e) {
248
+ super.willUpdate(e), this.hasInitializedValue && this.isControlled && (e.has("value") || e.has("itemRenderer") || e.has("enableImagePreview")) && (this.files = this.value ?? [], this.syncThumbnailUrls(this.files));
249
+ }
250
+ updated(e) {
251
+ super.updated(e), (e.has("uploadStrategy") || e.has("required") || e.has("value")) && this.syncFormSubmitListener(), this.uploadStrategy === "form" && (e.has("value") || e.has("files") || e.has("uploadStrategy")) && this.syncNativeInputFiles();
252
+ }
253
+ syncNativeInputFiles() {
254
+ let e = this.querySelector(`#${this.id}-input`);
255
+ if (!(!e || typeof DataTransfer > "u")) try {
256
+ let t = new DataTransfer();
257
+ for (let e of this.getCurrentFiles()) e.file && t.items.add(e.file);
258
+ e.files = t.files;
259
+ } catch {}
260
+ }
261
+ warnInvalidValueCombo() {
262
+ this.hasWarnedInvalidValueCombo ||= (console.warn("PktFileUpload: Både value og defaultValue er angitt. Komponenten kan være enten kontrollert eller ukontrollert, ikke begge. value vil bli prioritert."), !0);
263
+ }
264
+ disconnectedCallback() {
265
+ this.teardownFormSubmitListener(), this.addedAnnouncementTimer &&= (clearTimeout(this.addedAnnouncementTimer), null), super.disconnectedCallback(), this.revokeAllThumbnailUrls();
266
+ }
267
+ setAddedAnnouncement(e) {
268
+ this.addedAnnouncement = e, this.addedAnnouncementTimer && clearTimeout(this.addedAnnouncementTimer), this.addedAnnouncementTimer = setTimeout(() => {
269
+ this.addedAnnouncement = "", this.addedAnnouncementTimer = null;
270
+ }, 1500);
271
+ }
272
+ connectedCallback() {
273
+ super.connectedCallback(), this.syncFormSubmitListener();
274
+ }
275
+ addFiles(e) {
276
+ if (e.length === 0) return;
277
+ let t = this.multiple ? e : [e[0]];
278
+ for (let e of t) {
279
+ let t = this.validateFile(e);
280
+ if (t) {
281
+ this.validationErrorMessage = t;
282
+ return;
283
+ }
284
+ }
285
+ this.validationErrorMessage = null;
286
+ let n = t.map((e) => ({
287
+ fileId: crypto.randomUUID(),
288
+ file: e,
289
+ attributes: { targetFilename: e.name }
290
+ }));
291
+ this.setAddedAnnouncement(n.length === 1 ? l.srFileAdded(n[0].attributes.targetFilename) : l.srFilesAdded(n.length));
292
+ let r = this.getCurrentFiles(), i = this.multiple ? [...r, ...n] : [n[0]];
293
+ this.commitFiles(i, "add", n.map((e) => e.fileId)), this.uploadStrategy === "custom" && n.forEach((e) => {
294
+ this.dispatchEvent(new CustomEvent("file-upload-requested", {
295
+ detail: {
296
+ fileId: e.fileId,
297
+ file: e.file,
298
+ attributes: e.attributes
299
+ },
300
+ bubbles: !0,
301
+ composed: !0
302
+ }));
303
+ });
304
+ }
305
+ getCurrentFiles() {
306
+ return this.isControlled ? this.value ?? [] : this.files;
307
+ }
308
+ cancelTransfer(e) {
309
+ if (this.disabled) return;
310
+ let t = this.getCurrentFiles().find((t) => t.fileId === e);
311
+ t && (this.removeFileItem(e), this.dispatchEvent(new CustomEvent("transfer-cancelled", {
312
+ detail: {
313
+ fileId: t.fileId,
314
+ file: t.file,
315
+ attributes: t.attributes
316
+ },
317
+ bubbles: !0,
318
+ composed: !0
319
+ })));
320
+ }
321
+ removeFileItem(e) {
322
+ if (this.disabled) return;
323
+ let t = this.getCurrentFiles(), n = t.filter((t) => t.fileId !== e);
324
+ n.length !== t.length && this.commitFiles(n, "remove", [e]);
325
+ }
326
+ updateFileItem(e, t) {
327
+ let n = this.getCurrentFiles().map((n) => n.fileId === e ? {
328
+ ...n,
329
+ ...t
330
+ } : n);
331
+ this.commitFiles(n, "update", [e]);
332
+ }
333
+ commitFiles(e, t, n) {
334
+ this.isControlled || (this.files = e, this.syncThumbnailUrls(e)), this.validationErrorMessage === this.requiredSelectionMessage && e.length > 0 && (this.validationErrorMessage = null), this.dispatchEvent(new CustomEvent("files-changed", {
335
+ detail: {
336
+ files: e,
337
+ reason: t,
338
+ changedFileIds: n
339
+ },
340
+ bubbles: !0,
341
+ composed: !0
342
+ }));
343
+ }
344
+ getThumbnailUrl(e) {
345
+ return this.thumbnailUrls[e.fileId];
346
+ }
347
+ getTransferProgress(e) {
348
+ let t = this.transfers.find((t) => t.fileId === e);
349
+ return t ? t.progress : this.uploadStrategy === "form" ? "done" : "queued";
350
+ }
351
+ getTransferForFile(e) {
352
+ return this.transfers.find((t) => t.fileId === e);
353
+ }
354
+ isImageFile(e) {
355
+ return x(e);
356
+ }
357
+ formatFileSize(e) {
358
+ return d(e);
359
+ }
360
+ getResolvedAcceptValue() {
361
+ return g(this.accept, this.allowedFormats);
362
+ }
363
+ getSupportedFormatsText() {
364
+ return v(this.allowedFormats, this.accept);
365
+ }
366
+ getSortedFilesAndTransfers() {
367
+ return C(this.getCurrentFiles(), this.transfers, this.uploadStrategy);
368
+ }
369
+ validateFile(e) {
370
+ let t = b(e, {
371
+ allowedFormats: this.allowedFormats,
372
+ maxFileSize: this.maxFileSize,
373
+ formatErrorMessage: this.formatErrorMessage,
374
+ sizeErrorMessage: this.sizeErrorMessage,
375
+ onFileValidation: this.onFileValidation
376
+ });
377
+ if (t) return t;
378
+ let n = {
379
+ file: e,
380
+ errorMessage: null
381
+ }, r = new CustomEvent("file-validate", {
382
+ detail: n,
383
+ bubbles: !0,
384
+ composed: !0,
385
+ cancelable: !0
386
+ });
387
+ return this.dispatchEvent(r), n.errorMessage ? n.errorMessage : r.defaultPrevented ? l.genericValidationRejection : null;
388
+ }
389
+ syncThumbnailUrls(e) {
390
+ if (!(typeof URL < "u" && typeof URL.createObjectURL == "function" && typeof URL.revokeObjectURL == "function")) {
391
+ this.thumbnailUrls = {}, this.thumbnailFileById.clear();
392
+ return;
393
+ }
394
+ let t = new Set(e.map((e) => e.fileId)), n = {};
395
+ for (let [e, n] of Object.entries(this.thumbnailUrls)) t.has(e) || (URL.revokeObjectURL(n), this.thumbnailFileById.delete(e));
396
+ for (let t of e) {
397
+ let e = this.thumbnailUrls[t.fileId], r = this.thumbnailFileById.get(t.fileId);
398
+ if (!t.file || !this.isImageFile(t)) {
399
+ e && (URL.revokeObjectURL(e), this.thumbnailFileById.delete(t.fileId));
400
+ continue;
401
+ }
402
+ if (e && r === t.file) {
403
+ n[t.fileId] = e;
404
+ continue;
405
+ }
406
+ e && r !== t.file && URL.revokeObjectURL(e);
407
+ let i = URL.createObjectURL(t.file);
408
+ this.thumbnailFileById.set(t.fileId, t.file), n[t.fileId] = i;
409
+ }
410
+ this.thumbnailUrls = n;
411
+ }
412
+ revokeAllThumbnailUrls() {
413
+ if (typeof URL > "u" || typeof URL.revokeObjectURL != "function") {
414
+ this.thumbnailUrls = {}, this.thumbnailFileById.clear();
415
+ return;
416
+ }
417
+ Object.values(this.thumbnailUrls).forEach((e) => URL.revokeObjectURL(e)), this.thumbnailUrls = {}, this.thumbnailFileById.clear();
418
+ }
419
+ getSrUploadedMessage() {
420
+ if (this.addedAnnouncement) return this.addedAnnouncement;
421
+ let { totalCount: e, uploadedCount: t } = O(this.getCurrentFiles(), this.transfers);
422
+ return e === 0 || t === 0 ? "" : l.srFilesUploadedOfTotal(t, e, l.fileLabel(e));
423
+ }
424
+ getSrErrorsMessage() {
425
+ let { totalCount: e, failedCount: t } = O(this.getCurrentFiles(), this.transfers);
426
+ return e === 0 || t === 0 ? "" : l.srFilesFailedOfTotal(t, e, l.fileLabel(e));
427
+ }
428
+ syncFormSubmitListener() {
429
+ let e = this.closest("form");
430
+ this.connectedForm !== e && (this.teardownFormSubmitListener(), this.connectedForm = e, this.connectedForm && this.connectedForm.addEventListener("submit", this.onHostFormSubmit));
431
+ }
432
+ teardownFormSubmitListener() {
433
+ this.connectedForm &&= (this.connectedForm.removeEventListener("submit", this.onHostFormSubmit), null);
434
+ }
435
+ };
436
+ r([i({ type: String })], A.prototype, "id", void 0), r([i({ type: String })], A.prototype, "name", void 0), r([i({ type: String })], A.prototype, "label", void 0), r([i({ type: String })], A.prototype, "helptext", void 0), r([i({
437
+ type: Boolean,
438
+ reflect: !0
439
+ })], A.prototype, "required", void 0), r([i({
440
+ type: Boolean,
441
+ reflect: !0
442
+ })], A.prototype, "multiple", void 0), r([i({
443
+ type: Boolean,
444
+ reflect: !0
445
+ })], A.prototype, "disabled", void 0), r([i({
446
+ type: Boolean,
447
+ reflect: !0,
448
+ attribute: "fullwidth"
449
+ })], A.prototype, "fullwidth", void 0), r([i({
450
+ type: String,
451
+ reflect: !0,
452
+ attribute: "upload-strategy"
453
+ })], A.prototype, "uploadStrategy", void 0), r([i({
454
+ type: String,
455
+ reflect: !0,
456
+ attribute: "item-renderer"
457
+ })], A.prototype, "itemRenderer", void 0), r([i({ type: String })], A.prototype, "accept", void 0), r([i({
458
+ converter: c.csvToArray,
459
+ attribute: "allowed-formats"
460
+ })], A.prototype, "allowedFormats", void 0), r([i({
461
+ type: String,
462
+ attribute: "format-error-message"
463
+ })], A.prototype, "formatErrorMessage", void 0), r([i({ attribute: "max-file-size" })], A.prototype, "maxFileSize", void 0), r([i({
464
+ type: String,
465
+ attribute: "size-error-message"
466
+ })], A.prototype, "sizeErrorMessage", void 0), r([i({ attribute: !1 })], A.prototype, "onFileValidation", void 0), r([i({ attribute: !1 })], A.prototype, "transfers", void 0), r([i({
467
+ type: Boolean,
468
+ attribute: "add-comments-enabled"
469
+ })], A.prototype, "addCommentsEnabled", void 0), r([i({
470
+ type: Boolean,
471
+ attribute: "rename-files-enabled"
472
+ })], A.prototype, "renameFilesEnabled", void 0), r([i({ attribute: !1 })], A.prototype, "extraOperations", void 0), r([i({
473
+ type: Boolean,
474
+ reflect: !0,
475
+ attribute: "enable-image-preview"
476
+ })], A.prototype, "enableImagePreview", void 0), r([i({
477
+ type: Boolean,
478
+ attribute: "has-error"
479
+ })], A.prototype, "hasError", void 0), r([i({
480
+ type: String,
481
+ attribute: "error-message"
482
+ })], A.prototype, "errorMessage", void 0), r([i({
483
+ type: Boolean,
484
+ attribute: "optional-tag"
485
+ })], A.prototype, "optionalTag", void 0), r([i({
486
+ type: Boolean,
487
+ attribute: "required-tag"
488
+ })], A.prototype, "requiredTag", void 0), r([i({
489
+ type: Number,
490
+ attribute: "truncate-tail"
491
+ })], A.prototype, "truncateTail", void 0), r([i({ attribute: !1 })], A.prototype, "value", void 0), r([i({ attribute: !1 })], A.prototype, "defaultValue", void 0), r([n()], A.prototype, "files", void 0), r([n()], A.prototype, "isDragActive", void 0), r([n()], A.prototype, "validationErrorMessage", void 0), r([n()], A.prototype, "addedAnnouncement", void 0), r([n()], A.prototype, "thumbnailUrls", void 0);
492
+ //#endregion
493
+ //#region src/components/fileupload/fileupload-operations.ts
494
+ var j = "comments", M = (e) => {
495
+ let t = new Date(e);
496
+ return Number.isNaN(t.getTime()) ? e : `${String(t.getDate()).padStart(2, "0")}.${String(t.getMonth() + 1).padStart(2, "0")}.${t.getFullYear()} kl. ${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}`;
497
+ }, N = (e, t, n) => {
498
+ e.key === "Enter" && (e.preventDefault(), e.stopPropagation(), t()), e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), n());
499
+ }, P = (e, t, n) => {
500
+ e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), n()), (e.metaKey || e.ctrlKey) && e.key === "Enter" && (e.preventDefault(), e.stopPropagation(), t());
501
+ }, F = (e) => ({
502
+ id: "remove",
503
+ title: "Slett",
504
+ ariaLabel: "Slett fil",
505
+ onClick: ({ file: t }) => e(t.fileId)
506
+ }), I = () => ({
507
+ id: "rename",
508
+ title: "Rediger",
509
+ ariaLabel: "Rediger filnavn",
510
+ renderInlineUI: (e) => {
511
+ let n = e.getAttribute("targetFilename") || e.file.attributes?.targetFilename || e.file.file?.name || "", r = `pkt-fileupload-rename-${e.file.fileId}`, i = () => {
512
+ let t = document.getElementById(r)?.value?.trim();
513
+ t && e.setAttribute("targetFilename", t), e.close();
514
+ };
515
+ return t`
516
+ <label for=${r} class="pkt-sr-only">Endre filnavn</label>
517
+ <input
518
+ id=${r}
519
+ type="text"
520
+ class="pkt-fileupload__queue-display__item__rename-input"
521
+ ?disabled=${e.disabled}
522
+ .value=${n}
523
+ @keydown=${(t) => N(t, i, e.close)}
524
+ />
525
+ <button
526
+ type="button"
527
+ class="pkt-btn pkt-btn--secondary pkt-btn--small"
528
+ ?disabled=${e.disabled}
529
+ @click=${i}
530
+ >
531
+ Lagre
532
+ </button>
533
+ <button
534
+ type="button"
535
+ class="pkt-btn pkt-btn--tertiary pkt-btn--small"
536
+ ?disabled=${e.disabled}
537
+ @click=${e.close}
538
+ >
539
+ Avbryt
540
+ </button>
541
+ `;
542
+ },
543
+ renderHidden: (e) => {
544
+ let n = e.getAttribute("targetFilename") || e.file.attributes?.targetFilename || e.file.file?.name || "";
545
+ return t`<input
546
+ type="hidden"
547
+ name=${`${e.inputName}-targetFilename`}
548
+ value=${n}
549
+ />`;
550
+ }
551
+ }), L = () => ({
552
+ id: "comment",
553
+ title: (e) => (e.attributes?.[j] ?? []).length > 0 ? "" : "Legg til kommentar",
554
+ ariaLabel: "Legg til kommentar",
555
+ renderExtendedUI: (e) => {
556
+ let n = (e.getAttribute(j) ?? [])[0], r = `pkt-fileupload-comment-${e.file.fileId}`, i = () => {
557
+ let t = document.getElementById(r)?.value?.trim();
558
+ t && e.setAttribute(j, [{
559
+ text: t,
560
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
561
+ }]), e.close();
562
+ };
563
+ return t`
564
+ <label for=${r} class="pkt-fileupload__queue-display__item__comment-label">
565
+ ${n ? "Rediger kommentar" : "Legg til kommentar"}
566
+ </label>
567
+ <textarea
568
+ id=${r}
569
+ class="pkt-fileupload__queue-display__item__comment-input"
570
+ ?disabled=${e.disabled}
571
+ .value=${n?.text ?? ""}
572
+ rows="2"
573
+ placeholder="Skriv inn kommentar"
574
+ @keydown=${(t) => P(t, i, e.close)}
575
+ ></textarea>
576
+ <button
577
+ type="button"
578
+ class="pkt-btn pkt-btn--secondary pkt-btn--small"
579
+ ?disabled=${e.disabled}
580
+ @click=${i}
581
+ >
582
+ ${n ? "Lagre kommentar" : "Legg til kommentar"}
583
+ </button>
584
+ <button
585
+ type="button"
586
+ class="pkt-btn pkt-btn--tertiary pkt-btn--small"
587
+ ?disabled=${e.disabled}
588
+ @click=${e.close}
589
+ >
590
+ Avbryt
591
+ </button>
592
+ `;
593
+ },
594
+ renderContent: (e) => {
595
+ if (e.isActive) return null;
596
+ let n = e.getAttribute(j) ?? [];
597
+ if (n.length === 0) return null;
598
+ let r = n[0];
599
+ return t`
600
+ <div class="pkt-fileupload__queue-display__item__comments">
601
+ <div class="pkt-fileupload__queue-display__item__comment">
602
+ <div class="pkt-fileupload__queue-display__item__comment__content">
603
+ <span class="pkt-fileupload__queue-display__item__comment__text" aria-label="Kommentar tekst">
604
+ ${r.text}
605
+ </span>
606
+ <time class="pkt-fileupload__queue-display__item__comment__time">
607
+ ${M(r.timestamp)}
608
+ </time>
609
+ </div>
610
+ <div class="pkt-fileupload__queue-display__item__comment__actions">
611
+ <button
612
+ type="button"
613
+ class="pkt-fileupload__queue-display__item__comment__action"
614
+ aria-label="Rediger kommentar"
615
+ ?disabled=${e.disabled}
616
+ @click=${e.activate}
617
+ >
618
+ <pkt-icon name="edit"></pkt-icon>
619
+ </button>
620
+ <button
621
+ type="button"
622
+ class="pkt-fileupload__queue-display__item__comment__action"
623
+ aria-label="Slett kommentar"
624
+ ?disabled=${e.disabled}
625
+ @click=${() => e.setAttribute(j, void 0)}
626
+ >
627
+ <pkt-icon name="trash-can"></pkt-icon>
628
+ </button>
629
+ </div>
630
+ </div>
631
+ </div>
632
+ `;
633
+ },
634
+ renderHidden: (e) => {
635
+ let n = e.getAttribute(j);
636
+ return t`<input
637
+ type="hidden"
638
+ name=${`${e.inputName}-comments`}
639
+ value=${n ? JSON.stringify(n) : ""}
640
+ />`;
641
+ }
642
+ }), R = (e, n) => {
643
+ let r = E(e, n);
644
+ return r ? t`<span
645
+ class="pkt-fileupload__queue-display__item__title__head"
646
+ data-pkt-truncate-part="first"
647
+ >${r.head}</span
648
+ ><span
649
+ class="pkt-fileupload__queue-display__item__title__tail"
650
+ data-pkt-truncate-part="tail"
651
+ >${r.tail}</span
652
+ >` : t`<span data-pkt-truncate-part="first">${e}</span>`;
653
+ }, z = (e, n, r) => t`
654
+ <p class="pkt-fileupload__queue-display__item__title">
655
+ ${R(e, r)}${n ? t`<span class="pkt-fileupload__queue-display__item__filesize"> (${n})</span>` : null}
656
+ </p>
657
+ `, B = (e) => typeof e == "number" ? "in-progress" : e === "error" ? "error" : "idle", V = (e) => t`<span class="pkt-fileupload__queue-display__item__loading-text" aria-label="Laster opp fil"
658
+ >${e ?? "Laster opp..."}</span
659
+ >`, H = ({ operationId: e, file: t, inputName: n, disabled: r, isActive: i, onActivateOperation: a, onCloseOperation: o, getFileAttribute: s, setFileAttribute: c }) => ({
660
+ file: t,
661
+ inputName: n,
662
+ disabled: r,
663
+ isActive: i,
664
+ activate: () => a(t.fileId, e),
665
+ close: () => o(t.fileId),
666
+ getAttribute: (e) => s(t.fileId, e),
667
+ setAttribute: (e, n) => c(t.fileId, e, n)
668
+ }), U = ({ file: e, fileSize: n, disabled: r, transferProgress: i, transferShowProgress: a, loadingText: o, truncateTail: s, onCancel: c, iconName: l = "document-text" }) => {
669
+ let u = k(e), d = a ?? i !== 0;
670
+ return t`
671
+ <pkt-icon
672
+ name=${l}
673
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
674
+ aria-hidden="true"
675
+ ></pkt-icon>
676
+ ${z(u, n, s)}
677
+ <button
678
+ type="button"
679
+ class="pkt-fileupload__queue-display__item__cancel-button"
680
+ aria-label="Avbryt opplasting"
681
+ ?disabled=${r}
682
+ @click=${() => c(e.fileId)}
683
+ >
684
+ Avbryt
685
+ </button>
686
+ ${d ? t`
687
+ <pkt-progressbar
688
+ class="pkt-fileupload__queue-display__item__progress"
689
+ valueCurrent=${Math.round(i * 100)}
690
+ valueMax=${100}
691
+ statusType="none"
692
+ statusPlacement="following"
693
+ ></pkt-progressbar>
694
+ <span class="pkt-fileupload__queue-display__item__percentage" aria-hidden="true"
695
+ >${Math.round(i * 100)}%</span
696
+ >
697
+ ` : V(o)}
698
+ `;
699
+ }, W = ({ file: e, fileSize: n, disabled: r, transferShowProgress: i, transferLastProgress: a, transferErrorMessage: o, truncateTail: s, onCancel: c }) => {
700
+ let l = k(e), u = !!i, d = Math.round((a ?? 1) * 100);
701
+ return t`
702
+ <pkt-icon
703
+ name="alert-error"
704
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
705
+ aria-hidden="true"
706
+ ></pkt-icon>
707
+ ${z(l, n, s)}
708
+ <button
709
+ type="button"
710
+ class="pkt-fileupload__queue-display__item__cancel-button"
711
+ aria-label="Fjern fil som feilet under opplasting"
712
+ ?disabled=${r}
713
+ @click=${() => c(e.fileId)}
714
+ >
715
+ Fjern
716
+ </button>
717
+ ${u ? t`
718
+ <pkt-progressbar
719
+ class="pkt-fileupload__queue-display__item__progress pkt-fileupload__queue-display__item__progress--error"
720
+ valueCurrent=${d}
721
+ valueMax=${100}
722
+ statusType="none"
723
+ statusPlacement="following"
724
+ ></pkt-progressbar>
725
+ ` : null}
726
+ ${o ? t`<span class="pkt-fileupload__queue-display__item__error-message"
727
+ >${o}</span
728
+ >` : null}
729
+ `;
730
+ }, G = ({ file: e, disabled: n, inputName: r, operations: i, activeOperationId: a, onActivateOperation: o, onCloseOperation: c, getFileAttribute: l, setFileAttribute: u }) => {
731
+ let d = i.find((e) => e.id === a);
732
+ if (d?.renderInlineUI || d?.renderExtendedUI) return null;
733
+ let f = i.map((i) => {
734
+ let d = H({
735
+ operationId: i.id,
736
+ file: e,
737
+ inputName: r,
738
+ disabled: n,
739
+ isActive: i.id === a,
740
+ onActivateOperation: o,
741
+ onCloseOperation: c,
742
+ getFileAttribute: l,
743
+ setFileAttribute: u
744
+ }), f = typeof i.title == "function" ? i.title(e) : i.title;
745
+ return f ? t`<button
746
+ type="button"
747
+ class="pkt-fileupload__queue-display__item__operation"
748
+ aria-label=${s(typeof i.ariaLabel == "function" ? i.ariaLabel(e) : i.ariaLabel)}
749
+ ?disabled=${n}
750
+ @click=${() => {
751
+ (i.renderInlineUI || i.renderExtendedUI) && d.activate(), i.onClick?.(d);
752
+ }}
753
+ >
754
+ ${f}
755
+ </button>` : null;
756
+ }).filter(Boolean);
757
+ return f.length === 0 ? null : t`<div class="pkt-fileupload__queue-display__item__actions">${f}</div>`;
758
+ }, K = ({ file: e, disabled: n, inputName: r, operations: i, activeOperationId: a, onActivateOperation: o, onCloseOperation: s, getFileAttribute: c, setFileAttribute: l }) => i.map((i) => {
759
+ if (!i.renderContent) return null;
760
+ let u = H({
761
+ operationId: i.id,
762
+ file: e,
763
+ inputName: r,
764
+ disabled: n,
765
+ isActive: i.id === a,
766
+ onActivateOperation: o,
767
+ onCloseOperation: s,
768
+ getFileAttribute: c,
769
+ setFileAttribute: l
770
+ }), d = i.renderContent(u);
771
+ return d == null ? null : t`<div class="pkt-fileupload__queue-display__item__operation-content">
772
+ ${d}
773
+ </div>`;
774
+ }), q = ({ file: e, disabled: n, inputName: r, operations: i, activeOperationId: a, onActivateOperation: o, onCloseOperation: s, getFileAttribute: c, setFileAttribute: l }) => {
775
+ if (!a) return null;
776
+ let u = i.find((e) => e.id === a);
777
+ if (!u?.renderExtendedUI) return null;
778
+ let d = H({
779
+ operationId: u.id,
780
+ file: e,
781
+ inputName: r,
782
+ disabled: n,
783
+ isActive: !0,
784
+ onActivateOperation: o,
785
+ onCloseOperation: s,
786
+ getFileAttribute: c,
787
+ setFileAttribute: l
788
+ });
789
+ return t`<div class="pkt-fileupload__queue-display__item__expanded-operation-ui">
790
+ ${u.renderExtendedUI(d)}
791
+ </div>`;
792
+ }, J = ({ file: e, disabled: t, inputName: n, operations: r, activeOperationId: i, onActivateOperation: a, onCloseOperation: o, getFileAttribute: s, setFileAttribute: c }) => r.map((r) => {
793
+ if (!r.renderHidden) return null;
794
+ let l = H({
795
+ operationId: r.id,
796
+ file: e,
797
+ inputName: n,
798
+ disabled: t,
799
+ isActive: r.id === i,
800
+ onActivateOperation: a,
801
+ onCloseOperation: o,
802
+ getFileAttribute: s,
803
+ setFileAttribute: c
804
+ });
805
+ return r.renderHidden(l);
806
+ }), Y = (e, n, r) => t`
807
+ <pkt-icon
808
+ name="document-text"
809
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
810
+ aria-hidden="true"
811
+ ></pkt-icon>
812
+ ${z(k(e), n, r)}
813
+ `, X = ({ file: e, thumbnailUrl: n, previewEnabled: r, canOpenPreview: i, truncateTail: a, onOpenPreview: c, onThumbnailImageError: l }) => {
814
+ let u = k(e), d = !!n, f = !!r && !!i, p = f && !!c;
815
+ return t`
816
+ <div
817
+ class=${o({
818
+ "pkt-fileupload__queue-display__item__thumbnail": !0,
819
+ "pkt-fileupload__queue-display__item__thumbnail--fallback": !d
820
+ })}
821
+ >
822
+ <button
823
+ type="button"
824
+ class="pkt-fileupload__queue-display__item__thumbnail__image-wrapper pkt-btn pkt-btn--medium pkt-btn--secondary pkt-btn--label-only"
825
+ aria-label=${`Forhåndsvis bilde ${u}`}
826
+ ?disabled=${!p}
827
+ @click=${() => {
828
+ !p || !c || c(e.fileId);
829
+ }}
830
+ >
831
+ <span class="pkt-btn__text">
832
+ ${f ? t`<pkt-icon
833
+ name="expand"
834
+ class="pkt-fileupload__queue-display__item__thumbnail__expand-icon"
835
+ aria-hidden="true"
836
+ ></pkt-icon>` : null}
837
+ ${d ? t`<img
838
+ src=${s(n)}
839
+ alt=${u}
840
+ @error=${() => l?.(e.fileId)}
841
+ />` : t`<pkt-icon
842
+ name="document-text"
843
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
844
+ aria-hidden="true"
845
+ ></pkt-icon>`}
846
+ </span>
847
+ </button>
848
+ <span class="pkt-fileupload__queue-display__item__thumbnail__title"
849
+ >${R(u, a)}</span
850
+ >
851
+ </div>
852
+ `;
853
+ }, Z = ({ file: e, inputName: n, disabled: r, fileSize: i, operations: a, activeOperationId: s, onActivateOperation: c, onCloseOperation: l, getFileAttribute: u, setFileAttribute: d, transferProgress: f, transferErrorMessage: p, transferShowProgress: m, transferLastProgress: h, loadingText: g, truncateTail: _, onCancel: v }) => {
854
+ let y = B(f), b = a.find((e) => e.id === s), x = b?.renderInlineUI ? b.renderInlineUI(H({
855
+ operationId: b.id,
856
+ file: e,
857
+ inputName: n,
858
+ disabled: r,
859
+ isActive: !0,
860
+ onActivateOperation: c,
861
+ onCloseOperation: l,
862
+ getFileAttribute: u,
863
+ setFileAttribute: d
864
+ })) : null;
865
+ return t`
866
+ <li
867
+ class=${o({
868
+ "pkt-fileupload__queue-display__item": !0,
869
+ "pkt-fileupload__queue-display__item--in-progress": y === "in-progress",
870
+ "pkt-fileupload__queue-display__item--error": y === "error",
871
+ [`pkt-fileupload__queue-display__item--${f}`]: typeof f == "string"
872
+ })}
873
+ >
874
+ ${J({
875
+ file: e,
876
+ disabled: r,
877
+ inputName: n,
878
+ operations: a,
879
+ activeOperationId: s,
880
+ onActivateOperation: c,
881
+ onCloseOperation: l,
882
+ getFileAttribute: u,
883
+ setFileAttribute: d
884
+ })}
885
+ ${y === "in-progress" ? U({
886
+ file: e,
887
+ fileSize: i,
888
+ disabled: r,
889
+ transferProgress: f,
890
+ transferShowProgress: m,
891
+ loadingText: g,
892
+ truncateTail: _,
893
+ onCancel: v
894
+ }) : y === "error" ? W({
895
+ file: e,
896
+ fileSize: i,
897
+ disabled: r,
898
+ transferShowProgress: m,
899
+ transferLastProgress: h,
900
+ transferErrorMessage: p,
901
+ truncateTail: _,
902
+ onCancel: v
903
+ }) : x ? t`
904
+ <pkt-icon
905
+ name="document-text"
906
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
907
+ aria-hidden="true"
908
+ ></pkt-icon>
909
+ <div class="pkt-fileupload__queue-display__item__inline-ui">
910
+ ${x}
911
+ </div>
912
+ ` : Y(e, i, _)}
913
+ ${y === "idle" ? G({
914
+ file: e,
915
+ disabled: r,
916
+ inputName: n,
917
+ operations: a,
918
+ activeOperationId: s,
919
+ onActivateOperation: c,
920
+ onCloseOperation: l,
921
+ getFileAttribute: u,
922
+ setFileAttribute: d
923
+ }) : null}
924
+ ${y === "idle" ? K({
925
+ file: e,
926
+ disabled: r,
927
+ inputName: n,
928
+ operations: a,
929
+ activeOperationId: s,
930
+ onActivateOperation: c,
931
+ onCloseOperation: l,
932
+ getFileAttribute: u,
933
+ setFileAttribute: d
934
+ }) : null}
935
+ ${y === "idle" ? q({
936
+ file: e,
937
+ disabled: r,
938
+ inputName: n,
939
+ operations: a,
940
+ activeOperationId: s,
941
+ onActivateOperation: c,
942
+ onCloseOperation: l,
943
+ getFileAttribute: u,
944
+ setFileAttribute: d
945
+ }) : null}
946
+ </li>
947
+ `;
948
+ }, Q = ({ file: e, inputName: n, disabled: r, fileSize: i, thumbnailUrl: a, previewEnabled: s, canOpenPreview: c, operations: l, activeOperationId: u, onActivateOperation: d, onCloseOperation: f, getFileAttribute: p, setFileAttribute: m, transferProgress: h, transferErrorMessage: g, transferShowProgress: _, transferLastProgress: v, loadingText: y, truncateTail: b, onCancel: x, onOpenPreview: S, onThumbnailImageError: C }) => {
949
+ let w = B(h), T = l.find((e) => e.id === u), E = T?.renderInlineUI ? T.renderInlineUI(H({
950
+ operationId: T.id,
951
+ file: e,
952
+ inputName: n,
953
+ disabled: r,
954
+ isActive: !0,
955
+ onActivateOperation: d,
956
+ onCloseOperation: f,
957
+ getFileAttribute: p,
958
+ setFileAttribute: m
959
+ })) : null;
960
+ return t`
961
+ <li
962
+ class=${o({
963
+ "pkt-fileupload__queue-display__item": !0,
964
+ "pkt-fileupload__queue-display__item--in-progress": w === "in-progress",
965
+ "pkt-fileupload__queue-display__item--error": w === "error",
966
+ [`pkt-fileupload__queue-display__item--${h}`]: typeof h == "string"
967
+ })}
968
+ >
969
+ ${J({
970
+ file: e,
971
+ disabled: r,
972
+ inputName: n,
973
+ operations: l,
974
+ activeOperationId: u,
975
+ onActivateOperation: d,
976
+ onCloseOperation: f,
977
+ getFileAttribute: p,
978
+ setFileAttribute: m
979
+ })}
980
+ ${w === "in-progress" ? U({
981
+ file: e,
982
+ fileSize: i,
983
+ disabled: r,
984
+ transferProgress: h,
985
+ transferShowProgress: _,
986
+ loadingText: y,
987
+ truncateTail: b,
988
+ onCancel: x,
989
+ iconName: "picture"
990
+ }) : w === "error" ? W({
991
+ file: e,
992
+ fileSize: i,
993
+ disabled: r,
994
+ transferShowProgress: _,
995
+ transferLastProgress: v,
996
+ transferErrorMessage: g,
997
+ truncateTail: b,
998
+ onCancel: x
999
+ }) : E ? t`
1000
+ <pkt-icon
1001
+ name="picture"
1002
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
1003
+ aria-hidden="true"
1004
+ ></pkt-icon>
1005
+ <div class="pkt-fileupload__queue-display__item__inline-ui">
1006
+ ${E}
1007
+ </div>
1008
+ ` : X({
1009
+ file: e,
1010
+ thumbnailUrl: a,
1011
+ previewEnabled: s,
1012
+ canOpenPreview: c,
1013
+ truncateTail: b,
1014
+ onOpenPreview: S,
1015
+ onThumbnailImageError: C
1016
+ })}
1017
+ ${w === "idle" ? G({
1018
+ file: e,
1019
+ disabled: r,
1020
+ inputName: n,
1021
+ operations: l,
1022
+ activeOperationId: u,
1023
+ onActivateOperation: d,
1024
+ onCloseOperation: f,
1025
+ getFileAttribute: p,
1026
+ setFileAttribute: m
1027
+ }) : null}
1028
+ ${w === "idle" ? K({
1029
+ file: e,
1030
+ disabled: r,
1031
+ inputName: n,
1032
+ operations: l,
1033
+ activeOperationId: u,
1034
+ onActivateOperation: d,
1035
+ onCloseOperation: f,
1036
+ getFileAttribute: p,
1037
+ setFileAttribute: m
1038
+ }) : null}
1039
+ ${w === "idle" ? q({
1040
+ file: e,
1041
+ disabled: r,
1042
+ inputName: n,
1043
+ operations: l,
1044
+ activeOperationId: u,
1045
+ onActivateOperation: d,
1046
+ onCloseOperation: f,
1047
+ getFileAttribute: p,
1048
+ setFileAttribute: m
1049
+ }) : null}
1050
+ </li>
1051
+ `;
1052
+ }, $ = class extends A {
1053
+ constructor(...e) {
1054
+ super(...e), this.activeOperationByFileId = {}, this.isPreviewModalOpen = !1, this.previewCurrentIndex = 0, this.failedImageFileIds = {}, this.closePreview = () => {
1055
+ this.isPreviewModalOpen = !1;
1056
+ }, this.onPreviewKeyDown = (e, t) => {
1057
+ if (this.isPreviewModalOpen) {
1058
+ if (e.key === "Tab") {
1059
+ T(e, e.currentTarget);
1060
+ return;
1061
+ }
1062
+ switch (e.key) {
1063
+ case "ArrowLeft":
1064
+ e.preventDefault(), this.navigatePreview("prev", t);
1065
+ break;
1066
+ case "ArrowRight":
1067
+ e.preventDefault(), this.navigatePreview("next", t);
1068
+ break;
1069
+ case "Escape":
1070
+ e.preventDefault(), this.closePreview();
1071
+ break;
1072
+ default: break;
1073
+ }
1074
+ }
1075
+ };
1076
+ }
1077
+ render() {
1078
+ let e = this.renderContent();
1079
+ return this.label ? t`
1080
+ <pkt-input-wrapper
1081
+ .forId=${`${this.id}-input`}
1082
+ .label=${this.label}
1083
+ .helptext=${this.helptext}
1084
+ ?disabled=${this.disabled}
1085
+ ?hasError=${this.hasEffectiveError}
1086
+ ?optionalTag=${this.optionalTag}
1087
+ ?requiredTag=${this.requiredTag}
1088
+ class=${o({
1089
+ "pkt-fileupload-wrapper": !0,
1090
+ "pkt-fileupload-wrapper--full-width": this.fullwidth
1091
+ })}
1092
+ >
1093
+ ${e}
1094
+ </pkt-input-wrapper>
1095
+ ` : e;
1096
+ }
1097
+ renderContent() {
1098
+ let e = this.getSortedFilesAndTransfers(), n = this.getPreviewableImages(e), r = this.getSupportedFormatsText(), i = [!this.label && this.helptext ? `${this.id}-helptext` : void 0, this.hasEffectiveError ? `${this.id}-error` : void 0].filter(Boolean).join(" ") || void 0, a = this.itemRenderer === "thumbnail" ? this.multiple ? {
1099
+ dragInactive: l.dropZoneDragMultipleThumbnail,
1100
+ dragActive: l.dropZoneDragActiveMultipleThumbnail,
1101
+ openFileDialog: l.dropZoneOpenFileDialogMultipleThumbnail
1102
+ } : {
1103
+ dragInactive: l.dropZoneDragSingleThumbnail,
1104
+ dragActive: l.dropZoneDragActiveSingleThumbnail,
1105
+ openFileDialog: l.dropZoneOpenFileDialogSingleThumbnail
1106
+ } : this.multiple ? {
1107
+ dragInactive: l.dropZoneDragMultiple,
1108
+ dragActive: l.dropZoneDragActiveMultiple,
1109
+ openFileDialog: l.dropZoneOpenFileDialogMultiple
1110
+ } : {
1111
+ dragInactive: l.dropZoneDragSingle,
1112
+ dragActive: l.dropZoneDragActiveSingle,
1113
+ openFileDialog: l.dropZoneOpenFileDialogSingle
1114
+ };
1115
+ return t`
1116
+ <div
1117
+ class=${o({
1118
+ "pkt-fileupload": !0,
1119
+ "pkt-fileupload--full-width": this.fullwidth,
1120
+ "pkt-fileupload--error": this.hasEffectiveError,
1121
+ "pkt-fileupload--disabled": this.disabled
1122
+ })}
1123
+ aria-disabled=${String(this.disabled)}
1124
+ ?inert=${this.disabled}
1125
+ >
1126
+ <div class="pkt-sr-only" aria-live="polite" aria-atomic="true">
1127
+ ${this.getSrUploadedMessage()}
1128
+ </div>
1129
+ <div class="pkt-sr-only" aria-live="assertive" aria-atomic="true">
1130
+ ${this.getSrErrorsMessage()}
1131
+ </div>
1132
+ <div
1133
+ class=${o({
1134
+ "pkt-fileupload__drop-zone": !0,
1135
+ "pkt-fileupload__drop-zone--drag-active": this.isDragActive,
1136
+ "pkt-fileupload__drop-zone--disabled": this.disabled
1137
+ })}
1138
+ @dragover=${this.onDragOver}
1139
+ @dragleave=${this.onDragLeave}
1140
+ @drop=${this.onDrop}
1141
+ @click=${this.onDropZoneClick}
1142
+ >
1143
+ <input
1144
+ id=${`${this.id}-input`}
1145
+ type="file"
1146
+ name=${s(this.uploadStrategy === "form" ? this.name : void 0)}
1147
+ ?multiple=${this.multiple}
1148
+ ?disabled=${this.disabled}
1149
+ ?required=${this.required && this.uploadStrategy === "form"}
1150
+ accept=${this.getResolvedAcceptValue()}
1151
+ aria-label=${s(this.label ? void 0 : this.multiple ? "Velg filer" : "Velg fil")}
1152
+ aria-required=${s(this.required ? "true" : void 0)}
1153
+ aria-invalid=${s(this.hasEffectiveError ? "true" : void 0)}
1154
+ aria-describedby=${s(i)}
1155
+ @change=${this.onNativeFileChange}
1156
+ />
1157
+ ${this.uploadStrategy === "custom" ? e.map((e) => t`<input type="hidden" name=${this.name} value=${e.fileId} />`) : null}
1158
+ <div class="pkt-fileupload__drop-zone__placeholder">
1159
+ <pkt-icon
1160
+ name="attachment"
1161
+ class="pkt-fileupload__drop-zone__placeholder__icon"
1162
+ aria-hidden="true"
1163
+ ></pkt-icon>
1164
+ <p class="pkt-fileupload__drop-zone__placeholder__title">
1165
+ ${this.isDragActive ? `${a.dragActive} ...` : t`${a.dragInactive}
1166
+ <button
1167
+ type="button"
1168
+ class="pkt-fileupload__drop-zone__placeholder__title__open-file-dialog"
1169
+ @click=${this.openFileDialog}
1170
+ >
1171
+ ${a.openFileDialog}
1172
+ </button>`}
1173
+ </p>
1174
+ ${r ? t`<p class="pkt-fileupload__drop-zone__placeholder__formats">
1175
+ ${l.supportedFormatsPrefix} ${r}
1176
+ </p>` : null}
1177
+ </div>
1178
+ </div>
1179
+ ${this.hasEffectiveError ? t`
1180
+ <pkt-alert
1181
+ skin="error"
1182
+ role="alert"
1183
+ aria-live="assertive"
1184
+ compact
1185
+ id=${`${this.id}-error`}
1186
+ class="pkt-alert--error pkt-fileupload__error-alert"
1187
+ >
1188
+ ${this.effectiveErrorMessage}
1189
+ </pkt-alert>
1190
+ ` : null}
1191
+ ${e.length > 0 ? t`<ul class="pkt-fileupload__queue-display">
1192
+ ${e.map((e) => this.renderQueueItem(e, n))}
1193
+ </ul>` : null}
1194
+ ${this.renderPreviewModal(n)}
1195
+ </div>
1196
+ `;
1197
+ }
1198
+ renderQueueItem(e, t) {
1199
+ let n = typeof e.file?.size == "number" ? this.formatFileSize(e.file.size) : "", r = this.getQueueItemOperations();
1200
+ if (this.itemRenderer === "thumbnail") {
1201
+ let i = this.canOpenPreview(e), a = this.failedImageFileIds[e.fileId]?.thumbnail ? void 0 : this.getThumbnailUrl(e);
1202
+ return Q({
1203
+ file: e,
1204
+ inputName: this.name,
1205
+ disabled: this.disabled,
1206
+ fileSize: n,
1207
+ operations: r,
1208
+ activeOperationId: this.activeOperationByFileId[e.fileId],
1209
+ onActivateOperation: (e, t) => this.activateOperation(e, t),
1210
+ onCloseOperation: (e) => this.closeOperation(e),
1211
+ getFileAttribute: (e, t) => this.getFileAttribute(e, t),
1212
+ setFileAttribute: (e, t, n) => this.setFileAttribute(e, t, n),
1213
+ thumbnailUrl: a,
1214
+ previewEnabled: this.enableImagePreview,
1215
+ canOpenPreview: i,
1216
+ transferProgress: e.progress,
1217
+ transferErrorMessage: e.errorMessage,
1218
+ transferShowProgress: e.showProgress,
1219
+ transferLastProgress: e.lastProgress,
1220
+ loadingText: "Laster opp",
1221
+ truncateTail: this.truncateTail,
1222
+ onCancel: (e) => this.cancelTransfer(e),
1223
+ onOpenPreview: (e) => this.openPreview(e, t),
1224
+ onThumbnailImageError: (e) => this.markImageFailed(e, "thumbnail")
1225
+ });
1226
+ }
1227
+ return Z({
1228
+ file: e,
1229
+ inputName: this.name,
1230
+ disabled: this.disabled,
1231
+ fileSize: n,
1232
+ operations: r,
1233
+ activeOperationId: this.activeOperationByFileId[e.fileId],
1234
+ onActivateOperation: (e, t) => this.activateOperation(e, t),
1235
+ onCloseOperation: (e) => this.closeOperation(e),
1236
+ getFileAttribute: (e, t) => this.getFileAttribute(e, t),
1237
+ setFileAttribute: (e, t, n) => this.setFileAttribute(e, t, n),
1238
+ transferProgress: e.progress,
1239
+ transferErrorMessage: e.errorMessage,
1240
+ transferShowProgress: e.showProgress,
1241
+ transferLastProgress: e.lastProgress,
1242
+ loadingText: "Laster opp",
1243
+ truncateTail: this.truncateTail,
1244
+ onCancel: (e) => this.cancelTransfer(e)
1245
+ });
1246
+ }
1247
+ markImageFailed(e, t) {
1248
+ this.failedImageFileIds = {
1249
+ ...this.failedImageFileIds,
1250
+ [e]: {
1251
+ ...this.failedImageFileIds[e],
1252
+ [t]: !0
1253
+ }
1254
+ };
1255
+ }
1256
+ getPreviewableImages(e) {
1257
+ return this.enableImagePreview ? e.filter((e) => e.progress === "done" && this.isImageFile(e)) : [];
1258
+ }
1259
+ canOpenPreview(e) {
1260
+ return this.enableImagePreview && e.progress === "done" && this.isImageFile(e);
1261
+ }
1262
+ openPreview(e, t) {
1263
+ let n = t.findIndex((t) => t.fileId === e);
1264
+ n < 0 || (this.previewCurrentIndex = n, this.isPreviewModalOpen = !0, this.failedImageFileIds = {
1265
+ ...this.failedImageFileIds,
1266
+ [e]: {
1267
+ ...this.failedImageFileIds[e],
1268
+ preview: !1
1269
+ }
1270
+ });
1271
+ }
1272
+ navigatePreview(e, t) {
1273
+ t.length !== 0 && (this.previewCurrentIndex = D(this.previewCurrentIndex, e, t.length));
1274
+ }
1275
+ renderPreviewModal(e) {
1276
+ if (!this.enableImagePreview || e.length === 0) return null;
1277
+ let n = e[this.previewCurrentIndex];
1278
+ if (!n) return null;
1279
+ let r = e.length > 1, i = this.getThumbnailUrl(n), a = !!i && !this.failedImageFileIds[n.fileId]?.preview, o = n.attributes?.targetFilename || n.file?.name || "Forhåndsvisning";
1280
+ return t`
1281
+ <pkt-modal
1282
+ .open=${this.isPreviewModalOpen}
1283
+ .headingText=${o}
1284
+ closeOnBackdropClick
1285
+ class="pkt-fileupload__image-preview-modal"
1286
+ @close=${this.closePreview}
1287
+ @keydown=${(t) => this.onPreviewKeyDown(t, e)}
1288
+ >
1289
+ <div class="pkt-fileupload__image-preview">
1290
+ ${r ? t`<button
1291
+ type="button"
1292
+ class="pkt-fileupload__image-preview__nav pkt-fileupload__image-preview__nav--prev pkt-btn pkt-btn--medium pkt-btn--secondary pkt-btn--icon-only"
1293
+ aria-label=${`Forrige bilde ${this.previewCurrentIndex} / ${e.length}`}
1294
+ @click=${() => this.navigatePreview("prev", e)}
1295
+ >
1296
+ <pkt-icon
1297
+ class="pkt-btn__icon pkt-icon"
1298
+ name="chevron-thin-left"
1299
+ aria-hidden="true"
1300
+ ></pkt-icon>
1301
+ <span class="pkt-btn__text"></span>
1302
+ </button>` : null}
1303
+
1304
+ <div class="pkt-fileupload__image-preview__content">
1305
+ ${a ? t`<img
1306
+ src=${i}
1307
+ alt=${`${o} - ${this.previewCurrentIndex + 1} av ${e.length}`}
1308
+ class="pkt-fileupload__image-preview__image"
1309
+ @error=${() => this.markImageFailed(n.fileId, "preview")}
1310
+ />` : t`<pkt-icon
1311
+ name="picture"
1312
+ class="pkt-fileupload__queue-display__item__icon pkt-icon--medium"
1313
+ aria-hidden="true"
1314
+ ></pkt-icon>`}
1315
+ </div>
1316
+
1317
+ ${r ? t`<span class="pkt-fileupload__image-preview__counter">
1318
+ ${this.previewCurrentIndex + 1} / ${e.length}
1319
+ </span>` : null}
1320
+ ${r ? t`<button
1321
+ type="button"
1322
+ class="pkt-fileupload__image-preview__nav pkt-fileupload__image-preview__nav--next pkt-btn pkt-btn--medium pkt-btn--secondary pkt-btn--icon-only"
1323
+ aria-label=${`Neste bilde ${this.previewCurrentIndex + 2} / ${e.length}`}
1324
+ @click=${() => this.navigatePreview("next", e)}
1325
+ >
1326
+ <pkt-icon
1327
+ class="pkt-btn__icon pkt-icon"
1328
+ name="chevron-thin-right"
1329
+ aria-hidden="true"
1330
+ ></pkt-icon>
1331
+ <span class="pkt-btn__text"></span>
1332
+ </button>` : null}
1333
+ </div>
1334
+ </pkt-modal>
1335
+ `;
1336
+ }
1337
+ getQueueItemOperations() {
1338
+ let e = [];
1339
+ return this.renameFilesEnabled && this.itemRenderer !== "thumbnail" && e.push(I()), this.addCommentsEnabled && this.itemRenderer !== "thumbnail" && e.push(L()), e.push(...this.extraOperations), e.push(F((e) => this.removeFileItem(e))), e;
1340
+ }
1341
+ activateOperation(e, t) {
1342
+ this.activeOperationByFileId = {
1343
+ ...this.activeOperationByFileId,
1344
+ [e]: t
1345
+ };
1346
+ }
1347
+ closeOperation(e) {
1348
+ this.activeOperationByFileId = {
1349
+ ...this.activeOperationByFileId,
1350
+ [e]: void 0
1351
+ };
1352
+ }
1353
+ getFileAttribute(e, t) {
1354
+ let n = this.getCurrentFiles().find((t) => t.fileId === e);
1355
+ if (n) return n.attributes?.[t] ?? void 0;
1356
+ }
1357
+ setFileAttribute(e, t, n) {
1358
+ let r = this.getCurrentFiles().find((t) => t.fileId === e);
1359
+ if (!r) return;
1360
+ let i = {
1361
+ ...r.attributes,
1362
+ [t]: n
1363
+ };
1364
+ n === void 0 && delete i[t], this.updateFileItem(e, { attributes: i });
1365
+ }
1366
+ };
1367
+ r([n()], $.prototype, "activeOperationByFileId", void 0), r([n()], $.prototype, "isPreviewModalOpen", void 0), r([n()], $.prototype, "previewCurrentIndex", void 0), r([n()], $.prototype, "failedImageFileIds", void 0), $ = r([e("pkt-fileupload")], $);
1368
+ //#endregion
1369
+ //#region src/components/fileupload/index.ts
1370
+ var ee = $;
1371
+ //#endregion
1372
+ export { $ as n, ee as t };