@oslokommune/punkt-elements 13.6.11 → 13.6.12

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 (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{combobox-cK_746ek.cjs → combobox-BFOjlFIj.cjs} +1 -1
  3. package/dist/{combobox-DxNotM0u.js → combobox-DaiEdUKx.js} +1 -1
  4. package/dist/datepicker-C244h82t.cjs +190 -0
  5. package/dist/datepicker-DwOkktaP.js +859 -0
  6. package/dist/index.d.ts +30 -3
  7. package/dist/{input-wrapper-D_JdEqcO.js → input-wrapper-CQzXG44g.js} +22 -22
  8. package/dist/{input-wrapper-C9rZEgju.cjs → input-wrapper-DVjNwf8-.cjs} +11 -12
  9. package/dist/pkt-combobox.cjs +1 -1
  10. package/dist/pkt-combobox.js +1 -1
  11. package/dist/pkt-datepicker.cjs +1 -1
  12. package/dist/pkt-datepicker.js +1 -1
  13. package/dist/pkt-index.cjs +1 -1
  14. package/dist/pkt-index.js +6 -6
  15. package/dist/pkt-input-wrapper.cjs +1 -1
  16. package/dist/pkt-input-wrapper.js +1 -1
  17. package/dist/pkt-select.cjs +1 -1
  18. package/dist/pkt-select.js +1 -1
  19. package/dist/pkt-textarea.cjs +1 -1
  20. package/dist/pkt-textarea.js +1 -1
  21. package/dist/pkt-textinput.cjs +1 -1
  22. package/dist/pkt-textinput.js +1 -1
  23. package/dist/{select-D7OQaUrQ.js → select-DKkoxmgj.js} +1 -1
  24. package/dist/{select-Cf1RWSsI.cjs → select-DynzsPo0.cjs} +1 -1
  25. package/dist/{textarea-CXu8UUsY.cjs → textarea-BS1tgktz.cjs} +1 -1
  26. package/dist/{textarea-C0vTWTov.js → textarea-COG1CH_s.js} +1 -1
  27. package/dist/{textinput-C6wccDhZ.cjs → textinput-CCK8ti2y.cjs} +1 -1
  28. package/dist/{textinput-CmZrfH4A.js → textinput-CTOtfcTR.js} +1 -1
  29. package/package.json +2 -2
  30. package/src/components/datepicker/datepicker-popup.test.ts +77 -0
  31. package/src/components/datepicker/datepicker-popup.ts +137 -0
  32. package/src/components/datepicker/datepicker-utils.ts +13 -8
  33. package/src/components/datepicker/datepicker.ts +42 -47
  34. package/src/components/input-wrapper/input-wrapper.ts +7 -7
  35. package/dist/datepicker-BEMo4X9s.js +0 -770
  36. package/dist/datepicker-n49TAIAt.cjs +0 -169
@@ -0,0 +1,859 @@
1
+ import { e as v } from "./class-map-Dw6Wrxwi.js";
2
+ import { o as c } from "./if-defined-D3lgJqT7.js";
3
+ import { P as E, E as S, x as f, n as l, a as I } from "./element-DJZPsA_J.js";
4
+ import { r as F } from "./state-CPQXJ4Ct.js";
5
+ import { f as V, s as L, i as z, n as _, a as O, b as A, d as j, p as U, e as M } from "./calendar-CodWwTHM.js";
6
+ import { P as K } from "./input-element-DQOVrqUZ.js";
7
+ import { e as y, n as g } from "./ref-BCGCor-j.js";
8
+ import "./icon-B1-mkmwB.js";
9
+ import "./input-wrapper-CQzXG44g.js";
10
+ import { c as N } from "./repeat-B6qPUgAq.js";
11
+ import "./tag-NZ5oeGfw.js";
12
+ import { u as q } from "./stringutils-DJjRa8dG.js";
13
+ import { P as W } from "./pkt-slot-controller-BPGj-LC5.js";
14
+ const H = (e) => new Promise((t) => setTimeout(t, e)), $ = {
15
+ /**
16
+ * Detects if the current device is iOS (iPhone, iPad, iPod)
17
+ * Handles modern iPad Safari which uses desktop user agent since iOS 13
18
+ */
19
+ isIOS() {
20
+ const e = navigator.userAgent;
21
+ return !!(/iP(hone|od|ad)/.test(e) || /Macintosh/.test(e) && "ontouchend" in document);
22
+ }
23
+ }, m = {
24
+ /**
25
+ * Parses a value (string or string array) into an array of strings
26
+ */
27
+ parseValue(e) {
28
+ return e ? Array.isArray(e) ? e.filter(Boolean) : typeof e == "string" ? e.split(",").filter(Boolean) : String(e).split(",").filter(Boolean) : [];
29
+ },
30
+ /**
31
+ * Converts array of dates to comma-separated string
32
+ */
33
+ formatValue(e) {
34
+ return e.join(",");
35
+ },
36
+ /**
37
+ * Ensures name attribute ends with [] for multiple/range inputs
38
+ */
39
+ normalizeNameForMultiple(e, t, s) {
40
+ return e ? (t || s) && !e.endsWith("[]") ? e + "[]" : e : null;
41
+ },
42
+ /**
43
+ * Converts string arrays to proper arrays if they come as strings
44
+ */
45
+ normalizeStringArray(e) {
46
+ return typeof e == "string" ? e.split(",").filter(Boolean) : Array.isArray(e) ? e : [];
47
+ },
48
+ /**
49
+ * Validates that a range has valid order (start <= end)
50
+ */
51
+ validateRangeOrder(e) {
52
+ return !e || e.length !== 2 ? !0 : z(e[0], e[1]);
53
+ },
54
+ /**
55
+ * Sorts date strings chronologically
56
+ */
57
+ sortDates(e) {
58
+ return L(e);
59
+ },
60
+ /**
61
+ * Filters dates to only include selectable ones based on constraints
62
+ */
63
+ filterSelectableDates(e, t, s, a, i) {
64
+ return V(e, t, s, a, i);
65
+ }
66
+ }, G = {
67
+ /**
68
+ * Determines the appropriate input type based on device
69
+ * Mobile Safari does not play well with type="date" amd custom datepickers
70
+ */
71
+ getInputType() {
72
+ return $.isIOS() ? "text" : "date";
73
+ }
74
+ }, k = {
75
+ /**
76
+ * Submits the form that contains the given element
77
+ */
78
+ submitForm(e) {
79
+ var s;
80
+ const t = (s = e.internals) == null ? void 0 : s.form;
81
+ t && t.requestSubmit();
82
+ },
83
+ /**
84
+ * Submits form if available, otherwise executes fallback action
85
+ */
86
+ submitFormOrFallback(e, t) {
87
+ const s = e == null ? void 0 : e.form;
88
+ s ? s.requestSubmit() : t();
89
+ },
90
+ /**
91
+ * Validates a date input and sets validity state
92
+ */
93
+ validateDateInput(e, t, s, a, i) {
94
+ var n, p, T, B;
95
+ const r = e.value;
96
+ r && (s && s > r ? t.setValidity(
97
+ { rangeUnderflow: !0 },
98
+ ((p = (n = i == null ? void 0 : i.forms) == null ? void 0 : n.messages) == null ? void 0 : p.rangeUnderflow) || "Value is below minimum",
99
+ e
100
+ ) : a && a < r && t.setValidity(
101
+ { rangeOverflow: !0 },
102
+ ((B = (T = i == null ? void 0 : i.forms) == null ? void 0 : T.messages) == null ? void 0 : B.rangeOverflow) || "Value is above maximum",
103
+ e
104
+ ));
105
+ }
106
+ }, D = {
107
+ /**
108
+ * Adds a date to selected dates if it's valid
109
+ */
110
+ addToSelected(e, t, s, a) {
111
+ const i = e.target;
112
+ if (!i.value) return;
113
+ const r = s ? _(s) : null, n = a ? _(a) : null, p = _(i.value.split(",")[0]);
114
+ p && !isNaN(p.getTime()) && (!r || p >= r) && (!n || p <= n) && t.value && t.value.handleDateSelect(p), i.value = "";
115
+ },
116
+ /**
117
+ * Handles calendar positioning based on viewport and input position
118
+ */
119
+ handleCalendarPosition(e, t, s = !1) {
120
+ var p;
121
+ if (!e.value || !t.value) return;
122
+ const a = ((p = t.value.parentElement) == null ? void 0 : p.getBoundingClientRect()) || t.value.getBoundingClientRect(), i = s ? a.height + 30 : a.height, r = e.value.getBoundingClientRect().height;
123
+ let n = s ? "calc(100% - 30px)" : "100%";
124
+ a && a.top + r > window.innerHeight && a.top - r > 0 && (n = `calc(100% - ${i}px - ${r}px)`), e.value.style.top = n;
125
+ }
126
+ }, P = {
127
+ /**
128
+ * Generates input classes for datepicker
129
+ */
130
+ getInputClasses(e, t, s, a) {
131
+ return {
132
+ "pkt-input": !0,
133
+ "pkt-datepicker__input": !0,
134
+ "pkt-input--fullwidth": e,
135
+ "pkt-datepicker--hasrangelabels": t,
136
+ "pkt-datepicker--multiple": s,
137
+ "pkt-datepicker--range": a
138
+ };
139
+ },
140
+ /**
141
+ * Generates button classes for datepicker
142
+ */
143
+ getButtonClasses() {
144
+ return {
145
+ "pkt-input-icon": !0,
146
+ "pkt-btn": !0,
147
+ "pkt-btn--icon-only": !0,
148
+ "pkt-btn--tertiary": !0,
149
+ "pkt-datepicker__calendar-button": !0
150
+ };
151
+ },
152
+ /**
153
+ * Generates range label classes
154
+ */
155
+ getRangeLabelClasses(e) {
156
+ return {
157
+ "pkt-input-prefix": e,
158
+ "pkt-hide": !e
159
+ };
160
+ }
161
+ }, R = {
162
+ /**
163
+ * Handles date selection from calendar events
164
+ */
165
+ processDateSelection(e, t, s) {
166
+ return !t && !s ? e[0] || "" : Array.isArray(e) ? e.join(",") : e;
167
+ },
168
+ /**
169
+ * Updates input values after calendar selection
170
+ */
171
+ updateInputValues(e, t, s, a, i, r) {
172
+ e.value && (a && (t != null && t.value) ? (e.value.value = s[0] ?? "", t.value.value = s[1] ?? "", r(e.value), r(t.value)) : i || (e.value.value = s.length ? s[0] : "", r(e.value)));
173
+ },
174
+ /**
175
+ * Processes blur events for range inputs
176
+ */
177
+ processRangeBlur(e, t, s, a, i) {
178
+ var n;
179
+ const r = e.target;
180
+ if (r.value) {
181
+ i(r);
182
+ const p = O(r.value);
183
+ p && t[0] !== r.value && t[1] && (a(), (n = s == null ? void 0 : s.value) == null || n.handleDateSelect(p));
184
+ } else t[0] && a();
185
+ }
186
+ }, w = {
187
+ /**
188
+ * Handles common keyboard interactions for datepicker inputs
189
+ */
190
+ handleInputKeydown(e, t, s, a, i, r) {
191
+ const { key: n } = e;
192
+ n === "," && (e.preventDefault(), r ? r(e) : i && i()), (n === "Space" || n === " ") && (e.preventDefault(), t(e)), n === "Enter" && (e.preventDefault(), s ? s() : a ? a() : i && i());
193
+ },
194
+ /**
195
+ * Handles keyboard interactions for calendar button
196
+ */
197
+ handleButtonKeydown(e, t) {
198
+ const { key: s } = e;
199
+ (s === "Enter" || s === " " || s === "Space") && (e.preventDefault(), t(e));
200
+ }
201
+ };
202
+ var J = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, C = (e, t, s, a) => {
203
+ for (var i = a > 1 ? void 0 : a ? Q(t, s) : t, r = e.length - 1, n; r >= 0; r--)
204
+ (n = e[r]) && (i = (a ? n(t, s, i) : n(i)) || i);
205
+ return a && i && J(t, s, i), i;
206
+ };
207
+ let b = class extends E {
208
+ constructor() {
209
+ super(...arguments), this.dates = [], this.dateformat = "dd.MM.yyyy", this.className = "pkt-datepicker__tags", this.idBase = q();
210
+ }
211
+ render() {
212
+ return this.classes = {
213
+ "pkt-date-tags": !0,
214
+ [this.className]: !0
215
+ }, f`
216
+ <div class=${v(this.classes)} aria-live="polite">
217
+ ${Array.isArray(this.dates) && this.dates[0] ? N(
218
+ m.sortDates((this.dates ?? []).filter(Boolean)),
219
+ (e) => e,
220
+ (e) => {
221
+ var t;
222
+ return f` <pkt-tag
223
+ id=${this.idBase + e + "-tag"}
224
+ closeTag
225
+ @close=${() => {
226
+ this.dispatchEvent(new CustomEvent("date-tag-removed", { detail: e }));
227
+ }}
228
+ .ariaLabel=${`${(t = this.strings) == null ? void 0 : t.calendar.deleteDate} ${A(e, this.dateformat)}`}
229
+ >
230
+ <time datetime=${e}>${A(e, this.dateformat)}</time>
231
+ </pkt-tag>`;
232
+ }
233
+ ) : S}
234
+ </div>
235
+ `;
236
+ }
237
+ };
238
+ C([
239
+ l({ type: Array })
240
+ ], b.prototype, "dates", 2);
241
+ C([
242
+ l({ type: String })
243
+ ], b.prototype, "dateformat", 2);
244
+ C([
245
+ l({ type: String, attribute: "class" })
246
+ ], b.prototype, "className", 2);
247
+ C([
248
+ l({ type: String, attribute: "id-base" })
249
+ ], b.prototype, "idBase", 2);
250
+ b = C([
251
+ I("pkt-date-tags")
252
+ ], b);
253
+ const X = {
254
+ dateformat: {
255
+ default: "dd.MM.yyyy"
256
+ },
257
+ weeknumbers: {
258
+ default: !1
259
+ },
260
+ withcontrols: {
261
+ default: !1
262
+ },
263
+ multiple: {
264
+ default: !1
265
+ },
266
+ range: {
267
+ default: !1
268
+ }
269
+ }, x = {
270
+ props: X
271
+ };
272
+ var Y = Object.defineProperty, Z = Object.getOwnPropertyDescriptor, d = (e, t, s, a) => {
273
+ for (var i = a > 1 ? void 0 : a ? Z(t, s) : t, r = e.length - 1, n; r >= 0; r--)
274
+ (n = e[r]) && (i = (a ? n(t, s, i) : n(i)) || i);
275
+ return a && i && Y(t, s, i), i;
276
+ };
277
+ let h = class extends E {
278
+ constructor() {
279
+ 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 = y(), this.calendarRef = y(), this.handleDocumentClick = (e) => {
280
+ if (!this.open) return;
281
+ const t = e.composedPath(), s = this.parentElement, a = this.popupRef.value;
282
+ !t.includes(this) && !t.includes(a) && !(s && t.includes(s)) && (this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 })));
283
+ }, this.handleDocumentKeydown = (e) => {
284
+ this.open && e.key === "Escape" && (this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 })));
285
+ };
286
+ }
287
+ firstUpdated() {
288
+ this.calRef = this.calendarRef, document.addEventListener("keydown", this.handleDocumentKeydown), document.addEventListener("click", this.handleDocumentClick);
289
+ }
290
+ disconnectedCallback() {
291
+ super.disconnectedCallback(), document.removeEventListener("click", this.handleDocumentClick), document.removeEventListener("keydown", this.handleDocumentKeydown);
292
+ }
293
+ show() {
294
+ var e;
295
+ this.open = !0, (e = this.calendarRef.value) == null || e.focus();
296
+ }
297
+ hide() {
298
+ this.open = !1;
299
+ }
300
+ toggle() {
301
+ this.open ? this.hide() : this.show();
302
+ }
303
+ contains(e) {
304
+ var t;
305
+ return !!e && !!((t = this.popupRef.value) != null && t.contains(e));
306
+ }
307
+ focusOnCurrentDate() {
308
+ const e = this.calendarRef.value;
309
+ e && typeof e.focusOnCurrentDate == "function" && e.focusOnCurrentDate();
310
+ }
311
+ addToSelected(e, t, s) {
312
+ if (typeof D.addToSelected == "function")
313
+ return D.addToSelected(e, this.calendarRef, t, s);
314
+ }
315
+ handleDateSelect(e) {
316
+ const t = this.calendarRef.value;
317
+ if (t && typeof t.handleDateSelect == "function") return t.handleDateSelect(e);
318
+ }
319
+ render() {
320
+ const e = { "pkt-calendar-popup": !0, show: this.open, hide: !this.open };
321
+ return f`
322
+ <div
323
+ class="${v(e)}"
324
+ ${g(this.popupRef)}
325
+ id="date-popup"
326
+ ?hidden=${!this.open}
327
+ aria-hidden="${!this.open}"
328
+ >
329
+ <pkt-calendar
330
+ ${g(this.calendarRef)}
331
+ ?multiple=${this.multiple}
332
+ ?range=${this.range}
333
+ ?weeknumbers=${this.weeknumbers}
334
+ ?withcontrols=${this.withcontrols}
335
+ .maxMultiple=${this.maxMultiple}
336
+ .selected=${this.selected}
337
+ .earliest=${this.earliest}
338
+ .latest=${this.latest}
339
+ .excludedates=${this.excludedates}
340
+ .excludeweekdays=${this.excludeweekdays}
341
+ .currentmonth=${this.currentmonth}
342
+ @date-selected=${(t) => {
343
+ this.selected = t.detail, this.dispatchEvent(
344
+ new CustomEvent("date-selected", { detail: t.detail, bubbles: !0, composed: !0 })
345
+ );
346
+ }}
347
+ @close=${() => {
348
+ this.hide(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 }));
349
+ }}
350
+ ></pkt-calendar>
351
+ </div>
352
+ `;
353
+ }
354
+ };
355
+ d([
356
+ l({ type: Boolean, reflect: !0 })
357
+ ], h.prototype, "open", 2);
358
+ d([
359
+ l({ type: Boolean })
360
+ ], h.prototype, "multiple", 2);
361
+ d([
362
+ l({ type: Boolean })
363
+ ], h.prototype, "range", 2);
364
+ d([
365
+ l({ type: Boolean })
366
+ ], h.prototype, "weeknumbers", 2);
367
+ d([
368
+ l({ type: Boolean })
369
+ ], h.prototype, "withcontrols", 2);
370
+ d([
371
+ l({ type: Number })
372
+ ], h.prototype, "maxMultiple", 2);
373
+ d([
374
+ l({ type: Array })
375
+ ], h.prototype, "selected", 2);
376
+ d([
377
+ l({ type: String })
378
+ ], h.prototype, "earliest", 2);
379
+ d([
380
+ l({ type: String })
381
+ ], h.prototype, "latest", 2);
382
+ d([
383
+ l({ type: Array })
384
+ ], h.prototype, "excludedates", 2);
385
+ d([
386
+ l({ type: Array })
387
+ ], h.prototype, "excludeweekdays", 2);
388
+ d([
389
+ l({ type: String })
390
+ ], h.prototype, "currentmonth", 2);
391
+ h = d([
392
+ I("pkt-datepicker-popup")
393
+ ], h);
394
+ var ee = Object.defineProperty, te = Object.getOwnPropertyDescriptor, u = (e, t, s, a) => {
395
+ for (var i = a > 1 ? void 0 : a ? te(t, s) : t, r = e.length - 1, n; r >= 0; r--)
396
+ (n = e[r]) && (i = (a ? n(t, s, i) : n(i)) || i);
397
+ return a && i && ee(t, s, i), i;
398
+ };
399
+ let o = class extends K {
400
+ /**
401
+ * Housekeeping / lifecycle methods
402
+ */
403
+ constructor() {
404
+ super(), this._valueProperty = "", this.datepickerPopupRef = y(), this._value = [], this.label = "Datovelger", this.dateformat = x.props.dateformat.default, this.multiple = x.props.multiple.default, this.maxlength = null, this.range = x.props.range.default, this.showRangeLabels = !1, this.min = null, this.max = null, this.weeknumbers = x.props.weeknumbers.default, this.withcontrols = x.props.withcontrols.default, this.excludedates = [], this.excludeweekdays = [], this.currentmonth = null, this.calendarOpen = !1, this.timezone = "Europe/Oslo", this.inputClasses = {}, this.buttonClasses = {}, this.inputRef = y(), this.inputRefTo = y(), this.btnRef = y(), this.calRef = y(), this.popupRef = y(), this.helptextSlot = y(), this.addToSelected = (e) => {
405
+ const t = this.datepickerPopupRef.value;
406
+ return t && typeof t.addToSelected == "function" ? t.addToSelected(e, this.min, this.max) : D.addToSelected(e, this.calRef, this.min, this.max);
407
+ }, this.slotController = new W(this, this.helptextSlot);
408
+ }
409
+ get value() {
410
+ return this._valueProperty;
411
+ }
412
+ set value(e) {
413
+ const t = this._valueProperty;
414
+ this._valueProperty = Array.isArray(e) ? e.join(",") : e || "", this.valueChanged(this._valueProperty, t), this.requestUpdate("value", t);
415
+ }
416
+ /**
417
+ * Computed properties
418
+ */
419
+ get inputType() {
420
+ return G.getInputType();
421
+ }
422
+ connectedCallback() {
423
+ super.connectedCallback(), this.timezone && this.timezone !== window.pktTz && (window.pktTz = this.timezone), this.name = m.normalizeNameForMultiple(this.name, this.multiple, this.range) || this.name;
424
+ }
425
+ disconnectedCallback() {
426
+ super.disconnectedCallback();
427
+ }
428
+ onInput() {
429
+ this.dispatchEvent(new Event("input", { bubbles: !0 }));
430
+ }
431
+ valueChanged(e, t) {
432
+ if (e === t) return;
433
+ const s = m.parseValue(e), a = this.multiple && s.length > 1 ? m.filterSelectableDates(
434
+ s,
435
+ this.min,
436
+ this.max,
437
+ this.excludedates,
438
+ this.excludeweekdays
439
+ ) : s;
440
+ if (this.range && !m.validateRangeOrder(a)) {
441
+ this._value = [], this._valueProperty = "", super.valueChanged("", t);
442
+ return;
443
+ }
444
+ this._value = a;
445
+ const i = m.formatValue(a);
446
+ this._valueProperty !== i && (this._valueProperty = i), super.valueChanged(i, t);
447
+ }
448
+ attributeChangedCallback(e, t, s) {
449
+ e === "value" && this.value !== t && this.valueChanged(s, t), e === "excludedates" && typeof this.excludedates == "string" && (this.excludedates = m.normalizeStringArray(s || "")), e === "excludeweekdays" && typeof this.excludeweekdays == "string" && (this.excludeweekdays = m.normalizeStringArray(s || "")), super.attributeChangedCallback(e, t, s);
450
+ }
451
+ updated(e) {
452
+ if (e.has("value")) {
453
+ const t = Array.isArray(this.value) ? this.value.join(",") : this.value, s = e.get("value"), a = Array.isArray(s) ? s.join(",") : s;
454
+ this.valueChanged(t, a);
455
+ }
456
+ (e.has("multiple") || e.has("range")) && (this.name = m.normalizeNameForMultiple(this.name, this.multiple, this.range) || this.name), e.has("multiple") && (this.multiple && !Array.isArray(this._value) ? this._value = m.parseValue(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);
457
+ }
458
+ /**
459
+ * Rendering
460
+ */
461
+ renderInput() {
462
+ return f`
463
+ <input
464
+ class="${v(this.inputClasses)}"
465
+ .type=${this.inputType}
466
+ id="${this.id}-input"
467
+ .value=${this._value[0] ?? ""}
468
+ min=${c(this.min)}
469
+ max=${c(this.max)}
470
+ placeholder=${c(this.placeholder)}
471
+ ?readonly=${this.readonly}
472
+ aria-describedby="${this.id}-helptext"
473
+ @click=${(e) => {
474
+ e.preventDefault(), this.showCalendar();
475
+ }}
476
+ ?disabled=${this.disabled}
477
+ @keydown=${(e) => w.handleInputKeydown(
478
+ // event, toggleCalendar, submitForm, focusNext, blur, comma
479
+ e,
480
+ (t) => this.toggleCalendar(t),
481
+ () => k.submitFormOrFallback(this.internals, () => {
482
+ var t;
483
+ return (t = this.inputRef.value) == null ? void 0 : t.blur();
484
+ }),
485
+ void 0,
486
+ () => {
487
+ var t;
488
+ return (t = this.inputRef.value) == null ? void 0 : t.blur();
489
+ }
490
+ )}
491
+ @input=${(e) => {
492
+ this.onInput(), e.stopImmediatePropagation();
493
+ }}
494
+ @focus=${() => {
495
+ this.onFocus(), $.isIOS() && this.showCalendar();
496
+ }}
497
+ @blur=${(e) => {
498
+ var t;
499
+ (t = this.calRef.value) != null && t.contains(e.relatedTarget) || this.onBlur(), this.manageValidity(e.target), this.value = e.target.value;
500
+ }}
501
+ @change=${(e) => {
502
+ this.touched = !0, e.stopImmediatePropagation();
503
+ }}
504
+ ${g(this.inputRef)}
505
+ />
506
+ `;
507
+ }
508
+ renderRangeInput() {
509
+ const e = P.getRangeLabelClasses(this.showRangeLabels);
510
+ return f`
511
+ ${this.showRangeLabels ? f` <div class="pkt-input-prefix">${this.strings.generic.from}</div> ` : S}
512
+ <input
513
+ class=${v(this.inputClasses)}
514
+ .type=${this.inputType}
515
+ id="${this.id}-input"
516
+ .value=${this._value[0] ?? ""}
517
+ min=${c(this.min)}
518
+ max=${c(this.max)}
519
+ placeholder=${c(this.placeholder)}
520
+ ?readonly=${this.readonly}
521
+ ?disabled=${this.disabled}
522
+ @click=${(t) => {
523
+ t.preventDefault(), this.showCalendar();
524
+ }}
525
+ @keydown=${(t) => w.handleInputKeydown(
526
+ // event, toggleCalendar, submitForm, focusNext, blur, comma
527
+ t,
528
+ (s) => this.toggleCalendar(s),
529
+ () => k.submitFormOrFallback(this.internals, () => {
530
+ var s;
531
+ return (s = this.inputRefTo.value) == null ? void 0 : s.focus();
532
+ }),
533
+ () => {
534
+ var s;
535
+ return (s = this.inputRefTo.value) == null ? void 0 : s.focus();
536
+ },
537
+ () => {
538
+ var s;
539
+ return (s = this.inputRef.value) == null ? void 0 : s.blur();
540
+ }
541
+ )}
542
+ @input=${(t) => {
543
+ this.onInput(), t.stopImmediatePropagation();
544
+ }}
545
+ @focus=${() => {
546
+ this.onFocus(), $.isIOS() && this.showCalendar();
547
+ }}
548
+ @blur=${(t) => {
549
+ R.processRangeBlur(
550
+ t,
551
+ this._value,
552
+ this.calRef,
553
+ () => this.clearInputValue(),
554
+ (s) => this.manageValidity(s)
555
+ );
556
+ }}
557
+ @change=${(t) => {
558
+ t.stopImmediatePropagation();
559
+ }}
560
+ ${g(this.inputRef)}
561
+ />
562
+ <div class="${v(e)}" id="${this.id}-to-label">
563
+ ${this.strings.generic.to}
564
+ </div>
565
+ ${this.showRangeLabels ? S : f` <div class="pkt-input-separator">–</div> `}
566
+ <input
567
+ class=${v(this.inputClasses)}
568
+ .type=${this.inputType}
569
+ id="${this.id}-to"
570
+ aria-labelledby="${this.id}-to-label"
571
+ .value=${this._value[1] ?? ""}
572
+ min=${c(this.min)}
573
+ max=${c(this.max)}
574
+ placeholder=${c(this.placeholder)}
575
+ ?readonly=${this.readonly}
576
+ ?disabled=${this.disabled}
577
+ @click=${(t) => {
578
+ t.preventDefault(), this.showCalendar();
579
+ }}
580
+ @keydown=${(t) => w.handleInputKeydown(
581
+ // event, toggleCalendar, submitForm, focusNext, blur, comma
582
+ t,
583
+ (s) => this.toggleCalendar(s),
584
+ () => k.submitFormOrFallback(this.internals, () => {
585
+ var s;
586
+ return (s = this.inputRefTo.value) == null ? void 0 : s.blur();
587
+ }),
588
+ void 0,
589
+ () => {
590
+ var s;
591
+ return (s = this.inputRefTo.value) == null ? void 0 : s.blur();
592
+ }
593
+ )}
594
+ @input=${(t) => {
595
+ this.onInput(), t.stopImmediatePropagation();
596
+ }}
597
+ @focus=${() => {
598
+ this.onFocus(), $.isIOS() && this.showCalendar();
599
+ }}
600
+ @blur=${(t) => {
601
+ var s, a, i;
602
+ if ((s = this.calRef.value) != null && s.contains(t.relatedTarget) || this.onBlur(), t.target.value) {
603
+ this.manageValidity(t.target), k.validateDateInput(
604
+ t.target,
605
+ this.internals,
606
+ this.min,
607
+ this.max,
608
+ this.strings
609
+ );
610
+ const r = O(t.target.value);
611
+ r && this._value[1] !== j(r) && ((i = (a = this.calRef) == null ? void 0 : a.value) == null || i.handleDateSelect(r));
612
+ }
613
+ }}
614
+ @change=${(t) => {
615
+ this.touched = !0, t.stopImmediatePropagation();
616
+ }}
617
+ ${g(this.inputRefTo)}
618
+ />
619
+ `;
620
+ }
621
+ renderMultipleInput() {
622
+ return f`
623
+ <input
624
+ class=${v(this.inputClasses)}
625
+ .type=${this.inputType}
626
+ id="${this.id}-input"
627
+ min=${c(this.min)}
628
+ max=${c(this.max)}
629
+ placeholder=${c(this.placeholder)}
630
+ ?readonly=${this.readonly}
631
+ ?disabled=${this.disabled || this.maxlength && this._value.length >= this.maxlength}
632
+ @click=${(e) => {
633
+ e.preventDefault(), this.showCalendar();
634
+ }}
635
+ @blur=${(e) => {
636
+ var t;
637
+ (t = this.calRef.value) != null && t.contains(e.relatedTarget) || this.onBlur(), this.addToSelected(e);
638
+ }}
639
+ @input=${(e) => {
640
+ this.onInput(), e.stopImmediatePropagation();
641
+ }}
642
+ @focus=${() => {
643
+ this.onFocus(), $.isIOS() && this.showCalendar();
644
+ }}
645
+ @keydown=${(e) => w.handleInputKeydown(
646
+ // event, toggleCalendar, submitForm, focusNext, blur, comma
647
+ e,
648
+ (t) => this.toggleCalendar(t),
649
+ () => k.submitFormOrFallback(this.internals, () => {
650
+ var t;
651
+ return (t = this.inputRef.value) == null ? void 0 : t.blur();
652
+ }),
653
+ void 0,
654
+ void 0,
655
+ (t) => this.addToSelected(t)
656
+ )}
657
+ @change=${(e) => {
658
+ this.touched = !0, e.stopImmediatePropagation();
659
+ }}
660
+ ${g(this.inputRef)}
661
+ />
662
+ `;
663
+ }
664
+ renderCalendar() {
665
+ return f`
666
+ <pkt-datepicker-popup
667
+ class="pkt-contents"
668
+ ?open=${this.calendarOpen}
669
+ ?multiple=${this.multiple}
670
+ ?range=${this.range}
671
+ ?weeknumbers=${this.weeknumbers}
672
+ ?withcontrols=${this.withcontrols}
673
+ .maxMultiple=${this.maxlength}
674
+ .selected=${this._value}
675
+ .earliest=${this.min}
676
+ .latest=${this.max}
677
+ .excludedates=${Array.isArray(this.excludedates) ? this.excludedates : this.excludedates.split(",")}
678
+ .excludeweekdays=${this.excludeweekdays}
679
+ .currentmonth=${this.currentmonth ? U(this.currentmonth) : null}
680
+ @date-selected=${(e) => {
681
+ this.value = R.processDateSelection(e.detail, this.multiple, this.range), this._value = e.detail, R.updateInputValues(
682
+ this.inputRef,
683
+ this.inputRefTo,
684
+ this._value,
685
+ this.range,
686
+ this.multiple,
687
+ (t) => this.manageValidity(t)
688
+ );
689
+ }}
690
+ @close=${() => {
691
+ this.onBlur(), this.hideCalendar();
692
+ }}
693
+ ${g(this.datepickerPopupRef)}
694
+ ></pkt-datepicker-popup>
695
+ `;
696
+ }
697
+ render() {
698
+ return this.inputClasses = P.getInputClasses(
699
+ this.fullwidth,
700
+ this.showRangeLabels,
701
+ this.multiple,
702
+ this.range
703
+ ), this.buttonClasses = P.getButtonClasses(), f`
704
+ <pkt-input-wrapper
705
+ label="${this.label}"
706
+ forId="${this.id}-input"
707
+ ?counter=${this.multiple && !!this.maxlength}
708
+ .counterCurrent=${this.value ? this._value.length : 0}
709
+ .counterMaxLength=${this.maxlength}
710
+ ?disabled=${this.disabled}
711
+ ?hasError=${this.hasError}
712
+ ?hasFieldset=${this.hasFieldset}
713
+ ?inline=${this.inline}
714
+ ?required=${this.required}
715
+ ?optionalTag=${this.optionalTag}
716
+ ?requiredTag=${this.requiredTag}
717
+ ?useWrapper=${this.useWrapper}
718
+ .optionalText=${this.optionalText}
719
+ .requiredText=${this.requiredText}
720
+ .tagText=${this.tagText}
721
+ .errorMessage=${this.errorMessage}
722
+ .helptext=${this.helptext}
723
+ .helptextDropdown=${this.helptextDropdown}
724
+ .helptextDropdownButton=${this.helptextDropdownButton}
725
+ .ariaDescribedBy=${this.ariaDescribedBy}
726
+ class="pkt-datepicker"
727
+ >
728
+ <div class="pkt-contents" ${g(this.helptextSlot)} name="helptext" slot="helptext"></div>
729
+ ${this.multiple ? f`<pkt-date-tags
730
+ .dates=${this._value}
731
+ dateformat=${this.dateformat}
732
+ strings=${this.strings}
733
+ id-base=${this.id}
734
+ @date-tag-removed=${(e) => {
735
+ var a;
736
+ const t = this.datepickerPopupRef.value, s = O(e.detail);
737
+ t && s && typeof t.handleDateSelect == "function" ? t.handleDateSelect(s) : (a = this.calRef.value) == null || a.handleDateSelect(s);
738
+ }}
739
+ ></pkt-date-tags>` : S}
740
+ <div
741
+ class="pkt-datepicker__inputs ${this.range && this.showRangeLabels ? "pkt-input__range-inputs" : ""}"
742
+ >
743
+ <div class="pkt-input__container">
744
+ ${this.range ? this.renderRangeInput() : this.multiple ? this.renderMultipleInput() : this.renderInput()}
745
+ <button
746
+ class="${v(this.buttonClasses)}"
747
+ type="button"
748
+ @click=${this.toggleCalendar}
749
+ @keydown=${(e) => w.handleButtonKeydown(e, (t) => this.toggleCalendar(t))}
750
+ ?disabled=${this.disabled}
751
+ ${g(this.btnRef)}
752
+ >
753
+ <pkt-icon name="calendar"></pkt-icon>
754
+ <span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
755
+ </button>
756
+ </div>
757
+ </div>
758
+ </pkt-input-wrapper>
759
+ ${this.renderCalendar()}
760
+ `;
761
+ }
762
+ /**
763
+ * Handlers
764
+ */
765
+ handleCalendarPosition() {
766
+ const e = this.multiple && !!this.maxlength;
767
+ D.handleCalendarPosition(this.popupRef, this.inputRef, e);
768
+ }
769
+ async showCalendar() {
770
+ var t;
771
+ const e = this.datepickerPopupRef.value;
772
+ if (this.calendarOpen = !0, e && typeof e.show == "function") {
773
+ e.show(), $.isIOS() && e.focusOnCurrentDate();
774
+ return;
775
+ }
776
+ await H(20), this.handleCalendarPosition(), $.isIOS() && ((t = this.calRef.value) == null || t.focusOnCurrentDate());
777
+ }
778
+ hideCalendar() {
779
+ const e = this.datepickerPopupRef.value;
780
+ if (this.calendarOpen = !1, e && typeof e.hide == "function") return e.hide();
781
+ }
782
+ async toggleCalendar(e) {
783
+ e.preventDefault();
784
+ const t = this.datepickerPopupRef.value;
785
+ if (t && typeof t.toggle == "function") {
786
+ const s = !!t.open;
787
+ t.toggle(), this.calendarOpen = !s;
788
+ return;
789
+ }
790
+ this.calendarOpen ? this.hideCalendar() : this.showCalendar();
791
+ }
792
+ clearInputValue() {
793
+ this._value = [], this.value = "";
794
+ }
795
+ };
796
+ u([
797
+ l({ type: String, reflect: !0 })
798
+ ], o.prototype, "value", 1);
799
+ u([
800
+ l({ type: Array })
801
+ ], o.prototype, "_value", 2);
802
+ u([
803
+ l({ type: String, reflect: !0 })
804
+ ], o.prototype, "label", 2);
805
+ u([
806
+ l({ type: String })
807
+ ], o.prototype, "dateformat", 2);
808
+ u([
809
+ l({ type: Boolean, reflect: !0 })
810
+ ], o.prototype, "multiple", 2);
811
+ u([
812
+ l({ type: Number, reflect: !0 })
813
+ ], o.prototype, "maxlength", 2);
814
+ u([
815
+ l({ type: Boolean, reflect: !0 })
816
+ ], o.prototype, "range", 2);
817
+ u([
818
+ l({ type: Boolean })
819
+ ], o.prototype, "showRangeLabels", 2);
820
+ u([
821
+ l({ type: String, reflect: !0 })
822
+ ], o.prototype, "min", 2);
823
+ u([
824
+ l({ type: String, reflect: !0 })
825
+ ], o.prototype, "max", 2);
826
+ u([
827
+ l({ type: Boolean })
828
+ ], o.prototype, "weeknumbers", 2);
829
+ u([
830
+ l({ type: Boolean, reflect: !0 })
831
+ ], o.prototype, "withcontrols", 2);
832
+ u([
833
+ l({ converter: M.csvToArray })
834
+ ], o.prototype, "excludedates", 2);
835
+ u([
836
+ l({ converter: M.csvToArray })
837
+ ], o.prototype, "excludeweekdays", 2);
838
+ u([
839
+ l({ type: String })
840
+ ], o.prototype, "currentmonth", 2);
841
+ u([
842
+ l({ type: Boolean, reflect: !0 })
843
+ ], o.prototype, "calendarOpen", 2);
844
+ u([
845
+ l({ type: String })
846
+ ], o.prototype, "timezone", 2);
847
+ u([
848
+ F()
849
+ ], o.prototype, "inputClasses", 2);
850
+ u([
851
+ F()
852
+ ], o.prototype, "buttonClasses", 2);
853
+ o = u([
854
+ I("pkt-datepicker")
855
+ ], o);
856
+ export {
857
+ b as P,
858
+ o as a
859
+ };