@oslokommune/punkt-elements 14.5.4 → 15.0.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 (123) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/{accordionitem-DB3tAjIZ.js → accordionitem-BbeS44TD.js} +1 -1
  3. package/dist/{accordionitem-DHYmPA-o.cjs → accordionitem-DUWhTUEI.cjs} +1 -1
  4. package/dist/{alert-DVCenNTM.cjs → alert-B9flMht5.cjs} +1 -1
  5. package/dist/{alert-Cc5FtxHN.js → alert-BpFxQviu.js} +2 -2
  6. package/dist/{button-Ju4zPhVx.cjs → button-BgCKV0zW.cjs} +1 -1
  7. package/dist/{button-DrTXtc-n.js → button-CKgpX5QA.js} +1 -1
  8. package/dist/{calendar-CTx8PD1L.js → calendar-BMarIeVp.js} +332 -325
  9. package/dist/calendar-C6xgAJ7Z.cjs +90 -0
  10. package/dist/{card-DvHL7pNu.cjs → card-DI3KodEc.cjs} +1 -1
  11. package/dist/{card-CTtmPB2n.js → card-h8ekgJRr.js} +2 -2
  12. package/dist/{checkbox-B-0FOdwi.cjs → checkbox-B2t7wfxe.cjs} +1 -1
  13. package/dist/{checkbox-CkAwPK_E.js → checkbox-BJ9pz3kV.js} +1 -1
  14. package/dist/{combobox-DNPfpTjW.js → combobox-BjAvk8Y-.js} +5 -5
  15. package/dist/{combobox-DvL3SKz2.cjs → combobox-HNN7GTzh.cjs} +1 -1
  16. package/dist/{consent-DJW7YEat.cjs → consent-C37tuFwZ.cjs} +1 -1
  17. package/dist/{consent-OdhmtIK-.js → consent-DAk2BJ7I.js} +1 -1
  18. package/dist/datepicker-2bneToiA.cjs +275 -0
  19. package/dist/datepicker-DvcH2QD9.js +1160 -0
  20. package/dist/{helptext-7fyVJK2C.cjs → helptext-BG1P_9j0.cjs} +1 -1
  21. package/dist/{helptext-CfR0SYe9.js → helptext-Cm6FLBVf.js} +1 -1
  22. package/dist/index.d.ts +10 -42
  23. package/dist/input-element-BBv4xjPb.cjs +1 -0
  24. package/dist/{input-element-DVZhYDJ_.js → input-element-CbjYtVou.js} +143 -147
  25. package/dist/{input-wrapper-DVUh5rxv.js → input-wrapper-Bwmva-69.js} +3 -3
  26. package/dist/{input-wrapper-Bta4FZe3.cjs → input-wrapper-CJqmwe3I.cjs} +1 -1
  27. package/dist/{link-40XAFlYS.js → link-BKnT-97D.js} +1 -1
  28. package/dist/{link-CBQ7uKqb.cjs → link-DRPFqqEn.cjs} +1 -1
  29. package/dist/{linkcard-D8hxLedl.cjs → linkcard-02fxYQ2g.cjs} +1 -1
  30. package/dist/{linkcard-Opb42K2k.js → linkcard-C2UENcqo.js} +1 -1
  31. package/dist/{loader-Bv1R6-AA.js → loader-BW-AWQiE.js} +1 -1
  32. package/dist/{loader-Dh_5sihO.cjs → loader-Cj4kUNRE.cjs} +1 -1
  33. package/dist/{messagebox-B9MCodIz.cjs → messagebox-CK0sSRep.cjs} +1 -1
  34. package/dist/{messagebox-DEXCTOrz.js → messagebox-DB8tEXrV.js} +1 -1
  35. package/dist/{modal-Bw61rVrQ.cjs → modal-BzVQSQy2.cjs} +1 -1
  36. package/dist/{modal-B4adxB6X.js → modal-ClYfWW2a.js} +1 -1
  37. package/dist/pkt-accordion.cjs +1 -1
  38. package/dist/pkt-accordion.js +2 -2
  39. package/dist/pkt-alert.cjs +1 -1
  40. package/dist/pkt-alert.js +1 -1
  41. package/dist/pkt-button.cjs +1 -1
  42. package/dist/pkt-button.js +1 -1
  43. package/dist/pkt-calendar.cjs +1 -1
  44. package/dist/pkt-calendar.js +1 -1
  45. package/dist/pkt-card.cjs +1 -1
  46. package/dist/pkt-card.js +1 -1
  47. package/dist/pkt-checkbox.cjs +1 -1
  48. package/dist/pkt-checkbox.js +1 -1
  49. package/dist/pkt-combobox.cjs +1 -1
  50. package/dist/pkt-combobox.js +1 -1
  51. package/dist/pkt-consent.cjs +1 -1
  52. package/dist/pkt-consent.js +1 -1
  53. package/dist/pkt-datepicker.cjs +1 -1
  54. package/dist/pkt-datepicker.js +2 -2
  55. package/dist/pkt-header.cjs +1 -1
  56. package/dist/pkt-header.js +4 -4
  57. package/dist/pkt-helptext.cjs +1 -1
  58. package/dist/pkt-helptext.js +1 -1
  59. package/dist/pkt-index.cjs +1 -1
  60. package/dist/pkt-index.js +22 -22
  61. package/dist/pkt-input-wrapper.cjs +1 -1
  62. package/dist/pkt-input-wrapper.js +1 -1
  63. package/dist/pkt-link.cjs +1 -1
  64. package/dist/pkt-link.js +1 -1
  65. package/dist/pkt-linkcard.cjs +1 -1
  66. package/dist/pkt-linkcard.js +1 -1
  67. package/dist/pkt-loader.cjs +1 -1
  68. package/dist/pkt-loader.js +1 -1
  69. package/dist/pkt-messagebox.cjs +1 -1
  70. package/dist/pkt-messagebox.js +1 -1
  71. package/dist/pkt-modal.cjs +1 -1
  72. package/dist/pkt-modal.js +1 -1
  73. package/dist/{pkt-options-controller-zn5cmMvL.js → pkt-options-controller-BcGywCmf.js} +1 -1
  74. package/dist/{pkt-options-controller-DjBCEHU4.cjs → pkt-options-controller-BnTmkl3g.cjs} +1 -1
  75. package/dist/pkt-radiobutton.cjs +1 -1
  76. package/dist/pkt-radiobutton.js +1 -1
  77. package/dist/pkt-select.cjs +1 -1
  78. package/dist/pkt-select.js +1 -1
  79. package/dist/pkt-slot-controller-D4nKlom5.cjs +1 -0
  80. package/dist/{pkt-slot-controller-BPGj-LC5.js → pkt-slot-controller-D7CrjM52.js} +27 -25
  81. package/dist/pkt-tabs.cjs +1 -1
  82. package/dist/pkt-tabs.js +2 -2
  83. package/dist/pkt-tag.cjs +1 -1
  84. package/dist/pkt-tag.js +1 -1
  85. package/dist/pkt-textarea.cjs +1 -1
  86. package/dist/pkt-textarea.js +1 -1
  87. package/dist/pkt-textinput.cjs +1 -1
  88. package/dist/pkt-textinput.js +1 -1
  89. package/dist/{radiobutton-oA20HijB.js → radiobutton-CvKKNFMd.js} +1 -1
  90. package/dist/{radiobutton-iHuLnuAn.cjs → radiobutton-DWoYQn8H.cjs} +1 -1
  91. package/dist/{select--wvwpJ0_.cjs → select-BQUp88lY.cjs} +1 -1
  92. package/dist/{select-DfsNb_Yi.js → select-CFkxir_l.js} +4 -4
  93. package/dist/{tabitem-CypTmORF.js → tabitem-C8-tZyc_.js} +1 -1
  94. package/dist/{tabitem-CtltSqDK.cjs → tabitem-DaYfUaxw.cjs} +1 -1
  95. package/dist/{tag-Cw3OQqLW.js → tag-DIJMJhyp.js} +1 -1
  96. package/dist/{tag-P9lfQZbM.cjs → tag-h0vD2Na0.cjs} +1 -1
  97. package/dist/{textarea-CM_bj81t.js → textarea-CMuiBUee.js} +3 -3
  98. package/dist/{textarea-DcEKhXia.cjs → textarea-DcCOfNlr.cjs} +1 -1
  99. package/dist/{textinput-AVll6Nh7.js → textinput-D30TCADP.js} +3 -3
  100. package/dist/{textinput-BzuYzKZ6.cjs → textinput-DR3aaHTH.cjs} +1 -1
  101. package/package.json +4 -4
  102. package/src/components/calendar/calendar.core.test.ts +1 -1
  103. package/src/components/calendar/calendar.selection.test.ts +1 -1
  104. package/src/components/calendar/calendar.ts +32 -22
  105. package/src/components/datepicker/datepicker-popup.test.ts +1 -1
  106. package/src/components/datepicker/datepicker-popup.ts +73 -30
  107. package/src/components/datepicker/datepicker-range.ts +5 -1
  108. package/src/components/datepicker/datepicker-types.ts +4 -54
  109. package/src/components/datepicker/datepicker-utils.ts +38 -517
  110. package/src/components/datepicker/datepicker.core.test.ts +12 -10
  111. package/src/components/datepicker/datepicker.selection.test.ts +8 -6
  112. package/src/components/datepicker/datepicker.ts +26 -7
  113. package/src/components/icon/icon.test.ts +8 -8
  114. package/dist/calendar-5Obd0ZT3.cjs +0 -90
  115. package/dist/datepicker-CTCaZuZU.cjs +0 -271
  116. package/dist/datepicker-t0W9fA1e.js +0 -1444
  117. package/dist/input-element-RBQVA8i0.cjs +0 -1
  118. package/dist/pkt-slot-controller-BzddBp7z.cjs +0 -1
  119. package/src/components/calendar/helpers/calendar-grid.ts +0 -93
  120. package/src/components/calendar/helpers/date-validation.ts +0 -86
  121. package/src/components/calendar/helpers/index.ts +0 -49
  122. package/src/components/calendar/helpers/keyboard-navigation.ts +0 -54
  123. package/src/components/calendar/helpers/selection-manager.ts +0 -184
@@ -1,1444 +0,0 @@
1
- import { P as L, E, x as o, n as l, t as w } from "./element-BXsf_NlG.js";
2
- import { r as G } from "./state-DgnkjP0q.js";
3
- import { s as z, f as K, n as A, a as J, i as Q, b as F, v as D, c as X, d as Y, p as Z, e as H } from "./calendar-CTx8PD1L.js";
4
- import { P as ee } from "./input-element-DVZhYDJ_.js";
5
- import { e as g, n as v } from "./ref-BxiKhrfa.js";
6
- import "./icon-DBZvMard.js";
7
- import "./input-wrapper-DVUh5rxv.js";
8
- import { e as $ } from "./class-map-Dt2jXOlF.js";
9
- import { c as te } from "./repeat-B55jMEsG.js";
10
- import "./tag-Cw3OQqLW.js";
11
- import { u as se, s as ie } from "./utils-DznhwRXm.js";
12
- import { o as f } from "./if-defined-CxHgig4I.js";
13
- import { P as ae } from "./pkt-slot-controller-BPGj-LC5.js";
14
- var ne = Object.defineProperty, le = Object.getOwnPropertyDescriptor, R = (e, t, a, s) => {
15
- for (var i = s > 1 ? void 0 : s ? le(t, a) : t, n = e.length - 1, r; n >= 0; n--)
16
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
17
- return s && i && ne(t, a, i), i;
18
- };
19
- let k = class extends L {
20
- constructor() {
21
- super(...arguments), this.dates = [], this.dateformat = "dd.MM.yyyy", this.className = "pkt-datepicker__tags", this.idBase = se();
22
- }
23
- render() {
24
- return this.classes = {
25
- "pkt-date-tags": !0,
26
- [this.className]: !0
27
- }, o`
28
- <div class=${$(this.classes)} aria-live="polite">
29
- ${Array.isArray(this.dates) && this.dates[0] ? te(
30
- z((this.dates ?? []).filter(Boolean)),
31
- (e) => e,
32
- (e) => {
33
- var t;
34
- return o` <pkt-tag
35
- id=${this.idBase + e + "-tag"}
36
- closeTag
37
- @close=${() => {
38
- this.dispatchEvent(new CustomEvent("date-tag-removed", { detail: e }));
39
- }}
40
- .ariaLabel=${`${(t = this.strings) == null ? void 0 : t.calendar.deleteDate} ${K(e, this.dateformat)}`}
41
- >
42
- <time datetime=${e}>${K(e, this.dateformat)}</time>
43
- </pkt-tag>`;
44
- }
45
- ) : E}
46
- </div>
47
- `;
48
- }
49
- };
50
- R([
51
- l({ type: Array })
52
- ], k.prototype, "dates", 2);
53
- R([
54
- l({ type: String })
55
- ], k.prototype, "dateformat", 2);
56
- R([
57
- l({ type: String, attribute: "class" })
58
- ], k.prototype, "className", 2);
59
- R([
60
- l({ type: String, attribute: "id-base" })
61
- ], k.prototype, "idBase", 2);
62
- k = R([
63
- w("pkt-date-tags")
64
- ], k);
65
- const re = { dateformat: { default: "dd.MM.yyyy" }, weeknumbers: { default: !1 }, withcontrols: { default: !1 }, multiple: { default: !1 }, range: { default: !1 } }, C = {
66
- props: re
67
- }, b = () => {
68
- const e = navigator.userAgent;
69
- return !!(/iP(hone|od|ad)/.test(e) || /Macintosh/.test(e) && "ontouchend" in document);
70
- }, N = {
71
- /**
72
- * Validates that a range has valid order (start <= end)
73
- *
74
- * @param values - Array of date strings (ISO format YYYY-MM-DD)
75
- * @returns True if range is valid or incomplete, false if end date is before start date
76
- *
77
- * @example
78
- * validateRangeOrder(['2024-01-01', '2024-01-31']) // Returns true
79
- * validateRangeOrder(['2024-01-31', '2024-01-01']) // Returns false
80
- * validateRangeOrder(['2024-01-01']) // Returns true (incomplete range)
81
- */
82
- validateRangeOrder(e) {
83
- return !e || e.length !== 2 ? !0 : Q(e[0], e[1]);
84
- },
85
- /**
86
- * Sorts date strings chronologically
87
- *
88
- * @param dates - Array of date strings in ISO format (YYYY-MM-DD)
89
- * @returns New array with dates sorted from earliest to latest
90
- *
91
- * @example
92
- * sortDates(['2024-03-15', '2024-01-10', '2024-02-20'])
93
- * // Returns ['2024-01-10', '2024-02-20', '2024-03-15']
94
- */
95
- sortDates(e) {
96
- return z(e);
97
- },
98
- /**
99
- * Filters dates to only include selectable ones based on constraints
100
- *
101
- * Removes dates that:
102
- * - Fall outside the min/max range
103
- * - Are in the excludedDates array
104
- * - Fall on excluded weekdays (0=Sunday, 6=Saturday)
105
- *
106
- * @param dates - Array of date strings to filter
107
- * @param min - Minimum allowed date (ISO format)
108
- * @param max - Maximum allowed date (ISO format)
109
- * @param excludedDates - Array of specific dates to exclude
110
- * @param excludedWeekdays - Array of weekday numbers to exclude ('0'-'6')
111
- * @returns Filtered array containing only selectable dates
112
- *
113
- * @example
114
- * filterSelectableDates(
115
- * ['2024-01-01', '2024-01-06', '2024-01-15'],
116
- * '2024-01-05',
117
- * '2024-01-20',
118
- * ['2024-01-15'],
119
- * ['0', '6'] // Exclude weekends
120
- * )
121
- * // Returns ['2024-01-06'] (after min, not excluded, not a weekend)
122
- */
123
- filterSelectableDates(e, t, a, s, i) {
124
- return J(e, t, a, s, i);
125
- }
126
- }, pe = {
127
- /**
128
- * Determines the appropriate input type based on device
129
- *
130
- * Mobile Safari does not play well with type="date" and custom datepickers,
131
- * so we use type="text" on iOS devices to avoid the native date picker
132
- * interfering with our custom calendar component.
133
- *
134
- * @returns 'text' for iOS devices, 'date' for all other devices
135
- *
136
- * @example
137
- * const inputType = getInputType()
138
- * // Returns 'text' on iPhone/iPad, 'date' on desktop/Android
139
- */
140
- getInputType() {
141
- return b() ? "text" : "date";
142
- }
143
- }, x = {
144
- /**
145
- * Submits the form that contains the given element
146
- *
147
- * Uses ElementInternals API to access the associated form and trigger submission.
148
- * Requires the element to have attachInternals() called.
149
- *
150
- * @param element - The form-associated custom element
151
- *
152
- * @example
153
- * submitForm(this) // From within a custom element
154
- */
155
- submitForm(e) {
156
- var a;
157
- const t = (a = e.internals) == null ? void 0 : a.form;
158
- t && t.requestSubmit();
159
- },
160
- /**
161
- * Submits form if available, otherwise executes fallback action
162
- *
163
- * Useful for Enter key handling where we want to submit the form,
164
- * but provide a fallback behavior (like moving focus) if not in a form.
165
- *
166
- * @param internals - ElementInternals instance with optional form reference
167
- * @param fallbackAction - Function to call if no form is available
168
- *
169
- * @example
170
- * submitFormOrFallback(
171
- * this.internals,
172
- * () => this.inputRef.value?.blur()
173
- * )
174
- */
175
- submitFormOrFallback(e, t) {
176
- const a = e == null ? void 0 : e.form;
177
- a ? a.requestSubmit() : t();
178
- },
179
- /**
180
- * Validates a date input and sets validity state
181
- *
182
- * Checks if the input value falls within the min/max range and
183
- * sets appropriate validity flags using the ElementInternals API.
184
- *
185
- * @param input - The input element to validate
186
- * @param internals - ElementInternals instance for setting validity
187
- * @param min - Minimum allowed date (ISO format)
188
- * @param max - Maximum allowed date (ISO format)
189
- * @param strings - Optional localized error messages
190
- *
191
- * @example
192
- * validateDateInput(
193
- * inputElement,
194
- * this.internals,
195
- * '2024-01-01',
196
- * '2024-12-31',
197
- * { forms: { messages: { rangeUnderflow: 'Date too early' } } }
198
- * )
199
- */
200
- validateDateInput(e, t, a, s, i) {
201
- var r, h, U, q;
202
- const n = e.value;
203
- n && (a && a > n ? t.setValidity(
204
- { rangeUnderflow: !0 },
205
- ((h = (r = i == null ? void 0 : i.forms) == null ? void 0 : r.messages) == null ? void 0 : h.rangeUnderflow) || "Value is below minimum",
206
- e
207
- ) : s && s < n && t.setValidity(
208
- { rangeOverflow: !0 },
209
- ((q = (U = i == null ? void 0 : i.forms) == null ? void 0 : U.messages) == null ? void 0 : q.rangeOverflow) || "Value is above maximum",
210
- e
211
- ));
212
- }
213
- }, P = {
214
- /**
215
- * Adds a date to selected dates if it's valid
216
- *
217
- * Used for multiple date selection - validates the input date against
218
- * min/max constraints before adding it to the calendar's selected dates.
219
- * Clears the input field after processing.
220
- *
221
- * @param event - Input or keyboard event containing the target input
222
- * @param calendarRef - Lit ref to the calendar component
223
- * @param min - Minimum allowed date (ISO format)
224
- * @param max - Maximum allowed date (ISO format)
225
- *
226
- * @example
227
- * addToSelected(
228
- * blurEvent,
229
- * this.calendarRef,
230
- * '2024-01-01',
231
- * '2024-12-31'
232
- * )
233
- */
234
- addToSelected(e, t, a, s) {
235
- const i = e.target;
236
- if (!i.value) return;
237
- const n = a ? A(a) : null, r = s ? A(s) : null, h = A(i.value.split(",")[0]);
238
- h && !isNaN(h.getTime()) && (!n || h >= n) && (!r || h <= r) && t.value && t.value.handleDateSelect(h), i.value = "";
239
- },
240
- /**
241
- * Handles calendar positioning based on viewport and input position
242
- *
243
- * Intelligently positions the calendar popup either above or below the input
244
- * depending on available viewport space. Accounts for optional counter elements.
245
- *
246
- * The positioning logic:
247
- * 1. By default, positions calendar below the input (top: 100%)
248
- * 2. If calendar would overflow viewport bottom AND there's space above, positions above
249
- * 3. Accounts for counter height (30px) when hasCounter is true
250
- *
251
- * @param popupRef - Lit ref to the calendar popup element
252
- * @param inputRef - Lit ref to the input element
253
- * @param hasCounter - Whether the input has a character counter below it
254
- *
255
- * @example
256
- * handleCalendarPosition(
257
- * this.popupRef,
258
- * this.inputRef,
259
- * this.multiple && this.maxlength !== null
260
- * )
261
- */
262
- handleCalendarPosition(e, t, a = !1) {
263
- var h;
264
- if (!e.value || !t.value) return;
265
- const s = ((h = t.value.parentElement) == null ? void 0 : h.getBoundingClientRect()) || t.value.getBoundingClientRect(), i = a ? s.height + 30 : s.height, n = e.value.getBoundingClientRect().height;
266
- let r = a ? "calc(100% - 30px)" : "100%";
267
- s && s.top + n > window.innerHeight && s.top - n > 0 && (r = `calc(100% - ${i}px - ${n}px)`), e.value.style.top = r;
268
- }
269
- }, V = {
270
- /**
271
- * Generates input classes for datepicker
272
- *
273
- * @param fullwidth - Whether input should take full width
274
- * @param showRangeLabels - Whether range labels are visible
275
- * @param multiple - Whether this is a multiple date picker
276
- * @param range - Whether this is a range date picker
277
- * @param readonly - Whether input is readonly
278
- * @param inputType - The input type ('date' or 'text')
279
- * @returns Object with class names as keys and boolean values
280
- *
281
- * @example
282
- * const classes = getInputClasses(true, false, false, false, false, 'date')
283
- * // Returns { 'pkt-input': true, 'pkt-input--fullwidth': true, ... }
284
- */
285
- getInputClasses(e, t, a, s, i, n) {
286
- return {
287
- "pkt-input": !0,
288
- "pkt-datepicker__input": !0,
289
- "pkt-input--fullwidth": e,
290
- "pkt-datepicker--hasrangelabels": t,
291
- "pkt-datepicker--multiple": a,
292
- "pkt-datepicker--range": s,
293
- "ios-readonly-hack": i === !1 && n === "text"
294
- };
295
- },
296
- /**
297
- * Generates button classes for calendar button
298
- *
299
- * @returns Object with class names for the calendar toggle button
300
- *
301
- * @example
302
- * const classes = getButtonClasses()
303
- * // Returns { 'pkt-btn': true, 'pkt-btn--icon-only': true, ... }
304
- */
305
- getButtonClasses() {
306
- return {
307
- "pkt-input-icon": !0,
308
- "pkt-btn": !0,
309
- "pkt-btn--icon-only": !0,
310
- "pkt-btn--tertiary": !0,
311
- "pkt-datepicker__calendar-button": !0
312
- };
313
- },
314
- /**
315
- * Generates range label classes
316
- *
317
- * @param showRangeLabels - Whether range labels should be visible
318
- * @returns Object with class names for range label elements
319
- *
320
- * @example
321
- * const classes = getRangeLabelClasses(true)
322
- * // Returns { 'pkt-input-prefix': true, 'pkt-hide': false }
323
- */
324
- getRangeLabelClasses(e) {
325
- return {
326
- "pkt-input-prefix": e,
327
- "pkt-hide": !e
328
- };
329
- }
330
- }, j = {
331
- /**
332
- * Processes date selection from calendar events
333
- *
334
- * Converts the calendar's date selection into the appropriate string format
335
- * for the input element's value.
336
- *
337
- * @param detail - Date selection detail from calendar event (string or array)
338
- * @param multiple - Whether this is a multiple date picker
339
- * @param range - Whether this is a range date picker
340
- * @returns Formatted date string (single date or comma-separated dates)
341
- *
342
- * @example
343
- * processDateSelection(['2024-01-15'], false, false) // Returns '2024-01-15'
344
- * processDateSelection(['2024-01-15', '2024-01-20'], true, false) // Returns '2024-01-15,2024-01-20'
345
- */
346
- processDateSelection(e, t, a) {
347
- return !t && !a ? e[0] || "" : Array.isArray(e) ? e.join(",") : e;
348
- },
349
- /**
350
- * Updates input values after calendar selection
351
- *
352
- * Synchronizes input element values with the calendar's selected dates.
353
- * Handles single, range, and multiple date scenarios differently.
354
- *
355
- * - Single: Updates single input with first date
356
- * - Range: Updates two inputs with start and end dates
357
- * - Multiple: Does nothing (dates shown as tags, not in input)
358
- *
359
- * @param inputRef - Lit ref to the primary input element
360
- * @param inputRefTo - Lit ref to the secondary input (for range) or null
361
- * @param values - Array of selected date strings
362
- * @param range - Whether this is a range date picker
363
- * @param multiple - Whether this is a multiple date picker
364
- * @param manageValidity - Callback to validate the input
365
- *
366
- * @example
367
- * updateInputValues(
368
- * this.inputRef,
369
- * this.inputRefTo,
370
- * ['2024-01-15', '2024-01-20'],
371
- * true, // range
372
- * false,
373
- * (input) => this.dispatchManageValidity(input)
374
- * )
375
- */
376
- updateInputValues(e, t, a, s, i, n) {
377
- e.value && (s && (t != null && t.value) ? (e.value.value = a[0] ?? "", t.value.value = a[1] ?? "", n(e.value), n(t.value)) : i || (e.value.value = a.length ? a[0] : "", n(e.value)));
378
- },
379
- /**
380
- * Processes blur events for range inputs
381
- *
382
- * Handles the logic when a range input loses focus:
383
- * - If input has value: validates it and updates the calendar to reflect the typed date
384
- * - If input is empty but range has start date: clears the entire range
385
- *
386
- * This ensures the range picker calendar stays synchronized when users type dates directly.
387
- *
388
- * @param event - The blur event from the input
389
- * @param values - Current array of selected dates [start, end]
390
- * @param calendarRef - Lit ref to the calendar component
391
- * @param clearInputValue - Callback to clear the date selection
392
- * @param manageValidity - Callback to validate the input
393
- *
394
- * @example
395
- * processRangeBlur(
396
- * blurEvent,
397
- * ['2024-01-15', '2024-01-20'],
398
- * this.calendarRef,
399
- * () => this.value = [],
400
- * (input) => this.dispatchManageValidity(input)
401
- * )
402
- */
403
- processRangeBlur(e, t, a, s, i) {
404
- var r;
405
- const n = e.target;
406
- if (n.value) {
407
- i(n);
408
- const h = F(n.value);
409
- h && ((r = a == null ? void 0 : a.value) == null || r.handleDateSelect(h));
410
- } else t[0] && s();
411
- }
412
- }, I = {
413
- /**
414
- * Handles common keyboard interactions for datepicker inputs
415
- *
416
- * Provides consistent keyboard navigation across all datepicker types:
417
- * - Space: Opens calendar
418
- * - Enter: Submits form, focuses next input, or blurs (priority order)
419
- * - Comma: Adds date to selection (multiple) or blurs input
420
- *
421
- * The handler prioritizes callbacks in the order provided, allowing
422
- * different behaviors for single, multiple, and range pickers.
423
- *
424
- * @param event - The keyboard event
425
- * @param toggleCalendar - Callback to toggle calendar visibility
426
- * @param submitForm - Optional callback to submit the form (highest priority on Enter)
427
- * @param focusNextInput - Optional callback to focus next input (medium priority on Enter)
428
- * @param blurInput - Optional callback to blur current input (lowest priority on Enter/Comma)
429
- * @param commaHandler - Optional callback for comma key (overrides default blur behavior)
430
- *
431
- * @example
432
- * // Single datepicker: Enter submits form or blurs
433
- * handleInputKeydown(
434
- * event,
435
- * (e) => this.toggleCalendar(e),
436
- * () => formUtils.submitFormOrFallback(this.internals, () => this.inputRef.value?.blur()),
437
- * undefined,
438
- * () => this.inputRef.value?.blur()
439
- * )
440
- *
441
- * @example
442
- * // Range datepicker: Enter moves to next input
443
- * handleInputKeydown(
444
- * event,
445
- * (e) => this.toggleCalendar(e),
446
- * () => formUtils.submitFormOrFallback(this.internals, () => this.inputRefTo.value?.focus()),
447
- * () => this.inputRefTo.value?.focus(),
448
- * () => this.inputRef.value?.blur()
449
- * )
450
- */
451
- handleInputKeydown(e, t, a, s, i, n) {
452
- const { key: r } = e;
453
- r === "," && (e.preventDefault(), n ? n(e) : i && i()), (r === "Space" || r === " ") && (e.preventDefault(), t(e)), r === "Enter" && (e.preventDefault(), a ? a() : s ? s() : i && i());
454
- },
455
- /**
456
- * Handles keyboard interactions for calendar button
457
- *
458
- * Ensures the calendar button is keyboard accessible by responding
459
- * to Enter and Space keys (standard button activation keys).
460
- *
461
- * @param event - The keyboard event
462
- * @param toggleCalendar - Callback to toggle calendar visibility
463
- *
464
- * @example
465
- * handleButtonKeydown(
466
- * event,
467
- * (e) => this.dispatchToggleCalendar(e)
468
- * )
469
- */
470
- handleButtonKeydown(e, t) {
471
- const { key: a } = e;
472
- (a === "Enter" || a === " " || a === "Space") && (e.preventDefault(), t(e));
473
- }
474
- };
475
- var ue = Object.defineProperty, oe = Object.getOwnPropertyDescriptor, c = (e, t, a, s) => {
476
- for (var i = s > 1 ? void 0 : s ? oe(t, a) : t, n = e.length - 1, r; n >= 0; n--)
477
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
478
- return s && i && ue(t, a, i), i;
479
- };
480
- let d = class extends L {
481
- constructor() {
482
- super(...arguments), this.open = !1, this.multiple = !1, this.range = !1, this.weeknumbers = !1, this.withcontrols = !1, this.maxMultiple = null, this.selected = [], this.earliest = null, this.latest = null, this.excludedates = [], this.excludeweekdays = [], this.currentmonth = null, this.popupRef = g(), this.calendarRef = g(), this.handleDocumentClick = (e) => {
483
- if (!this.open) return;
484
- const t = e.composedPath(), a = this.parentElement, s = this.popupRef.value;
485
- !t.includes(this) && !t.includes(s) && !(a && t.includes(a)) && (this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 })));
486
- }, this.handleDocumentKeydown = (e) => {
487
- this.open && e.key === "Escape" && (this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 })));
488
- };
489
- }
490
- firstUpdated() {
491
- this.calRef = this.calendarRef, document.addEventListener("keydown", this.handleDocumentKeydown), document.addEventListener("click", this.handleDocumentClick);
492
- }
493
- disconnectedCallback() {
494
- super.disconnectedCallback(), document.removeEventListener("click", this.handleDocumentClick), document.removeEventListener("keydown", this.handleDocumentKeydown);
495
- }
496
- show() {
497
- var e;
498
- this.open = !0, (e = this.calendarRef.value) == null || e.focus();
499
- }
500
- hide() {
501
- this.open = !1;
502
- }
503
- toggle() {
504
- this.open ? this.hide() : this.show();
505
- }
506
- contains(e) {
507
- var t;
508
- return !!e && !!((t = this.popupRef.value) != null && t.contains(e));
509
- }
510
- focusOnCurrentDate() {
511
- const e = this.calendarRef.value;
512
- e && typeof e.focusOnCurrentDate == "function" && e.focusOnCurrentDate();
513
- }
514
- addToSelected(e, t, a) {
515
- if (typeof P.addToSelected == "function")
516
- return P.addToSelected(e, this.calendarRef, t, a);
517
- }
518
- handleDateSelect(e) {
519
- const t = this.calendarRef.value;
520
- if (t && typeof t.handleDateSelect == "function") return t.handleDateSelect(e);
521
- }
522
- render() {
523
- const e = { "pkt-calendar-popup": !0, show: this.open, hide: !this.open };
524
- return o`
525
- <div
526
- class="${$(e)}"
527
- ${v(this.popupRef)}
528
- id="date-popup"
529
- ?hidden=${!this.open}
530
- aria-hidden="${!this.open}"
531
- >
532
- <pkt-calendar
533
- ${v(this.calendarRef)}
534
- ?multiple=${this.multiple}
535
- ?range=${this.range}
536
- ?weeknumbers=${this.weeknumbers}
537
- ?withcontrols=${this.withcontrols}
538
- .maxMultiple=${this.maxMultiple}
539
- .selected=${this.selected}
540
- .earliest=${this.earliest}
541
- .latest=${this.latest}
542
- .excludedates=${this.excludedates}
543
- .excludeweekdays=${this.excludeweekdays}
544
- .currentmonth=${this.currentmonth}
545
- @date-selected=${(t) => {
546
- this.selected = t.detail, this.dispatchEvent(
547
- new CustomEvent("date-selected", { detail: t.detail, bubbles: !0, composed: !0 })
548
- );
549
- }}
550
- @close=${() => {
551
- this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 }));
552
- }}
553
- ></pkt-calendar>
554
- </div>
555
- `;
556
- }
557
- };
558
- c([
559
- l({ type: Boolean, reflect: !0 })
560
- ], d.prototype, "open", 2);
561
- c([
562
- l({ type: Boolean })
563
- ], d.prototype, "multiple", 2);
564
- c([
565
- l({ type: Boolean })
566
- ], d.prototype, "range", 2);
567
- c([
568
- l({ type: Boolean })
569
- ], d.prototype, "weeknumbers", 2);
570
- c([
571
- l({ type: Boolean })
572
- ], d.prototype, "withcontrols", 2);
573
- c([
574
- l({ type: Number })
575
- ], d.prototype, "maxMultiple", 2);
576
- c([
577
- l({ type: Array })
578
- ], d.prototype, "selected", 2);
579
- c([
580
- l({ type: String })
581
- ], d.prototype, "earliest", 2);
582
- c([
583
- l({ type: String })
584
- ], d.prototype, "latest", 2);
585
- c([
586
- l({ type: Array })
587
- ], d.prototype, "excludedates", 2);
588
- c([
589
- l({ type: Array })
590
- ], d.prototype, "excludeweekdays", 2);
591
- c([
592
- l({ type: String })
593
- ], d.prototype, "currentmonth", 2);
594
- d = c([
595
- w("pkt-datepicker-popup")
596
- ], d);
597
- var he = Object.defineProperty, y = (e, t, a, s) => {
598
- for (var i = void 0, n = e.length - 1, r; n >= 0; n--)
599
- (r = e[n]) && (i = r(t, a, i) || i);
600
- return i && he(t, a, i), i;
601
- };
602
- class m extends L {
603
- constructor() {
604
- super(...arguments), this.inputType = "date", this.id = "", this.readonly = !1, this.disabled = !1, this.inputClasses = {}, this.inputRef = g(), this.btnRef = g();
605
- }
606
- // Shared getters
607
- get inputElement() {
608
- return this.inputRef.value;
609
- }
610
- get buttonElement() {
611
- return this.btnRef.value;
612
- }
613
- get isInputReadonly() {
614
- return this.readonly || this.inputType === "text";
615
- }
616
- // Shared event dispatchers (protected so subclasses can use them)
617
- dispatchToggleCalendar(t) {
618
- this.readonly || this.dispatchEvent(
619
- new CustomEvent("toggle-calendar", {
620
- detail: t,
621
- bubbles: !0,
622
- composed: !0
623
- })
624
- );
625
- }
626
- dispatchInput(t) {
627
- this.dispatchEvent(
628
- new CustomEvent("input-change", {
629
- detail: t,
630
- bubbles: !0,
631
- composed: !0
632
- })
633
- );
634
- }
635
- dispatchFocus() {
636
- this.dispatchEvent(
637
- new CustomEvent("input-focus", {
638
- bubbles: !0,
639
- composed: !0
640
- })
641
- );
642
- }
643
- dispatchBlur(t) {
644
- this.dispatchEvent(
645
- new CustomEvent("input-blur", {
646
- detail: t,
647
- bubbles: !0,
648
- composed: !0
649
- })
650
- );
651
- }
652
- dispatchChange(t) {
653
- this.dispatchEvent(
654
- new CustomEvent("input-changed", {
655
- detail: t,
656
- bubbles: !0,
657
- composed: !0
658
- })
659
- );
660
- }
661
- // Shared render helper for calendar button
662
- renderCalendarButton() {
663
- var t;
664
- return o`
665
- <button
666
- class="${$(V.getButtonClasses())}"
667
- type="button"
668
- @click=${(a) => this.dispatchToggleCalendar(a)}
669
- @keydown=${(a) => {
670
- const { key: s } = a;
671
- (s === "Enter" || s === " " || s === "Space") && (a.preventDefault(), this.dispatchToggleCalendar(a));
672
- }}
673
- ?disabled=${this.disabled}
674
- ${this.btnRef}
675
- >
676
- <pkt-icon name="calendar"></pkt-icon>
677
- <span class="pkt-btn__text">${((t = this.strings.calendar) == null ? void 0 : t.buttonAltText) || "Åpne kalender"}</span>
678
- </button>
679
- `;
680
- }
681
- // Shared method - no shadow DOM
682
- createRenderRoot() {
683
- return this;
684
- }
685
- }
686
- y([
687
- l({ type: String })
688
- ], m.prototype, "inputType");
689
- y([
690
- l({ type: String })
691
- ], m.prototype, "id");
692
- y([
693
- l({ type: String })
694
- ], m.prototype, "min");
695
- y([
696
- l({ type: String })
697
- ], m.prototype, "max");
698
- y([
699
- l({ type: String })
700
- ], m.prototype, "placeholder");
701
- y([
702
- l({ type: Boolean })
703
- ], m.prototype, "readonly");
704
- y([
705
- l({ type: Boolean })
706
- ], m.prototype, "disabled");
707
- y([
708
- l({ type: Object })
709
- ], m.prototype, "inputClasses");
710
- y([
711
- l({ type: Object })
712
- ], m.prototype, "internals");
713
- const W = {
714
- calendar: { buttonAltText: "Åpne kalender" }
715
- }, de = {
716
- calendar: { buttonAltText: "Åpne kalender" },
717
- generic: { from: "Fra", to: "Til" }
718
- };
719
- var ce = Object.defineProperty, ge = Object.getOwnPropertyDescriptor, M = (e, t, a, s) => {
720
- for (var i = s > 1 ? void 0 : s ? ge(t, a) : t, n = e.length - 1, r; n >= 0; n--)
721
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
722
- return s && i && ce(t, a, i), i;
723
- };
724
- let S = class extends m {
725
- constructor() {
726
- super(...arguments), this.value = "", this.strings = W;
727
- }
728
- dispatchManageValidity(e) {
729
- this.dispatchEvent(
730
- new CustomEvent("manage-validity", {
731
- detail: e,
732
- bubbles: !0,
733
- composed: !0
734
- })
735
- );
736
- }
737
- render() {
738
- return o`
739
- <div class="pkt-input__container">
740
- <input
741
- class="${$(this.inputClasses)}"
742
- .type=${this.inputType}
743
- id="${this.id}-input"
744
- .value=${this.value}
745
- min=${f(this.min)}
746
- max=${f(this.max)}
747
- placeholder=${f(this.placeholder)}
748
- ?readonly=${this.isInputReadonly}
749
- aria-describedby="${this.id}-helptext"
750
- @click=${(e) => {
751
- e.preventDefault(), this.dispatchToggleCalendar(e);
752
- }}
753
- @touchend=${(e) => {
754
- e.preventDefault(), this.dispatchToggleCalendar(e);
755
- }}
756
- ?disabled=${this.disabled}
757
- @keydown=${(e) => I.handleInputKeydown(
758
- e,
759
- (t) => this.dispatchToggleCalendar(t),
760
- () => x.submitFormOrFallback(this.internals, () => {
761
- var t;
762
- return (t = this.inputRef.value) == null ? void 0 : t.blur();
763
- }),
764
- void 0,
765
- () => {
766
- var t;
767
- return (t = this.inputRef.value) == null ? void 0 : t.blur();
768
- }
769
- )}
770
- @input=${(e) => {
771
- this.dispatchInput(e), e.stopImmediatePropagation();
772
- }}
773
- @focus=${() => {
774
- this.dispatchFocus(), b() && this.dispatchToggleCalendar(new Event("focus"));
775
- }}
776
- @blur=${(e) => {
777
- this.dispatchBlur(e), this.dispatchManageValidity(e.target), this.dispatchEvent(
778
- new CustomEvent("value-change", {
779
- detail: e.target.value,
780
- bubbles: !0,
781
- composed: !0
782
- })
783
- );
784
- }}
785
- @change=${(e) => {
786
- this.dispatchChange(e), e.stopImmediatePropagation();
787
- }}
788
- ${v(this.inputRef)}
789
- />
790
- ${this.renderCalendarButton()}
791
- </div>
792
- `;
793
- }
794
- };
795
- M([
796
- l({ type: String })
797
- ], S.prototype, "value", 2);
798
- M([
799
- l({ type: Object })
800
- ], S.prototype, "strings", 2);
801
- S = M([
802
- w("pkt-datepicker-single")
803
- ], S);
804
- var fe = Object.defineProperty, me = Object.getOwnPropertyDescriptor, O = (e, t, a, s) => {
805
- for (var i = s > 1 ? void 0 : s ? me(t, a) : t, n = e.length - 1, r; n >= 0; n--)
806
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
807
- return s && i && fe(t, a, i), i;
808
- };
809
- let _ = class extends m {
810
- constructor() {
811
- super(...arguments), this.value = [], this.showRangeLabels = !1, this.strings = de, this.inputRefTo = g();
812
- }
813
- get inputElementTo() {
814
- return this.inputRefTo.value;
815
- }
816
- render() {
817
- var t, a;
818
- const e = V.getRangeLabelClasses(this.showRangeLabels);
819
- return o`
820
- <div class="pkt-input__container">
821
- ${this.showRangeLabels ? o` <div class="pkt-input-prefix">${(t = this.strings.generic) == null ? void 0 : t.from}</div> ` : E}
822
- <input
823
- class=${$(this.inputClasses)}
824
- .type=${this.inputType}
825
- id="${this.id}-input"
826
- .value=${this.value[0] ?? ""}
827
- min=${f(this.min)}
828
- max=${f(this.max)}
829
- placeholder=${f(this.placeholder)}
830
- ?readonly=${this.isInputReadonly}
831
- ?disabled=${this.disabled}
832
- @click=${(s) => {
833
- s.preventDefault(), this.dispatchToggleCalendar(s);
834
- }}
835
- @touchend=${(s) => {
836
- s.preventDefault(), this.dispatchToggleCalendar(s);
837
- }}
838
- @keydown=${(s) => I.handleInputKeydown(
839
- s,
840
- (i) => this.dispatchToggleCalendar(i),
841
- () => x.submitFormOrFallback(
842
- this.internals,
843
- () => {
844
- var i;
845
- return (i = this.inputRefTo.value) == null ? void 0 : i.focus();
846
- }
847
- ),
848
- () => {
849
- var i;
850
- return (i = this.inputRefTo.value) == null ? void 0 : i.focus();
851
- },
852
- () => {
853
- var i;
854
- return (i = this.inputRef.value) == null ? void 0 : i.blur();
855
- }
856
- )}
857
- @input=${(s) => {
858
- this.dispatchInput(s), s.stopImmediatePropagation();
859
- }}
860
- @focus=${() => {
861
- this.dispatchFocus(), b() && this.dispatchToggleCalendar(new Event("focus"));
862
- }}
863
- @blur=${(s) => {
864
- this.dispatchBlur(s), this.dispatchEvent(
865
- new CustomEvent("range-blur", {
866
- detail: {
867
- event: s,
868
- values: this.value,
869
- inputType: "from"
870
- },
871
- bubbles: !0,
872
- composed: !0
873
- })
874
- );
875
- }}
876
- @change=${(s) => {
877
- this.dispatchChange(s), s.stopImmediatePropagation();
878
- }}
879
- ${v(this.inputRef)}
880
- />
881
- <div class="${$(e)}" id="${this.id}-to-label">
882
- ${(a = this.strings.generic) == null ? void 0 : a.to}
883
- </div>
884
- ${this.showRangeLabels ? E : o` <div class="pkt-input-separator">–</div> `}
885
- <input
886
- class=${$(this.inputClasses)}
887
- .type=${this.inputType}
888
- id="${this.id}-to"
889
- aria-labelledby="${this.id}-to-label"
890
- .value=${this.value[1] ?? ""}
891
- min=${f(this.min)}
892
- max=${f(this.max)}
893
- placeholder=${f(this.placeholder)}
894
- ?readonly=${this.isInputReadonly}
895
- ?disabled=${this.disabled}
896
- @click=${(s) => {
897
- s.preventDefault(), this.dispatchToggleCalendar(s);
898
- }}
899
- @touchend=${(s) => {
900
- s.preventDefault(), this.dispatchToggleCalendar(s);
901
- }}
902
- @keydown=${(s) => I.handleInputKeydown(
903
- s,
904
- (i) => this.dispatchToggleCalendar(i),
905
- () => x.submitFormOrFallback(this.internals, () => {
906
- var i;
907
- return (i = this.inputRefTo.value) == null ? void 0 : i.blur();
908
- }),
909
- void 0,
910
- () => {
911
- var i;
912
- return (i = this.inputRefTo.value) == null ? void 0 : i.blur();
913
- }
914
- )}
915
- @input=${(s) => {
916
- this.dispatchInput(s), s.stopImmediatePropagation();
917
- }}
918
- @focus=${() => {
919
- this.dispatchFocus(), b() && this.dispatchToggleCalendar(new Event("focus"));
920
- }}
921
- @blur=${(s) => {
922
- this.dispatchBlur(s), this.dispatchEvent(
923
- new CustomEvent("range-blur", {
924
- detail: {
925
- event: s,
926
- values: this.value,
927
- inputType: "to"
928
- },
929
- bubbles: !0,
930
- composed: !0
931
- })
932
- );
933
- }}
934
- @change=${(s) => {
935
- this.dispatchChange(s), s.stopImmediatePropagation();
936
- }}
937
- ${v(this.inputRefTo)}
938
- />
939
- ${this.renderCalendarButton()}
940
- </div>
941
- `;
942
- }
943
- };
944
- O([
945
- l({ type: Array })
946
- ], _.prototype, "value", 2);
947
- O([
948
- l({ type: Boolean })
949
- ], _.prototype, "showRangeLabels", 2);
950
- O([
951
- l({ type: Object })
952
- ], _.prototype, "strings", 2);
953
- _ = O([
954
- w("pkt-datepicker-range")
955
- ], _);
956
- var ve = Object.defineProperty, ye = Object.getOwnPropertyDescriptor, B = (e, t, a, s) => {
957
- for (var i = s > 1 ? void 0 : s ? ye(t, a) : t, n = e.length - 1, r; n >= 0; n--)
958
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
959
- return s && i && ve(t, a, i), i;
960
- };
961
- let T = class extends m {
962
- constructor() {
963
- super(...arguments), this.value = [], this.strings = W;
964
- }
965
- get isInputDisabled() {
966
- return this.disabled || this.maxlength !== void 0 && this.maxlength !== null && this.value.length >= this.maxlength;
967
- }
968
- dispatchAddToSelected(e) {
969
- this.dispatchEvent(
970
- new CustomEvent("add-to-selected", {
971
- detail: e,
972
- bubbles: !0,
973
- composed: !0
974
- })
975
- );
976
- }
977
- render() {
978
- return o`
979
- <div class="pkt-input__container">
980
- <input
981
- class=${$(this.inputClasses)}
982
- .type=${this.inputType}
983
- id="${this.id}-input"
984
- min=${f(this.min)}
985
- max=${f(this.max)}
986
- placeholder=${f(this.placeholder)}
987
- ?readonly=${this.isInputReadonly}
988
- ?disabled=${this.isInputDisabled}
989
- @click=${(e) => {
990
- e.preventDefault(), this.dispatchToggleCalendar(e);
991
- }}
992
- @touchend=${(e) => {
993
- e.preventDefault(), this.dispatchToggleCalendar(e);
994
- }}
995
- @blur=${(e) => {
996
- this.dispatchBlur(e), this.dispatchAddToSelected(e);
997
- }}
998
- @input=${(e) => {
999
- this.dispatchInput(e), e.stopImmediatePropagation();
1000
- }}
1001
- @focus=${() => {
1002
- this.dispatchFocus(), b() && this.dispatchToggleCalendar(new Event("focus"));
1003
- }}
1004
- @keydown=${(e) => I.handleInputKeydown(
1005
- e,
1006
- (t) => this.dispatchToggleCalendar(t),
1007
- () => x.submitFormOrFallback(this.internals, () => {
1008
- var t;
1009
- return (t = this.inputRef.value) == null ? void 0 : t.blur();
1010
- }),
1011
- void 0,
1012
- void 0,
1013
- (t) => this.dispatchAddToSelected(t)
1014
- )}
1015
- @change=${(e) => {
1016
- this.dispatchChange(e), e.stopImmediatePropagation();
1017
- }}
1018
- ${v(this.inputRef)}
1019
- />
1020
- ${this.renderCalendarButton()}
1021
- </div>
1022
- `;
1023
- }
1024
- };
1025
- B([
1026
- l({ type: Array })
1027
- ], T.prototype, "value", 2);
1028
- B([
1029
- l({ type: Number })
1030
- ], T.prototype, "maxlength", 2);
1031
- B([
1032
- l({ type: Object })
1033
- ], T.prototype, "strings", 2);
1034
- T = B([
1035
- w("pkt-datepicker-multiple")
1036
- ], T);
1037
- var $e = Object.defineProperty, be = Object.getOwnPropertyDescriptor, u = (e, t, a, s) => {
1038
- for (var i = s > 1 ? void 0 : s ? be(t, a) : t, n = e.length - 1, r; n >= 0; n--)
1039
- (r = e[n]) && (i = (s ? r(t, a, i) : r(i)) || i);
1040
- return s && i && $e(t, a, i), i;
1041
- };
1042
- let p = class extends ee {
1043
- /**
1044
- * Housekeeping / lifecycle methods
1045
- */
1046
- constructor() {
1047
- super(), this._valueProperty = "", this.datepickerPopupRef = g(), this._value = [], this.label = "Datovelger", this.dateformat = C.props.dateformat.default, this.multiple = C.props.multiple.default, this.maxlength = null, this.range = C.props.range.default, this.showRangeLabels = !1, this.min = null, this.max = null, this.weeknumbers = C.props.weeknumbers.default, this.withcontrols = C.props.withcontrols.default, this.excludedates = [], this.excludeweekdays = [], this.currentmonth = null, this.calendarOpen = !1, this.timezone = "Europe/Oslo", this.inputClasses = {}, this.calRef = g(), this.popupRef = g(), this.helptextSlot = g(), this.singleInputRef = g(), this.rangeInputRef = g(), this.multipleInputRef = g(), this.addToSelected = (e) => {
1048
- const t = this.datepickerPopupRef.value;
1049
- return t && typeof t.addToSelected == "function" ? t.addToSelected(e, this.min, this.max) : P.addToSelected(e, this.calRef, this.min, this.max);
1050
- }, this.slotController = new ae(this, this.helptextSlot);
1051
- }
1052
- get value() {
1053
- return this._valueProperty;
1054
- }
1055
- set value(e) {
1056
- const t = this._valueProperty;
1057
- this._valueProperty = Array.isArray(e) ? e.join(",") : e || "", this.valueChanged(this._valueProperty, t), this.requestUpdate("value", t);
1058
- }
1059
- /**
1060
- * Computed properties
1061
- */
1062
- get inputType() {
1063
- return pe.getInputType();
1064
- }
1065
- connectedCallback() {
1066
- super.connectedCallback(), this.timezone && this.timezone !== window.pktTz && (window.pktTz = this.timezone);
1067
- }
1068
- disconnectedCallback() {
1069
- super.disconnectedCallback();
1070
- }
1071
- onInput() {
1072
- this.dispatchEvent(new Event("input", { bubbles: !0 }));
1073
- }
1074
- valueChanged(e, t) {
1075
- if (e === t) return;
1076
- const a = D(e), s = this.multiple && a.length > 1 ? N.filterSelectableDates(
1077
- a,
1078
- this.min,
1079
- this.max,
1080
- this.excludedates,
1081
- this.excludeweekdays
1082
- ) : a;
1083
- if (this.range && !N.validateRangeOrder(s)) {
1084
- this._value = [], this._valueProperty = "", super.valueChanged("", t);
1085
- return;
1086
- }
1087
- this._value = s;
1088
- const i = X(s);
1089
- this._valueProperty !== i && (this._valueProperty = i), super.valueChanged(i, t);
1090
- }
1091
- attributeChangedCallback(e, t, a) {
1092
- e === "value" && this.value !== t && this.valueChanged(a, t), e === "excludedates" && typeof this.excludedates == "string" && (this.excludedates = D(a || "")), e === "excludeweekdays" && typeof this.excludeweekdays == "string" && (this.excludeweekdays = D(a || "")), super.attributeChangedCallback(e, t, a);
1093
- }
1094
- updated(e) {
1095
- if (e.has("value")) {
1096
- const t = Array.isArray(this.value) ? this.value.join(",") : this.value, a = e.get("value"), s = Array.isArray(a) ? a.join(",") : a;
1097
- this.valueChanged(t, s);
1098
- }
1099
- e.has("multiple") && (this.multiple && !Array.isArray(this._value) ? this._value = D(this.value) : !this.multiple && Array.isArray(this._value) && (this._value = this._value.filter(Boolean)), !this.multiple && !this.range && Array.isArray(this._value) && (this._value = [this._value[0] ?? ""])), super.updated(e);
1100
- }
1101
- /**
1102
- * Element references
1103
- */
1104
- // Override the inputRef and inputRefTo for compatibility
1105
- get inputRef() {
1106
- return { value: this.currentInputElement };
1107
- }
1108
- get inputRefTo() {
1109
- return { value: this.currentInputElementTo };
1110
- }
1111
- // Getters for backward compatibility with input refs
1112
- get currentInputElement() {
1113
- var e, t, a;
1114
- return this.multiple ? (e = this.multipleInputRef.value) == null ? void 0 : e.inputElement : this.range ? (t = this.rangeInputRef.value) == null ? void 0 : t.inputElement : (a = this.singleInputRef.value) == null ? void 0 : a.inputElement;
1115
- }
1116
- get currentInputElementTo() {
1117
- var e;
1118
- if (this.range)
1119
- return (e = this.rangeInputRef.value) == null ? void 0 : e.inputElementTo;
1120
- }
1121
- get currentButtonElement() {
1122
- var e, t, a;
1123
- return this.multiple ? (e = this.multipleInputRef.value) == null ? void 0 : e.buttonElement : this.range ? (t = this.rangeInputRef.value) == null ? void 0 : t.buttonElement : (a = this.singleInputRef.value) == null ? void 0 : a.buttonElement;
1124
- }
1125
- // Override btnRef for compatibility
1126
- get btnRef() {
1127
- return { value: this.currentButtonElement };
1128
- }
1129
- /**
1130
- * Rendering
1131
- */
1132
- renderInput() {
1133
- return o`
1134
- <pkt-datepicker-single
1135
- .value=${this._value[0] ?? ""}
1136
- .inputType=${this.inputType}
1137
- .id=${this.id}
1138
- .min=${this.min}
1139
- .max=${this.max}
1140
- .placeholder=${this.placeholder}
1141
- .readonly=${this.readonly}
1142
- .disabled=${this.disabled}
1143
- .inputClasses=${this.inputClasses}
1144
- .internals=${this.internals}
1145
- .strings=${this.strings}
1146
- @toggle-calendar=${(e) => this.toggleCalendar(e.detail)}
1147
- @input-change=${() => this.onInput()}
1148
- @input-focus=${() => this.onFocus()}
1149
- @input-blur=${(e) => {
1150
- var t;
1151
- (t = this.calRef.value) != null && t.contains(e.detail.relatedTarget) || this.onBlur();
1152
- }}
1153
- @manage-validity=${(e) => this.manageValidity(e.detail)}
1154
- @value-change=${(e) => {
1155
- this.value = e.detail;
1156
- }}
1157
- @input-changed=${() => {
1158
- this.touched = !0;
1159
- }}
1160
- ${v(this.singleInputRef)}
1161
- ></pkt-datepicker-single>
1162
- `;
1163
- }
1164
- renderRangeInput() {
1165
- return o`
1166
- <pkt-datepicker-range
1167
- .value=${this._value}
1168
- .inputType=${this.inputType}
1169
- .id=${this.id}
1170
- .min=${this.min}
1171
- .max=${this.max}
1172
- .placeholder=${this.placeholder}
1173
- .readonly=${this.readonly}
1174
- .disabled=${this.disabled}
1175
- .showRangeLabels=${this.showRangeLabels}
1176
- .inputClasses=${this.inputClasses}
1177
- .internals=${this.internals}
1178
- .strings=${this.strings}
1179
- @toggle-calendar=${(e) => this.toggleCalendar(e.detail)}
1180
- @input-change=${() => this.onInput()}
1181
- @input-focus=${() => this.onFocus()}
1182
- @input-blur=${(e) => {
1183
- var t;
1184
- (t = this.calRef.value) != null && t.contains(e.detail.relatedTarget) || this.onBlur();
1185
- }}
1186
- @range-blur=${(e) => {
1187
- const t = this.currentInputElement, a = this.currentInputElementTo;
1188
- if (t && a) {
1189
- const s = t.value, i = a.value;
1190
- if (s && i && s > i)
1191
- a.value = "", this._value = [s], this.value = s;
1192
- else {
1193
- const n = [s, i].filter(Boolean);
1194
- n.length > 0 && (n[0] !== this._value[0] || n[1] !== this._value[1]) && (this._value = n, this.value = n.join(","));
1195
- }
1196
- }
1197
- j.processRangeBlur(
1198
- e.detail.event,
1199
- e.detail.values,
1200
- this.calRef,
1201
- () => this.clearInputValue(),
1202
- (s) => this.manageValidity(s)
1203
- );
1204
- }}
1205
- @manage-validity=${(e) => this.manageValidity(e.detail)}
1206
- @validate-date-input=${(e) => {
1207
- x.validateDateInput(e.detail, this.internals, this.min, this.max, this.strings);
1208
- }}
1209
- @handle-date-select=${(e) => {
1210
- var a, s;
1211
- const t = F(e.detail);
1212
- if (t) {
1213
- const i = Y(t);
1214
- this._value[0] !== i && this._value[1] !== i && ((s = (a = this.calRef) == null ? void 0 : a.value) == null || s.handleDateSelect(t));
1215
- }
1216
- }}
1217
- @input-changed=${() => {
1218
- this.touched = !0;
1219
- }}
1220
- ${v(this.rangeInputRef)}
1221
- ></pkt-datepicker-range>
1222
- `;
1223
- }
1224
- renderMultipleInput() {
1225
- return o`
1226
- <pkt-datepicker-multiple
1227
- .value=${this._value}
1228
- .inputType=${this.inputType}
1229
- .id=${this.id}
1230
- .min=${this.min}
1231
- .max=${this.max}
1232
- .placeholder=${this.placeholder}
1233
- .readonly=${this.readonly}
1234
- .disabled=${this.disabled}
1235
- .maxlength=${this.maxlength}
1236
- .inputClasses=${this.inputClasses}
1237
- .internals=${this.internals}
1238
- .strings=${this.strings}
1239
- @toggle-calendar=${(e) => this.toggleCalendar(e.detail)}
1240
- @input-change=${() => this.onInput()}
1241
- @input-focus=${() => this.onFocus()}
1242
- @input-blur=${(e) => {
1243
- var t;
1244
- (t = this.calRef.value) != null && t.contains(e.detail.relatedTarget) || this.onBlur();
1245
- }}
1246
- @add-to-selected=${(e) => this.addToSelected(e.detail)}
1247
- @input-changed=${() => {
1248
- this.touched = !0;
1249
- }}
1250
- ${v(this.multipleInputRef)}
1251
- ></pkt-datepicker-multiple>
1252
- `;
1253
- }
1254
- renderCalendar() {
1255
- return o`
1256
- <pkt-datepicker-popup
1257
- class="pkt-contents"
1258
- ?open=${this.calendarOpen}
1259
- ?multiple=${this.multiple}
1260
- ?range=${this.range}
1261
- ?weeknumbers=${this.weeknumbers}
1262
- ?withcontrols=${this.withcontrols}
1263
- .maxMultiple=${this.maxlength}
1264
- .selected=${this._value}
1265
- .earliest=${this.min}
1266
- .latest=${this.max}
1267
- .excludedates=${Array.isArray(this.excludedates) ? this.excludedates : this.excludedates.split(",")}
1268
- .excludeweekdays=${this.excludeweekdays}
1269
- .currentmonth=${this.currentmonth ? Z(this.currentmonth) : null}
1270
- @date-selected=${(e) => {
1271
- this.value = j.processDateSelection(e.detail, this.multiple, this.range), this._value = e.detail, j.updateInputValues(
1272
- this.inputRef,
1273
- this.inputRefTo,
1274
- this._value,
1275
- this.range,
1276
- this.multiple,
1277
- (t) => this.manageValidity(t)
1278
- );
1279
- }}
1280
- @close=${() => {
1281
- this.onBlur(), this.hideCalendar();
1282
- }}
1283
- ${v(this.datepickerPopupRef)}
1284
- ></pkt-datepicker-popup>
1285
- `;
1286
- }
1287
- render() {
1288
- return this.inputClasses = V.getInputClasses(
1289
- this.fullwidth,
1290
- this.showRangeLabels,
1291
- this.multiple,
1292
- this.range,
1293
- this.readonly,
1294
- this.inputType
1295
- ), o`
1296
- <pkt-input-wrapper
1297
- label="${this.label}"
1298
- forId="${this.id}-input"
1299
- ?counter=${this.multiple && !!this.maxlength}
1300
- .counterCurrent=${this.value ? this._value.length : 0}
1301
- .counterMaxLength=${this.maxlength}
1302
- ?disabled=${this.disabled}
1303
- ?hasError=${this.hasError}
1304
- ?hasFieldset=${this.hasFieldset}
1305
- ?inline=${this.inline}
1306
- ?required=${this.required}
1307
- ?optionalTag=${this.optionalTag}
1308
- ?requiredTag=${this.requiredTag}
1309
- useWrapper=${this.useWrapper}
1310
- .optionalText=${this.optionalText}
1311
- .requiredText=${this.requiredText}
1312
- .tagText=${this.tagText}
1313
- .errorMessage=${this.errorMessage}
1314
- .helptext=${this.helptext}
1315
- .helptextDropdown=${this.helptextDropdown}
1316
- .helptextDropdownButton=${this.helptextDropdownButton}
1317
- .ariaDescribedBy=${this.ariaDescribedBy}
1318
- class="pkt-datepicker"
1319
- >
1320
- <div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
1321
- ${this.multiple ? o`<pkt-date-tags
1322
- .dates=${this._value}
1323
- dateformat=${this.dateformat}
1324
- strings=${this.strings}
1325
- id-base=${this.id}
1326
- @date-tag-removed=${(e) => {
1327
- var s;
1328
- const t = this.datepickerPopupRef.value, a = F(e.detail);
1329
- t && a && typeof t.handleDateSelect == "function" ? t.handleDateSelect(a) : (s = this.calRef.value) == null || s.handleDateSelect(a);
1330
- }}
1331
- ></pkt-date-tags>` : E}
1332
- <div
1333
- class="pkt-datepicker__inputs ${this.range && this.showRangeLabels ? "pkt-input__range-inputs" : ""}"
1334
- >
1335
- ${this.range ? this.renderRangeInput() : this.multiple ? this.renderMultipleInput() : this.renderInput()}
1336
- </div>
1337
- </pkt-input-wrapper>
1338
- ${this.renderCalendar()}
1339
- `;
1340
- }
1341
- /**
1342
- * Handlers
1343
- */
1344
- handleCalendarPosition() {
1345
- const e = this.multiple && !!this.maxlength;
1346
- P.handleCalendarPosition(this.popupRef, this.inputRef, e);
1347
- }
1348
- async showCalendar() {
1349
- var t;
1350
- const e = this.datepickerPopupRef.value;
1351
- if (this.calendarOpen = !0, e && typeof e.show == "function") {
1352
- e.show(), b() && e.focusOnCurrentDate();
1353
- return;
1354
- }
1355
- await ie(20), this.handleCalendarPosition(), b() && ((t = this.calRef.value) == null || t.focusOnCurrentDate());
1356
- }
1357
- hideCalendar() {
1358
- const e = this.datepickerPopupRef.value;
1359
- if (this.calendarOpen = !1, e && typeof e.hide == "function") return e.hide();
1360
- }
1361
- async toggleCalendar(e) {
1362
- e.preventDefault();
1363
- const t = this.datepickerPopupRef.value;
1364
- if (t && typeof t.toggle == "function") {
1365
- const a = !!t.open;
1366
- t.toggle(), this.calendarOpen = !a;
1367
- return;
1368
- }
1369
- this.calendarOpen ? this.hideCalendar() : this.showCalendar();
1370
- }
1371
- clearInputValue() {
1372
- this._value = [], this.value = "", this.internals.setFormValue(this.value), this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), this.dispatchEvent(
1373
- new CustomEvent("value-change", {
1374
- detail: this._value,
1375
- bubbles: !0,
1376
- composed: !0
1377
- })
1378
- );
1379
- }
1380
- };
1381
- u([
1382
- l({ type: String, reflect: !0 })
1383
- ], p.prototype, "value", 1);
1384
- u([
1385
- l({ type: Array })
1386
- ], p.prototype, "_value", 2);
1387
- u([
1388
- l({ type: String, reflect: !0 })
1389
- ], p.prototype, "label", 2);
1390
- u([
1391
- l({ type: String })
1392
- ], p.prototype, "dateformat", 2);
1393
- u([
1394
- l({ type: Boolean, reflect: !0 })
1395
- ], p.prototype, "multiple", 2);
1396
- u([
1397
- l({ type: Number, reflect: !0 })
1398
- ], p.prototype, "maxlength", 2);
1399
- u([
1400
- l({ type: Boolean, reflect: !0 })
1401
- ], p.prototype, "range", 2);
1402
- u([
1403
- l({ type: Boolean })
1404
- ], p.prototype, "showRangeLabels", 2);
1405
- u([
1406
- l({ type: String, reflect: !0 })
1407
- ], p.prototype, "min", 2);
1408
- u([
1409
- l({ type: String, reflect: !0 })
1410
- ], p.prototype, "max", 2);
1411
- u([
1412
- l({ type: Boolean })
1413
- ], p.prototype, "weeknumbers", 2);
1414
- u([
1415
- l({ type: Boolean, reflect: !0 })
1416
- ], p.prototype, "withcontrols", 2);
1417
- u([
1418
- l({ converter: H.csvToArray })
1419
- ], p.prototype, "excludedates", 2);
1420
- u([
1421
- l({ converter: H.csvToArray })
1422
- ], p.prototype, "excludeweekdays", 2);
1423
- u([
1424
- l({ type: String })
1425
- ], p.prototype, "currentmonth", 2);
1426
- u([
1427
- l({ type: Boolean, reflect: !0 })
1428
- ], p.prototype, "calendarOpen", 2);
1429
- u([
1430
- l({ type: String })
1431
- ], p.prototype, "timezone", 2);
1432
- u([
1433
- G()
1434
- ], p.prototype, "inputClasses", 2);
1435
- p = u([
1436
- w("pkt-datepicker")
1437
- ], p);
1438
- export {
1439
- k as P,
1440
- p as a,
1441
- S as b,
1442
- _ as c,
1443
- T as d
1444
- };