@golemui/gui-lit 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/{button.element-ATNRRDN3.js → button.element-DxwYDdu6.js} +49 -45
  3. package/{currency.element-C7SZkoPP.js → currency.element-ybKzwXEh.js} +11 -10
  4. package/{date-input-e0k3oBof.js → date-input-D_Swskk4.js} +5 -5
  5. package/{date-picker.element-D6v6aHR5.js → date-picker.element-CP2_u_ZE.js} +1 -1
  6. package/{date.element-COU_mEUt.js → date.element-p6aB6OGd.js} +1 -1
  7. package/{dropdown.element-DCUI5Y7I.js → dropdown.element-8OaBgk7F.js} +1 -0
  8. package/index.js +271 -279
  9. package/index.umd.cjs +268 -195
  10. package/lib/components/range-date-picker.element.d.ts +3 -0
  11. package/lib/components/tags.element.d.ts +17 -0
  12. package/{markdown.element-CT1JOOM3.js → markdown.element-1IF3G5KX.js} +1 -0
  13. package/{number.element-HaXEg_7U.js → number.element-zgd4L5hn.js} +7 -6
  14. package/package.json +6 -6
  15. package/{password.element-B4-0SCe4.js → password.element-BT65mDsp.js} +1 -0
  16. package/pills-D0yyi-op.js +323 -0
  17. package/range-calendar-CZGBBOzO.js +258 -0
  18. package/{range-calendar.element-C-4qqRGK.js → range-calendar.element-DQZXvd-L.js} +1 -1
  19. package/range-date-input-CcPYH7P3.js +398 -0
  20. package/{range-date-input.element-D3xRMAaY.js → range-date-input.element-v71P-oUp.js} +1 -1
  21. package/{range-date-picker.element-Vgj3tFlQ.js → range-date-picker.element-CA-KcQhA.js} +60 -51
  22. package/{select.element-DuGZjlZY.js → select.element-CjWqp9dd.js} +1 -1
  23. package/tags.element-ed1_51GA.js +365 -0
  24. package/{textarea.element-C8yx2u0o.js → textarea.element-BTJLqnnI.js} +6 -5
  25. package/{textinput.element-DKuplF1A.js → textinput.element-zI0iG-Cq.js} +4 -3
  26. package/range-calendar-qpakwAba.js +0 -326
  27. package/range-date-input-DFnvo-KK.js +0 -507
@@ -0,0 +1,258 @@
1
+ import { html as v, nothing as b } from "lit";
2
+ import { property as D, state as f, customElement as $ } from "lit/decorators.js";
3
+ import { classMap as w } from "lit/directives/class-map.js";
4
+ import { i as g, a as S, b as m, g as M, m as O, c as p } from "./date-CG1562vW.js";
5
+ import { A } from "./abstract-calendar-YDgwwbqe.js";
6
+ import "./pills-D0yyi-op.js";
7
+ import "@golemui/gui-shared";
8
+ var E = Object.defineProperty, P = Object.getOwnPropertyDescriptor, u = (e, i, s, n) => {
9
+ for (var a = n > 1 ? void 0 : n ? P(i, s) : i, t = e.length - 1, r; t >= 0; t--)
10
+ (r = e[t]) && (a = (n ? r(i, s, a) : r(a)) || a);
11
+ return n && a && E(i, s, a), a;
12
+ };
13
+ let c = class extends A {
14
+ constructor() {
15
+ super(...arguments), this.value = [], this.focusDate = void 0, this.hidePills = !1, this.removePillAriaLabel = void 0, this._anchorDate = null, this._nextDate = null, this._isSelecting = !1, this._skipValueNavigation = !1, this.onPillRemoveEvent = (e) => {
16
+ if (this.disabled || this.readOnly) return;
17
+ const s = this.getSortedPills().find(
18
+ (a) => `${a.start}-${a.end ?? a.start}` === e.detail.key
19
+ );
20
+ if (!s) return;
21
+ const n = (this.value ?? []).filter(
22
+ (a) => !(a.start === s.start && (a.end ?? null) === (s.end ?? null))
23
+ );
24
+ this.value = n, this.dispatchEvent(
25
+ new CustomEvent("change", {
26
+ detail: { value: this.value },
27
+ bubbles: !0,
28
+ composed: !0
29
+ })
30
+ );
31
+ }, this.onPillClickEvent = (e) => {
32
+ const s = this.getSortedPills().find(
33
+ (n) => `${n.start}-${n.end ?? n.start}` === e.detail.key
34
+ );
35
+ s && this.navigateToDate(s.start);
36
+ };
37
+ }
38
+ createRenderRoot() {
39
+ return this;
40
+ }
41
+ connectedCallback() {
42
+ super.connectedCallback(), this.classList.add("gui-field");
43
+ }
44
+ willUpdate(e) {
45
+ if (e.has("value") && !e.has("focusDate")) {
46
+ if (this._skipValueNavigation)
47
+ this._skipValueNavigation = !1;
48
+ else if (this.value) {
49
+ const i = Array.isArray(this.value) ? this.value : [{ start: this.value }];
50
+ if (i.length > 0 && i[0].start) {
51
+ const s = new Date(i[0].start);
52
+ !isNaN(s.getTime()) && !g(s, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = s);
53
+ }
54
+ }
55
+ }
56
+ if (e.has("focusDate") && this.focusDate) {
57
+ const i = new Date(this.focusDate);
58
+ isNaN(i.getTime()) || (g(i, this._currentDate, this.numberOfMonths ?? 1) || (this._currentDate = i), this.focusDate = void 0);
59
+ }
60
+ }
61
+ renderDay(e) {
62
+ const i = {
63
+ "gui-calendar__day-button": !0,
64
+ today: e.isToday,
65
+ "other-month": !e.isCurrentMonth,
66
+ "range-start": e.isRangeStart && !e.isOneDayRange,
67
+ "range-end": e.isRangeEnd && !e.isOneDayRange,
68
+ selected: e.isOneDayRange,
69
+ "in-range": e.isInRange,
70
+ "is-anchor": e.isAnchor,
71
+ "is-selecting": e.isSelecting,
72
+ disabled: e.isDisabled
73
+ };
74
+ return v`
75
+ <button
76
+ type="button"
77
+ role="gridcell"
78
+ class=${w(i)}
79
+ tabindex=${e.isFocusable ? 0 : -1}
80
+ ?disabled=${!e.isCurrentMonth || e.isDisabled}
81
+ data-date=${e.date.toISOString()}
82
+ @click=${(s) => this.selectDate(e, s)}
83
+ @mouseover=${() => this.onMouseOver(e)}
84
+ @focus=${() => this.onMouseOver(e)}
85
+ @keydown=${(s) => this.handleKeydown(s, e)}
86
+ aria-selected=${e.isRangeStart || e.isRangeEnd || e.isInRange ? "true" : "false"}
87
+ >
88
+ ${e.dayLabel}
89
+ </button>
90
+ `;
91
+ }
92
+ getDaysInMonth(e) {
93
+ const i = new Date(this._currentDate);
94
+ i.setDate(1), i.setMonth(i.getMonth() + e);
95
+ const s = this.generateDateGrid(e), n = i.getMonth();
96
+ let a = s.map((t) => {
97
+ const r = t.getMonth() === n, l = this.isDisabled(t), o = S(t), { isRangeStart: h, isRangeEnd: d, isInRange: _, isSelecting: y } = this.checkDateStatus(t), R = o || h, T = this._anchorDate ? m(t, this._anchorDate) : !1;
98
+ return {
99
+ date: t,
100
+ dayLabel: M(this.localeId, t),
101
+ isCurrentMonth: r,
102
+ isToday: o,
103
+ isRangeStart: h,
104
+ isRangeEnd: d,
105
+ isInRange: _,
106
+ isDisabled: l,
107
+ isOneDayRange: h && d,
108
+ isAnchor: T,
109
+ isFocusable: R,
110
+ isSelecting: y && r
111
+ };
112
+ });
113
+ for (let t = 0; t < 2; t++)
114
+ a.slice(-7).every((l) => !l.isCurrentMonth) && (a = a.slice(0, -7));
115
+ if (e === 0 && !a.some((t) => t.isFocusable)) {
116
+ const t = this.numberOfMonths ?? 1, r = g(/* @__PURE__ */ new Date(), this._currentDate, t), l = this.value?.some(
117
+ (o) => g(new Date(o.start), this._currentDate, t)
118
+ ) ?? !1;
119
+ if (!r && !l) {
120
+ const o = a.find((h) => h.isCurrentMonth && !h.isDisabled);
121
+ o && (o.isFocusable = !0);
122
+ }
123
+ }
124
+ return a;
125
+ }
126
+ checkDateStatus(e) {
127
+ let i = !1, s = !1, n = !1, a = !1;
128
+ if (this._isSelecting && this._nextDate && this._anchorDate) {
129
+ const t = this._nextDate.date, r = new Date(this._anchorDate);
130
+ t.getTime() > r.getTime() ? a = e.getTime() >= r.getTime() && e.getTime() <= t.getTime() : a = e.getTime() >= t.getTime() && e.getTime() <= r.getTime();
131
+ }
132
+ if (this.value && Array.isArray(this.value))
133
+ for (const t of this.value) {
134
+ const r = new Date(t.start);
135
+ if (m(e, r) && (i = !0, s = !t.end), t.end) {
136
+ const l = new Date(t.end);
137
+ m(e, l) && (s = !0);
138
+ const o = e.getTime(), h = r.getTime(), d = l.getTime();
139
+ o > h && o < d && (n = !0);
140
+ }
141
+ }
142
+ return { isRangeStart: i, isRangeEnd: s, isInRange: n, isSelecting: a };
143
+ }
144
+ selectDate(e, i = null) {
145
+ if (!e.isCurrentMonth || this.disabled || this.readOnly) return;
146
+ const s = e.date;
147
+ if (!this._anchorDate) {
148
+ this._isSelecting = !0, this._anchorDate = s;
149
+ return;
150
+ }
151
+ let n = this._anchorDate, a = s;
152
+ s < n && (n = s, a = this._anchorDate);
153
+ const t = this.calculateValidRanges(n, a), r = [...this.value || [], ...t];
154
+ this._skipValueNavigation = !0, this.value = O(r), this._isSelecting = !1, this._nextDate = null, this._anchorDate = null, this.dispatchEvent(
155
+ new CustomEvent("change", {
156
+ detail: { value: this.value },
157
+ bubbles: !0,
158
+ composed: !0
159
+ })
160
+ );
161
+ }
162
+ /**
163
+ * Calculates and returns an array of valid date ranges between the given start date and end date.
164
+ * A date range is considered valid if no dates within the range are disabled.
165
+ *
166
+ * @param {Date} startDate - The starting date for the range calculation.
167
+ * @param {Date} endDate - The ending date for the range calculation.
168
+ * @return {DateRange[]} An array of valid date ranges where each range defines consecutive, non-disabled dates.
169
+ */
170
+ calculateValidRanges(e, i) {
171
+ const s = [], n = new Date(e), a = new Date(i);
172
+ n.setHours(0, 0, 0, 0), a.setHours(0, 0, 0, 0);
173
+ let t = null;
174
+ for (; n <= a; ) {
175
+ if (!this.isDisabled(n))
176
+ t || (t = new Date(n));
177
+ else if (t) {
178
+ const l = new Date(n);
179
+ l.setDate(n.getDate() - 1), s.push(p(t, l)), t = null;
180
+ }
181
+ n.setDate(n.getDate() + 1);
182
+ }
183
+ return t && s.push(p(t, i)), s;
184
+ }
185
+ onMouseOver(e) {
186
+ this._isSelecting && (this._nextDate = e);
187
+ }
188
+ // --- Pills ---
189
+ renderAboveCalendar() {
190
+ if (this.hidePills) return b;
191
+ const e = this.getSortedPills();
192
+ if (e.length === 0) return b;
193
+ const i = e.map((s) => {
194
+ const n = this.formatDateForDisplay(s.start), a = s.end ? this.formatDateForDisplay(s.end) : n, t = `${n} - ${a}`;
195
+ return {
196
+ key: `${s.start}-${s.end ?? s.start}`,
197
+ label: t,
198
+ ariaLabel: `${this.removePillAriaLabel ?? "Remove date"} ${t}`
199
+ };
200
+ });
201
+ return v`
202
+ <gui-pills
203
+ class="gui-range-calendar__pills"
204
+ .items=${i}
205
+ .removable=${!0}
206
+ .clickable=${!0}
207
+ .bubble=${!1}
208
+ ?disabled=${this.disabled}
209
+ ?readonly=${this.readOnly}
210
+ .removeAriaLabel=${this.removePillAriaLabel ?? "Remove date"}
211
+ @pillremove=${this.onPillRemoveEvent}
212
+ @pillclick=${this.onPillClickEvent}
213
+ ></gui-pills>
214
+ `;
215
+ }
216
+ formatDateForDisplay(e) {
217
+ const i = new Date(e);
218
+ return isNaN(i.getTime()) ? e : new Intl.DateTimeFormat(this.localeId ?? "en", {
219
+ year: "numeric",
220
+ month: "2-digit",
221
+ day: "2-digit"
222
+ }).format(i);
223
+ }
224
+ getSortedPills() {
225
+ return !this.value || !Array.isArray(this.value) ? [] : [...this.value].sort(
226
+ (e, i) => new Date(e.start).getTime() - new Date(i.start).getTime()
227
+ );
228
+ }
229
+ navigateToDate(e) {
230
+ const i = new Date(e);
231
+ !isNaN(i.getTime()) && !g(i, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = i);
232
+ }
233
+ };
234
+ u([
235
+ D({ type: Array })
236
+ ], c.prototype, "value", 2);
237
+ u([
238
+ D({ type: String })
239
+ ], c.prototype, "focusDate", 2);
240
+ u([
241
+ D({ type: Boolean })
242
+ ], c.prototype, "hidePills", 2);
243
+ u([
244
+ D({ type: String })
245
+ ], c.prototype, "removePillAriaLabel", 2);
246
+ u([
247
+ f()
248
+ ], c.prototype, "_anchorDate", 2);
249
+ u([
250
+ f()
251
+ ], c.prototype, "_nextDate", 2);
252
+ u([
253
+ f()
254
+ ], c.prototype, "_isSelecting", 2);
255
+ c = u([
256
+ $("gui-range-calendar")
257
+ ], c);
258
+ typeof customElements < "u" && !customElements.get("gui-range-calendar") && customElements.define("gui-range-calendar", c);
@@ -1,6 +1,6 @@
1
1
  import { InputWidgetAdapter as d, formContext as o, inputContext as h } from "@golemui/lit";
2
2
  import "@golemui/gui-shared";
3
- import "./range-calendar-qpakwAba.js";
3
+ import "./range-calendar-CZGBBOzO.js";
4
4
  import { consume as m, provide as u } from "@lit/context";
5
5
  import { LitElement as c, html as b } from "lit";
6
6
  import { property as D, customElement as $ } from "lit/decorators.js";
@@ -0,0 +1,398 @@
1
+ import "@golemui/gui-shared";
2
+ import { LitElement as v, nothing as g, html as c } from "lit";
3
+ import { repeat as D } from "lit-html/directives/repeat.js";
4
+ import { property as h, state as f, customElement as b } from "lit/decorators.js";
5
+ import { classMap as _ } from "lit/directives/class-map.js";
6
+ import { live as $ } from "lit/directives/live.js";
7
+ import { G as I, b as A, c as w } from "./templates-Dk1jxLwS.js";
8
+ import { t as m, m as P } from "./date-CG1562vW.js";
9
+ import "./pills-D0yyi-op.js";
10
+ import { styleMap as E } from "lit-html/directives/style-map.js";
11
+ var S = Object.defineProperty, M = Object.getOwnPropertyDescriptor, d = (t, e, s, a) => {
12
+ for (var r = a > 1 ? void 0 : a ? M(e, s) : e, i = t.length - 1, l; i >= 0; i--)
13
+ (l = t[i]) && (r = (a ? l(e, s, r) : l(r)) || r);
14
+ return a && r && S(e, s, r), r;
15
+ };
16
+ let o = class extends v {
17
+ constructor() {
18
+ super(...arguments), this.uid = void 0, this.label = void 0, this.localeId = void 0, this.errors = [], this.showErrors = !0, this.touched = !1, this.required = !1, this.disabled = !1, this.readOnly = !1, this.value = [], this.hint = void 0, this.icon = "", this.removePillAriaLabel = void 0, this.startDateAriaLabel = void 0, this.endDateAriaLabel = void 0, this.separator = void 0, this._startDate = { day: "", month: "", year: "" }, this._endDate = { day: "", month: "", year: "" }, this.MIN_DAY = 1, this.MAX_DAY = 31, this.MAX_VALID_DAY = (t, e) => t === 2 ? new Date(e, 1, 29).getDate() === 29 || !e ? 29 : 28 : t === 4 || t === 6 || t === 9 || t === 11 ? 30 : 31, this.MIN_MONTH = 1, this.MAX_MONTH = 12, this.MIN_YEAR = 1e3, this.MAX_YEAR = 9999, this.ariaController = new I(this, {
19
+ getTargets: () => this.querySelectorAll(".gui-range-date-input"),
20
+ getState: () => ({
21
+ uid: this.uid,
22
+ templateData: {
23
+ hint: this.hint,
24
+ errors: this.errors,
25
+ readonly: this.readOnly,
26
+ disabled: this.disabled,
27
+ touched: this.touched
28
+ }
29
+ })
30
+ }), this.onPillRemoveEvent = (t) => {
31
+ if (this.disabled || this.readOnly) return;
32
+ const e = this.getSortedPills(), s = e.findIndex(
33
+ (i) => `${i.start}-${i.end ?? i.start}` === t.detail.key
34
+ );
35
+ if (s < 0) return;
36
+ const a = e[s], r = (this.value ?? []).filter(
37
+ (i) => !(i.start === a.start && (i.end ?? null) === (a.end ?? null))
38
+ );
39
+ this.value = r, this.dispatchEvent(
40
+ new CustomEvent("change", {
41
+ detail: { value: this.value },
42
+ bubbles: !0,
43
+ composed: !0
44
+ })
45
+ ), r.length === 0 && requestAnimationFrame(() => {
46
+ this.querySelector(
47
+ ".gui-range-date-input__field input"
48
+ )?.focus();
49
+ });
50
+ }, this.onPillClickEvent = (t) => {
51
+ const s = this.getSortedPills().find(
52
+ (a) => `${a.start}-${a.end ?? a.start}` === t.detail.key
53
+ );
54
+ s && this.onPillClick(s);
55
+ };
56
+ }
57
+ createRenderRoot() {
58
+ return this;
59
+ }
60
+ connectedCallback() {
61
+ super.connectedCallback(), this.classList.add("gui-field");
62
+ }
63
+ render() {
64
+ const t = {
65
+ uid: this.uid,
66
+ label: this.label,
67
+ errors: this.errors,
68
+ touched: this.touched,
69
+ required: this.required,
70
+ disabled: this.disabled,
71
+ readonly: this.readOnly,
72
+ value: this.value,
73
+ hint: this.hint
74
+ }, e = new Intl.DateTimeFormat(this.localeId ?? "en", {
75
+ year: "numeric",
76
+ month: "numeric",
77
+ day: "numeric"
78
+ }).formatToParts(/* @__PURE__ */ new Date()), a = this.getSortedPills().map((i) => {
79
+ const l = this.formatDateForDisplay(i.start), n = i.end ? this.formatDateForDisplay(i.end) : l, u = `${l} - ${n}`;
80
+ return {
81
+ key: `${i.start}-${i.end ?? i.start}`,
82
+ label: u,
83
+ ariaLabel: `${this.removePillAriaLabel ?? "Remove date"} ${u}`
84
+ };
85
+ }), r = {
86
+ "gui-widget-icon": !0,
87
+ [this.icon]: !!this.icon
88
+ };
89
+ return c`
90
+ ${this.label ? A(this.uid, t, !1, void 0, !1) : g}
91
+
92
+ <div class="gui-widget">
93
+ <div
94
+ class="gui-widget-input gui-range-date-input ${this.icon ? "gui-range-date-input--icon" : ""}"
95
+ role="group"
96
+ aria-label=${this.label ?? "Date range input"}
97
+ >
98
+ ${this.icon ? c`<span class=${_(r)} data-icon=${this.icon}></span>` : g}
99
+
100
+ <gui-pills
101
+ class="gui-range-date-input__pills"
102
+ style=${E(a.length ? {} : { "min-width": 0 })}
103
+ .items=${a}
104
+ .removable=${!0}
105
+ .clickable=${!0}
106
+ .bubble=${!0}
107
+ ?disabled=${this.disabled}
108
+ ?readonly=${this.readOnly}
109
+ .removeAriaLabel=${this.removePillAriaLabel ?? "Remove date"}
110
+ .compactAriaLabel=${`${a.length} date ranges`}
111
+ @pillremove=${this.onPillRemoveEvent}
112
+ @pillclick=${this.onPillClickEvent}
113
+ ></gui-pills>
114
+
115
+ <div class="gui-range-date-input__inputs">
116
+ <div
117
+ class="gui-range-date-input__field"
118
+ role="group"
119
+ aria-label=${this.startDateAriaLabel ?? "Start date"}
120
+ >
121
+ ${this.renderDateInputs("start", e)}
122
+ </div>
123
+
124
+ <span class="gui-range-date-input__separator">${this.separator ?? "-"}</span>
125
+
126
+ <div
127
+ class="gui-range-date-input__field"
128
+ role="group"
129
+ aria-label=${this.endDateAriaLabel ?? "End date"}
130
+ >
131
+ ${this.renderDateInputs("end", e)}
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ ${this.showErrors && this.errors?.length ? w(this.uid, t) : g}
137
+ </div>
138
+ `;
139
+ }
140
+ renderDateInputs(t, e) {
141
+ const s = t === "start" ? this._startDate : this._endDate;
142
+ return D(
143
+ e,
144
+ (a) => `${t}-${a.type}`,
145
+ (a, r) => {
146
+ const i = t === "start" && r === 0 ? 0 : -1;
147
+ switch (a.type) {
148
+ case "day":
149
+ return this.renderInput(t, "day", "dd", 2, i, s.day);
150
+ case "month":
151
+ return this.renderInput(t, "month", "mm", 2, i, s.month);
152
+ case "year":
153
+ return this.renderInput(t, "year", "yyyy", 4, i, s.year);
154
+ case "literal":
155
+ return c`<span class="gui-range-date-input__separator">${a.value}</span>`;
156
+ default:
157
+ return "";
158
+ }
159
+ }
160
+ );
161
+ }
162
+ renderInput(t, e, s, a, r, i) {
163
+ return c`
164
+ <div class="gui-range-date-input__touch-target">
165
+ <input
166
+ type="text"
167
+ inputmode="numeric"
168
+ class="gui-range-date-input__part ${e === "year" ? "gui-range-date-input__year" : ""}"
169
+ data-type=${e}
170
+ data-group=${t}
171
+ maxlength=${a}
172
+ placeholder=${s}
173
+ tabindex=${r}
174
+ ?required=${this.required}
175
+ ?disabled=${this.disabled}
176
+ ?readonly=${this.readOnly}
177
+ autocomplete="off"
178
+ .value=${$(i)}
179
+ @keydown=${this.handleKeyDown}
180
+ @keyup=${(l) => this.handleKeyUp(l, t, e)}
181
+ @focus=${this.handleFocus}
182
+ @blur=${(l) => this.handleBlur(l, t, e)}
183
+ @change=${(l) => this.handleChange(l, t, e)}
184
+ />
185
+ <div class="gui-range-date-input__visual-underline"></div>
186
+ </div>
187
+ `;
188
+ }
189
+ formatDateForDisplay(t) {
190
+ const e = new Date(t);
191
+ return isNaN(e.getTime()) ? t : new Intl.DateTimeFormat(this.localeId ?? "en", {
192
+ year: "numeric",
193
+ month: "2-digit",
194
+ day: "2-digit"
195
+ }).format(e);
196
+ }
197
+ getSortedPills() {
198
+ return !this.value || !Array.isArray(this.value) ? [] : [...this.value].sort(
199
+ (t, e) => new Date(t.start).getTime() - new Date(e.start).getTime()
200
+ );
201
+ }
202
+ onPillClick(t) {
203
+ this.dispatchEvent(
204
+ new CustomEvent("pillClick", {
205
+ detail: { range: t },
206
+ bubbles: !0,
207
+ composed: !0
208
+ })
209
+ );
210
+ }
211
+ handleKeyDown(t) {
212
+ [
213
+ "Backspace",
214
+ "Tab",
215
+ "ArrowUp",
216
+ "ArrowDown",
217
+ "ArrowLeft",
218
+ "ArrowRight",
219
+ "Delete",
220
+ "Enter"
221
+ ].includes(t.key) || t.ctrlKey || t.metaKey || this.readOnly || /^[0-9]$/.test(t.key) || t.preventDefault();
222
+ }
223
+ handleFocus(t) {
224
+ this.dispatchEvent(new CustomEvent("focus", { detail: t }));
225
+ }
226
+ handleKeyUp(t, e, s) {
227
+ if (this.readOnly) return;
228
+ const a = window.getComputedStyle(this).direction === "rtl", r = t.target, i = this.getGroupInputs(e), l = i.indexOf(r);
229
+ if (r.value.length === r.maxLength && /^[0-9]$/.test(t.key))
230
+ if (l === i.length - 1) {
231
+ if (e === "start") {
232
+ const n = this.getGroupInputs("end");
233
+ n.length > 0 && n[0].focus();
234
+ }
235
+ } else
236
+ i[l + 1].focus();
237
+ switch (t.key) {
238
+ case "Enter": {
239
+ if (this.tryCreatePill(), this.value && this.value.length > 0) {
240
+ const n = this.value[this.value.length - 1];
241
+ this.onPillClick(n);
242
+ }
243
+ break;
244
+ }
245
+ case "ArrowUp": {
246
+ const n = isNaN(parseInt(r.value, 10) + 1) ? 1 : parseInt(r.value, 10) + 1;
247
+ this.setDatePartValue(e, s, n), r.select(), this.tryCreatePill();
248
+ break;
249
+ }
250
+ case "ArrowDown": {
251
+ const n = isNaN(parseInt(r.value, 10) - 1) ? 1 : parseInt(r.value, 10) - 1;
252
+ this.setDatePartValue(e, s, n), r.select(), this.tryCreatePill();
253
+ break;
254
+ }
255
+ case "ArrowLeft": {
256
+ const n = a ? l + 1 : l - 1;
257
+ if (n >= 0 && n < i.length)
258
+ i[n].focus(), i[n].select();
259
+ else {
260
+ const u = a ? "end" : "start";
261
+ if (e !== u) {
262
+ const p = this.getGroupInputs(u);
263
+ if (p.length > 0) {
264
+ const y = p[p.length - 1];
265
+ y.focus(), y.select();
266
+ }
267
+ }
268
+ }
269
+ break;
270
+ }
271
+ case "ArrowRight": {
272
+ const n = a ? l - 1 : l + 1;
273
+ if (n >= 0 && n < i.length)
274
+ i[n].focus(), i[n].select();
275
+ else {
276
+ const u = a ? "start" : "end";
277
+ if (e !== u) {
278
+ const p = this.getGroupInputs(u);
279
+ p.length > 0 && (p[0].focus(), p[0].select());
280
+ }
281
+ }
282
+ break;
283
+ }
284
+ }
285
+ }
286
+ handleChange(t, e, s) {
287
+ if (t.stopImmediatePropagation(), this.readOnly) return;
288
+ const r = t.target.value.replace(/[^0-9]/g, "");
289
+ this.updateDatePart(e, s, r), this.tryCreatePill();
290
+ }
291
+ handleBlur(t, e, s) {
292
+ const a = t.target, r = parseInt(a.value, 10);
293
+ if (!isNaN(r) && r > 0) {
294
+ const i = s === "year" ? 4 : 2;
295
+ a.value = r.toString().padStart(i, "0");
296
+ }
297
+ this.dispatchEvent(new CustomEvent("blur"));
298
+ }
299
+ getGroupInputs(t) {
300
+ return Array.from(this.querySelectorAll(`input[data-group="${t}"]`));
301
+ }
302
+ setDatePartValue(t, e, s) {
303
+ const a = t === "start" ? this._startDate : this._endDate, r = e === "year" ? 4 : 2;
304
+ e === "day" && (a.day = s.toString().padStart(r, "0")), e === "month" && (a.month = s.toString().padStart(r, "0")), e === "year" && (a.year = s.toString().padStart(r, "0")), t === "start" ? this._startDate = { ...a } : this._endDate = { ...a };
305
+ }
306
+ updateDatePart(t, e, s) {
307
+ t === "start" ? this._startDate = { ...this._startDate, [e]: s } : this._endDate = { ...this._endDate, [e]: s };
308
+ }
309
+ validateDateParts(t) {
310
+ let e = parseInt(t.year, 10), s = parseInt(t.month, 10), a = parseInt(t.day, 10);
311
+ if (isNaN(e) || isNaN(s) || isNaN(a) || String(e).length < 4) return null;
312
+ e = Math.max(this.MIN_YEAR, Math.min(this.MAX_YEAR, e)), s = Math.max(this.MIN_MONTH, Math.min(this.MAX_MONTH, s)), a = Math.max(this.MIN_DAY, Math.min(this.MAX_DAY, a));
313
+ const r = this.MAX_VALID_DAY(s, e);
314
+ return a > r ? (this.dispatchEvent(
315
+ new CustomEvent("inputError", {
316
+ detail: {
317
+ message: "Invalid date: day is greater than the maximum valid day for the month and year."
318
+ },
319
+ bubbles: !0
320
+ })
321
+ ), null) : new Date(e, s - 1, a);
322
+ }
323
+ tryCreatePill() {
324
+ const t = this.validateDateParts(this._startDate), e = this.validateDateParts(this._endDate);
325
+ if (!t || !e) return;
326
+ let s = t, a = e;
327
+ e.getTime() < t.getTime() && (s = e, a = t);
328
+ const r = m(s), i = m(a), l = r === i ? { start: r } : { start: r, end: i }, n = this.value ? [...this.value] : [];
329
+ n.push(l), this.value = P(n), this._startDate = { day: "", month: "", year: "" }, this._endDate = { day: "", month: "", year: "" }, this.dispatchEvent(
330
+ new CustomEvent("change", {
331
+ detail: { value: this.value },
332
+ bubbles: !0,
333
+ composed: !0
334
+ })
335
+ ), requestAnimationFrame(() => {
336
+ const u = this.getGroupInputs("start");
337
+ u.length > 0 && u[0].focus();
338
+ }), this.requestUpdate();
339
+ }
340
+ };
341
+ d([
342
+ h({ type: String })
343
+ ], o.prototype, "uid", 2);
344
+ d([
345
+ h({ type: String })
346
+ ], o.prototype, "label", 2);
347
+ d([
348
+ h({ type: String, attribute: "locale-id" })
349
+ ], o.prototype, "localeId", 2);
350
+ d([
351
+ h({ type: Array })
352
+ ], o.prototype, "errors", 2);
353
+ d([
354
+ h({ type: Boolean })
355
+ ], o.prototype, "showErrors", 2);
356
+ d([
357
+ h({ type: Boolean })
358
+ ], o.prototype, "touched", 2);
359
+ d([
360
+ h({ type: Boolean })
361
+ ], o.prototype, "required", 2);
362
+ d([
363
+ h({ type: Boolean })
364
+ ], o.prototype, "disabled", 2);
365
+ d([
366
+ h({ type: Boolean, attribute: "readonly" })
367
+ ], o.prototype, "readOnly", 2);
368
+ d([
369
+ h({ type: Array })
370
+ ], o.prototype, "value", 2);
371
+ d([
372
+ h({ type: String })
373
+ ], o.prototype, "hint", 2);
374
+ d([
375
+ h({ type: String })
376
+ ], o.prototype, "icon", 2);
377
+ d([
378
+ h({ type: String })
379
+ ], o.prototype, "removePillAriaLabel", 2);
380
+ d([
381
+ h({ type: String })
382
+ ], o.prototype, "startDateAriaLabel", 2);
383
+ d([
384
+ h({ type: String })
385
+ ], o.prototype, "endDateAriaLabel", 2);
386
+ d([
387
+ h({ type: String })
388
+ ], o.prototype, "separator", 2);
389
+ d([
390
+ f()
391
+ ], o.prototype, "_startDate", 2);
392
+ d([
393
+ f()
394
+ ], o.prototype, "_endDate", 2);
395
+ o = d([
396
+ b("gui-range-date")
397
+ ], o);
398
+ typeof customElements < "u" && !customElements.get("gui-range-date") && customElements.define("gui-range-date", o);
@@ -1,6 +1,6 @@
1
1
  import { InputWidgetAdapter as n, formContext as o, inputContext as u } from "@golemui/lit";
2
2
  import "@golemui/gui-shared";
3
- import "./range-date-input-DFnvo-KK.js";
3
+ import "./range-date-input-CcPYH7P3.js";
4
4
  import { consume as h, provide as m } from "@lit/context";
5
5
  import { LitElement as c, html as b } from "lit";
6
6
  import { property as D, customElement as g } from "lit/decorators.js";