@oslokommune/punkt-elements 16.14.0 → 16.15.1

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