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