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