@golemui/gui-lit 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/calendar-BuJgwvZx.js +254 -0
- package/{calendar.element-DcnTyvfg.js → calendar.element-M5MPJmap.js} +1 -1
- package/{currency.element-5GSakkxF.js → currency.element-CfFrAtrr.js} +4 -1
- package/{date-CDUlLuYy.js → date-Bj9mI3GU.js} +80 -29
- package/date-input-cJDkNnVw.js +184 -0
- package/date-picker.element-va_-LGZD.js +312 -0
- package/date-time-calendar-BzRfkLKU.js +361 -0
- package/date-time-calendar.element-DC4NK0y1.js +93 -0
- package/date-time-input-BXxsfuyZ.js +214 -0
- package/date-time-picker.element-Dy-8cb-_.js +380 -0
- package/date-time.element-Bv4XdzMi.js +87 -0
- package/{date.element-BZO0UQez.js → date.element-Consgsbb.js} +32 -27
- package/day-status-0-hJHrI7.js +530 -0
- package/{dropdown.element-CyJbVAA5.js → dropdown.element-WsD61Qel.js} +46 -36
- package/focus-leave.controller-2gV0pQd5.js +73 -0
- package/index.js +1199 -971
- package/index.umd.cjs +1582 -530
- package/lib/components/date-picker.element.d.ts +0 -11
- package/lib/components/date-time-calendar.element.d.ts +18 -0
- package/lib/components/date-time-picker.element.d.ts +18 -0
- package/lib/components/date-time.element.d.ts +18 -0
- package/lib/components/dropdown.element.d.ts +2 -0
- package/lib/components/range-calendar.element.d.ts +2 -1
- package/lib/components/range-date-picker.element.d.ts +0 -15
- package/lib/components/range-date-time-calendar.element.d.ts +18 -0
- package/lib/components/range-date-time-input.element.d.ts +18 -0
- package/lib/components/range-date-time-picker.element.d.ts +18 -0
- package/lib/components/range-time-input.element.d.ts +18 -0
- package/lib/components/range-time-picker.element.d.ts +18 -0
- package/lib/components/time-picker.element.d.ts +18 -0
- package/lib/components/time.element.d.ts +18 -0
- package/{list-D1oKnH89.js → list-CrLIL4by.js} +76 -61
- package/{list.element-Co3V3Cn5.js → list.element-DV82YxnJ.js} +22 -22
- package/package.json +6 -6
- package/part-templates-Db871PS3.js +677 -0
- package/pill-ranges-DCqDmpkk.js +48 -0
- package/{pills-B66qz_KX.js → pills-Be1UrLgq.js} +4 -1
- package/popup.controller-eUDxE6jD.js +71 -0
- package/range-calendar-CKPYeSGt.js +452 -0
- package/{range-calendar.element-_1bHW_c1.js → range-calendar.element-D6KYq18B.js} +24 -20
- package/range-commit-8-MmYUyo.js +14 -0
- package/range-date-input-D--AqBMv.js +292 -0
- package/{range-date-input.element-BqzAF0O3.js → range-date-input.element-D4nIXJbw.js} +8 -7
- package/range-date-picker.element-dhxPAAE6.js +386 -0
- package/range-date-time-calendar-yksWrR7b.js +720 -0
- package/range-date-time-calendar.element-C00aDefZ.js +95 -0
- package/range-date-time-input-B37TUoM3.js +322 -0
- package/range-date-time-input.element-DUnbv4ed.js +81 -0
- package/range-date-time-picker.element-Cbps6s_G.js +412 -0
- package/range-selection-CU3hxLJE.js +25 -0
- package/range-time-input-3lhqR1Ku.js +329 -0
- package/range-time-input.element-dU2iBdmJ.js +81 -0
- package/range-time-picker.element-v6nQsIPw.js +429 -0
- package/{select.element-jcDF1h-g.js → select.element-C0V-Bv3L.js} +94 -90
- package/{tags.element-CX3vQL8L.js → tags.element-DvwEpxpK.js} +1 -1
- package/time-input-BOhlBGJZ.js +181 -0
- package/time-list-Czo48bZm.js +217 -0
- package/time-picker-bFJ63ky8.js +261 -0
- package/time-picker.element-CYZVXgRS.js +85 -0
- package/time.element-fK3oLi49.js +82 -0
- package/abstract-calendar-D0-077XJ.js +0 -545
- package/calendar-BclCC9VJ.js +0 -96
- package/date-input-DCdGWRio.js +0 -268
- package/date-picker.element-k7AJFQ5W.js +0 -168
- package/range-calendar-CBINu84w.js +0 -255
- package/range-date-input-BYXzqnr1.js +0 -395
- package/range-date-picker.element-BCBefgvY.js +0 -182
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/gui-lit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.umd.cjs",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"*.md"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@golemui/lit": "1.0
|
|
26
|
-
"@golemui/core": "1.0
|
|
27
|
-
"@golemui/gui-components": "1.0
|
|
28
|
-
"@golemui/gui-shared": "1.0
|
|
29
|
-
"@golemui/gui-validators": "1.0
|
|
25
|
+
"@golemui/lit": "1.1.0",
|
|
26
|
+
"@golemui/core": "1.1.0",
|
|
27
|
+
"@golemui/gui-components": "1.1.0",
|
|
28
|
+
"@golemui/gui-shared": "1.1.0",
|
|
29
|
+
"@golemui/gui-validators": "1.1.0",
|
|
30
30
|
"@lit/context": "^1.1.6",
|
|
31
31
|
"lit-html": "^3.3.1",
|
|
32
32
|
"lit": "^3.3.1",
|
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import { html as D, nothing as N } from "lit";
|
|
2
|
+
import { p as b, o as V, q as C, I as O, a as R, s as v, u as x, t as B } from "./date-Bj9mI3GU.js";
|
|
3
|
+
import { live as H } from "lit/directives/live.js";
|
|
4
|
+
import { repeat as T } from "lit-html/directives/repeat.js";
|
|
5
|
+
const A = new Date(2025, 0, 15, 9, 5, 0);
|
|
6
|
+
function K(n, t) {
|
|
7
|
+
if (t === "12" || t === "24") return t;
|
|
8
|
+
const { hourCycle: r } = new Intl.DateTimeFormat(n ?? "en", {
|
|
9
|
+
hour: "numeric"
|
|
10
|
+
}).resolvedOptions();
|
|
11
|
+
return r === "h11" || r === "h12" ? "12" : "24";
|
|
12
|
+
}
|
|
13
|
+
function ut(n, t) {
|
|
14
|
+
return new Intl.DateTimeFormat(n ?? "en", {
|
|
15
|
+
hour: "numeric",
|
|
16
|
+
minute: "numeric",
|
|
17
|
+
hourCycle: t === "12" ? "h12" : "h23"
|
|
18
|
+
}).formatToParts(A);
|
|
19
|
+
}
|
|
20
|
+
function ct(n, t) {
|
|
21
|
+
return new Intl.DateTimeFormat(n ?? "en", {
|
|
22
|
+
year: "numeric",
|
|
23
|
+
month: "numeric",
|
|
24
|
+
day: "numeric",
|
|
25
|
+
hour: "numeric",
|
|
26
|
+
minute: "numeric",
|
|
27
|
+
hourCycle: t === "12" ? "h12" : "h23"
|
|
28
|
+
}).formatToParts(A);
|
|
29
|
+
}
|
|
30
|
+
function U(n) {
|
|
31
|
+
const t = new Intl.DateTimeFormat(n ?? "en", {
|
|
32
|
+
hour: "numeric",
|
|
33
|
+
hourCycle: "h12"
|
|
34
|
+
}), r = (e) => t.formatToParts(new Date(2025, 0, 15, e, 0, 0)).find((s) => s.type === "dayPeriod")?.value ?? "";
|
|
35
|
+
return { am: r(9) || "AM", pm: r(21) || "PM" };
|
|
36
|
+
}
|
|
37
|
+
function I(n) {
|
|
38
|
+
const t = n.getFullYear(), r = String(n.getMonth() + 1).padStart(2, "0"), e = String(n.getDate()).padStart(2, "0"), s = String(n.getHours()).padStart(2, "0"), i = String(n.getMinutes()).padStart(2, "0"), a = String(n.getSeconds()).padStart(2, "0");
|
|
39
|
+
return `${t}-${r}-${e}T${s}:${i}:${a}`;
|
|
40
|
+
}
|
|
41
|
+
function S(n) {
|
|
42
|
+
const t = String(n.getHours()).padStart(2, "0"), r = String(n.getMinutes()).padStart(2, "0"), e = String(n.getSeconds()).padStart(2, "0");
|
|
43
|
+
return `${t}:${r}:${e}`;
|
|
44
|
+
}
|
|
45
|
+
function P(n) {
|
|
46
|
+
const t = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/.exec(n);
|
|
47
|
+
return t ? {
|
|
48
|
+
hours: Number(t[1]),
|
|
49
|
+
minutes: Number(t[2]),
|
|
50
|
+
seconds: Number(t[3] ?? 0)
|
|
51
|
+
} : null;
|
|
52
|
+
}
|
|
53
|
+
function l(n) {
|
|
54
|
+
const t = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2}))?)?$/.exec(n);
|
|
55
|
+
return t ? new Date(
|
|
56
|
+
Number(t[1]),
|
|
57
|
+
Number(t[2]) - 1,
|
|
58
|
+
Number(t[3]),
|
|
59
|
+
Number(t[4] ?? 0),
|
|
60
|
+
Number(t[5] ?? 0),
|
|
61
|
+
Number(t[6] ?? 0)
|
|
62
|
+
) : new Date(n);
|
|
63
|
+
}
|
|
64
|
+
const lt = "No available times";
|
|
65
|
+
function f(n, t) {
|
|
66
|
+
const r = (i) => i.length === 5 ? `${i}:00` : i, e = r(n), s = r(t);
|
|
67
|
+
return e < s ? -1 : e > s ? 1 : 0;
|
|
68
|
+
}
|
|
69
|
+
function dt(n, t) {
|
|
70
|
+
const r = P(n);
|
|
71
|
+
if (!r) return;
|
|
72
|
+
const e = r.hours * 60 + r.minutes + (t || 30);
|
|
73
|
+
if (!(e >= 1440))
|
|
74
|
+
return S(new Date(1970, 0, 1, Math.floor(e / 60), e % 60, 0));
|
|
75
|
+
}
|
|
76
|
+
function mt(n, t) {
|
|
77
|
+
if (!n?.length) return [];
|
|
78
|
+
const r = b(t).getDay();
|
|
79
|
+
return n.filter(
|
|
80
|
+
(e) => (e.date == null || e.date === t) && (e.weekdays == null || e.weekdays.includes(r))
|
|
81
|
+
).map(({ start: e, end: s }) => ({ start: e, end: s }));
|
|
82
|
+
}
|
|
83
|
+
function q(n, t) {
|
|
84
|
+
return t?.length ? t.some(
|
|
85
|
+
(r) => f(n, r.start) >= 0 && f(n, r.end ?? r.start) <= 0
|
|
86
|
+
) : !1;
|
|
87
|
+
}
|
|
88
|
+
function ht(n, t, r) {
|
|
89
|
+
if (!r?.length) return !1;
|
|
90
|
+
const e = t ?? n;
|
|
91
|
+
return r.some((s) => {
|
|
92
|
+
const i = s.end ?? s.start;
|
|
93
|
+
return f(n, i) <= 0 && f(s.start, e) <= 0;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function E(n) {
|
|
97
|
+
return n.length === 5 ? `${n}:00` : n;
|
|
98
|
+
}
|
|
99
|
+
function ft(n) {
|
|
100
|
+
if (!n.length) return [];
|
|
101
|
+
const t = n.map((e) => ({ start: E(e.start), end: E(e.end ?? e.start) })).sort((e, s) => f(e.start, s.start)), r = [];
|
|
102
|
+
for (const e of t) {
|
|
103
|
+
const s = r[r.length - 1];
|
|
104
|
+
s && f(e.start, s.end) <= 0 ? f(e.end, s.end) > 0 && (s.end = e.end) : r.push({ ...e });
|
|
105
|
+
}
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
function pt(n, t) {
|
|
109
|
+
return l(n).getTime() <= l(t).getTime() ? { start: n, end: t } : { start: t, end: n };
|
|
110
|
+
}
|
|
111
|
+
function gt(n) {
|
|
112
|
+
if (!n.length) return [];
|
|
113
|
+
const t = n.map((e) => ({
|
|
114
|
+
start: l(e.start).getTime(),
|
|
115
|
+
end: l(e.end ?? e.start).getTime()
|
|
116
|
+
})).sort((e, s) => e.start - s.start), r = [];
|
|
117
|
+
for (const e of t) {
|
|
118
|
+
const s = r[r.length - 1];
|
|
119
|
+
s && e.start <= s.end ? e.end > s.end && (s.end = e.end) : r.push({ start: e.start, end: e.end });
|
|
120
|
+
}
|
|
121
|
+
return r.map((e) => ({
|
|
122
|
+
start: I(new Date(e.start)),
|
|
123
|
+
end: I(new Date(e.end))
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
function yt(n, t) {
|
|
127
|
+
if (!t?.length) return !1;
|
|
128
|
+
const r = l(n.start).getTime(), e = l(n.end ?? n.start).getTime();
|
|
129
|
+
return t.some((s) => {
|
|
130
|
+
const i = l(s.start).getTime(), a = l(s.end ?? s.start).getTime();
|
|
131
|
+
return r < a && i < e;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function St(n, t) {
|
|
135
|
+
if (!t?.length) return !1;
|
|
136
|
+
const r = l(`${n}T00:00:00`).getTime(), e = l(`${n}T23:59:59`).getTime();
|
|
137
|
+
return t.some((s) => {
|
|
138
|
+
const i = l(s.start).getTime(), a = l(s.end ?? s.start).getTime();
|
|
139
|
+
return i <= r && a >= e;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function Tt(n, t) {
|
|
143
|
+
if (!n?.length) return [];
|
|
144
|
+
const r = l(`${t}T00:00:00`).getTime(), e = l(`${t}T23:59:59`).getTime(), s = [];
|
|
145
|
+
for (const i of n) {
|
|
146
|
+
const a = l(i.start).getTime(), o = l(i.end ?? i.start).getTime();
|
|
147
|
+
if (o < r || a > e) continue;
|
|
148
|
+
const u = a <= r ? "00:00:00" : S(new Date(a)), c = o >= e ? "23:59:59" : S(new Date(o));
|
|
149
|
+
s.push({ start: u, end: c });
|
|
150
|
+
}
|
|
151
|
+
return s;
|
|
152
|
+
}
|
|
153
|
+
function Dt(n) {
|
|
154
|
+
const t = n.minuteStep || 30, r = P(n.minTime ?? "") ?? { hours: 0, minutes: 0, seconds: 0 }, e = S(new Date(1970, 0, 1, r.hours, r.minutes, r.seconds)), s = n.maxTime ?? "23:59:59", i = [];
|
|
155
|
+
for (let a = r.hours * 60 + r.minutes; a < 1440; a += t) {
|
|
156
|
+
const o = S(
|
|
157
|
+
new Date(1970, 0, 1, Math.floor(a / 60), a % 60, 0)
|
|
158
|
+
);
|
|
159
|
+
if (f(o, s) > 0) break;
|
|
160
|
+
f(o, e) < 0 || i.push({ value: o, disabled: q(o, n.disabledRanges) });
|
|
161
|
+
}
|
|
162
|
+
return i;
|
|
163
|
+
}
|
|
164
|
+
function Pt(n, t, r) {
|
|
165
|
+
const e = P(n);
|
|
166
|
+
return e ? new Intl.DateTimeFormat(t ?? "en", {
|
|
167
|
+
hour: "numeric",
|
|
168
|
+
minute: "numeric",
|
|
169
|
+
hourCycle: r === "12" ? "h12" : "h23"
|
|
170
|
+
}).format(new Date(2025, 0, 15, e.hours, e.minutes, e.seconds)) : n;
|
|
171
|
+
}
|
|
172
|
+
function _t(n, t, r) {
|
|
173
|
+
const e = l(n);
|
|
174
|
+
return isNaN(e.getTime()) ? n : new Intl.DateTimeFormat(t ?? "en", {
|
|
175
|
+
year: "numeric",
|
|
176
|
+
month: "2-digit",
|
|
177
|
+
day: "2-digit",
|
|
178
|
+
hour: "2-digit",
|
|
179
|
+
minute: "2-digit",
|
|
180
|
+
hour12: r === "12"
|
|
181
|
+
}).format(e);
|
|
182
|
+
}
|
|
183
|
+
function It(n, t, r, e) {
|
|
184
|
+
const s = l(n).getTime();
|
|
185
|
+
if (isNaN(s)) return null;
|
|
186
|
+
if (t) {
|
|
187
|
+
const i = l(t);
|
|
188
|
+
if (!isNaN(i.getTime()) && s < i.getTime())
|
|
189
|
+
return e?.minDateTimeMessage ?? V;
|
|
190
|
+
}
|
|
191
|
+
if (r) {
|
|
192
|
+
const i = l(r);
|
|
193
|
+
if (!isNaN(i.getTime()) && s > i.getTime())
|
|
194
|
+
return e?.maxDateTimeMessage ?? C;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function M(n, t) {
|
|
199
|
+
const r = n % 12;
|
|
200
|
+
return t === "pm" ? r + 12 : r;
|
|
201
|
+
}
|
|
202
|
+
function Y(n) {
|
|
203
|
+
const t = n >= 12 ? "pm" : "am";
|
|
204
|
+
return { hour12: n % 12 === 0 ? 12 : n % 12, period: t };
|
|
205
|
+
}
|
|
206
|
+
function W() {
|
|
207
|
+
return {
|
|
208
|
+
day: { type: "day", kind: "numeric", maxLength: 2, min: 1, max: 31, placeholder: "dd" },
|
|
209
|
+
month: { type: "month", kind: "numeric", maxLength: 2, min: 1, max: 12, placeholder: "mm" },
|
|
210
|
+
year: {
|
|
211
|
+
type: "year",
|
|
212
|
+
kind: "numeric",
|
|
213
|
+
maxLength: 4,
|
|
214
|
+
min: 1e3,
|
|
215
|
+
// TODO: Add a prop to set the default minimum year, like 1979 or 2000
|
|
216
|
+
max: 9999,
|
|
217
|
+
placeholder: "yyyy"
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function z(n, t, r) {
|
|
222
|
+
return {
|
|
223
|
+
hour: n === "12" ? {
|
|
224
|
+
type: "hour",
|
|
225
|
+
kind: "numeric",
|
|
226
|
+
maxLength: 2,
|
|
227
|
+
min: 1,
|
|
228
|
+
max: 12,
|
|
229
|
+
placeholder: "hh"
|
|
230
|
+
} : {
|
|
231
|
+
type: "hour",
|
|
232
|
+
kind: "numeric",
|
|
233
|
+
maxLength: 2,
|
|
234
|
+
min: 0,
|
|
235
|
+
max: 23,
|
|
236
|
+
placeholder: "hh",
|
|
237
|
+
incrementFallback: 0
|
|
238
|
+
},
|
|
239
|
+
minute: {
|
|
240
|
+
type: "minute",
|
|
241
|
+
kind: "numeric",
|
|
242
|
+
maxLength: 2,
|
|
243
|
+
min: 0,
|
|
244
|
+
max: 59,
|
|
245
|
+
placeholder: "mm",
|
|
246
|
+
step: t,
|
|
247
|
+
incrementFallback: 0,
|
|
248
|
+
wrap: !0
|
|
249
|
+
},
|
|
250
|
+
dayPeriod: {
|
|
251
|
+
type: "dayPeriod",
|
|
252
|
+
kind: "dayPeriod",
|
|
253
|
+
maxLength: 8,
|
|
254
|
+
min: 0,
|
|
255
|
+
max: 0,
|
|
256
|
+
placeholder: r
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function G(n, t, r) {
|
|
261
|
+
return n[t]?.[r] ?? "";
|
|
262
|
+
}
|
|
263
|
+
function L(n, t, r, e) {
|
|
264
|
+
return { ...n, [t]: { ...n[t], [r]: e } };
|
|
265
|
+
}
|
|
266
|
+
function j(n, t) {
|
|
267
|
+
return { ...n, [t]: {} };
|
|
268
|
+
}
|
|
269
|
+
function X(n, t, r) {
|
|
270
|
+
if (r !== "12") return n;
|
|
271
|
+
let e = n;
|
|
272
|
+
for (const s of t)
|
|
273
|
+
G(e, s, "dayPeriod") || (e = L(e, s, "dayPeriod", "am"));
|
|
274
|
+
return e;
|
|
275
|
+
}
|
|
276
|
+
function J(n, t) {
|
|
277
|
+
if (isNaN(t)) return { value: t };
|
|
278
|
+
if (!n) return { value: t };
|
|
279
|
+
const r = Math.max(n.min, Math.min(n.max, t));
|
|
280
|
+
return r === t ? { value: t } : {
|
|
281
|
+
value: r,
|
|
282
|
+
writeBack: r.toString().padStart(n.maxLength ?? 2, "0")
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function p(n, t, r, e) {
|
|
286
|
+
const s = parseInt(n[r] ?? "", 10), { value: i, writeBack: a } = J(t[r], s);
|
|
287
|
+
return a !== void 0 && (e[r] = a), i;
|
|
288
|
+
}
|
|
289
|
+
function kt(n, t) {
|
|
290
|
+
const r = {}, e = p(n, t.descriptors, "year", r), s = p(n, t.descriptors, "month", r), i = p(n, t.descriptors, "day", r), a = !isNaN(e) && String(e).length === 4, o = !isNaN(s) && s > 0, u = !isNaN(i) && i > 0;
|
|
291
|
+
if (!(a && o && u))
|
|
292
|
+
return { result: { kind: "incomplete" }, writeBacks: r };
|
|
293
|
+
if (i > v(s, e))
|
|
294
|
+
return {
|
|
295
|
+
result: { kind: "invalid", message: t.invalidDateMessage ?? x },
|
|
296
|
+
writeBacks: r
|
|
297
|
+
};
|
|
298
|
+
const c = new Date(e, s - 1, i);
|
|
299
|
+
return { result: { kind: "valid", iso: B(c), instant: c }, writeBacks: r };
|
|
300
|
+
}
|
|
301
|
+
function $t(n, t) {
|
|
302
|
+
const r = t.hourFormat === "12", e = {}, s = p(n, t.descriptors, "hour", e), i = p(n, t.descriptors, "minute", e), a = n.dayPeriod ?? "";
|
|
303
|
+
if (isNaN(s) || isNaN(i)) return { result: { kind: "incomplete" }, writeBacks: e };
|
|
304
|
+
if (r && a !== "am" && a !== "pm")
|
|
305
|
+
return { result: { kind: "incomplete" }, writeBacks: e };
|
|
306
|
+
const o = r ? M(s, a) : s, u = new Date(1970, 0, 1, o, i, 0);
|
|
307
|
+
return { result: { kind: "valid", iso: S(u), instant: u }, writeBacks: e };
|
|
308
|
+
}
|
|
309
|
+
function Et(n, t) {
|
|
310
|
+
const r = t.hourFormat === "12", e = {}, s = p(n, t.descriptors, "year", e), i = p(n, t.descriptors, "month", e), a = p(n, t.descriptors, "day", e), o = p(n, t.descriptors, "hour", e), u = p(n, t.descriptors, "minute", e), c = n.dayPeriod ?? "", d = !isNaN(s) && String(s).length === 4, m = !isNaN(i) && i > 0, h = !isNaN(a) && a > 0, g = !isNaN(o), y = !isNaN(u);
|
|
311
|
+
if (!(d && m && h && g && y && (!r || c === "am" || c === "pm")))
|
|
312
|
+
return { result: { kind: "incomplete" }, writeBacks: e };
|
|
313
|
+
if (a > v(i, s))
|
|
314
|
+
return {
|
|
315
|
+
result: { kind: "invalid", message: t.invalidDateMessage ?? x },
|
|
316
|
+
writeBacks: e
|
|
317
|
+
};
|
|
318
|
+
const _ = r ? M(o, c) : o, $ = new Date(s, i - 1, a, _, u, 0);
|
|
319
|
+
return { result: { kind: "valid", iso: I($), instant: $ }, writeBacks: e };
|
|
320
|
+
}
|
|
321
|
+
function wt(n, t) {
|
|
322
|
+
return t.minTime && f(n, t.minTime) < 0 ? t.minTimeMessage ?? O : t.maxTime && f(n, t.maxTime) > 0 ? t.maxTimeMessage ?? R : null;
|
|
323
|
+
}
|
|
324
|
+
const Q = [
|
|
325
|
+
"Backspace",
|
|
326
|
+
"Tab",
|
|
327
|
+
"ArrowUp",
|
|
328
|
+
"ArrowDown",
|
|
329
|
+
"ArrowLeft",
|
|
330
|
+
"ArrowRight",
|
|
331
|
+
"Delete",
|
|
332
|
+
"Enter"
|
|
333
|
+
];
|
|
334
|
+
function F(n) {
|
|
335
|
+
return /^[0-9]$/.test(n);
|
|
336
|
+
}
|
|
337
|
+
function Z(n, t) {
|
|
338
|
+
return Q.includes(n.key) || n.ctrlKey || n.metaKey || t ? !1 : !F(n.key);
|
|
339
|
+
}
|
|
340
|
+
function tt(n, t, r) {
|
|
341
|
+
const e = n?.step ?? 1, s = n?.incrementFallback ?? 1, i = r === "up" ? e : -e, a = parseInt(t, 10);
|
|
342
|
+
let o;
|
|
343
|
+
if (isNaN(a))
|
|
344
|
+
o = s;
|
|
345
|
+
else if (o = a + i, n?.wrap) {
|
|
346
|
+
const u = n.max - n.min + 1;
|
|
347
|
+
o = ((o - n.min) % u + u) % u + n.min;
|
|
348
|
+
} else n && (o = Math.max(n.min, Math.min(n.max, o)));
|
|
349
|
+
return o.toString().padStart(n?.maxLength ?? 2, "0");
|
|
350
|
+
}
|
|
351
|
+
const w = /* @__PURE__ */ new Map();
|
|
352
|
+
function Nt(n, t, r, e = !1) {
|
|
353
|
+
const s = r || 1, i = `${n ?? ""}|${t ?? ""}|${s}|${e ? "dt" : "t"}`, a = w.get(i);
|
|
354
|
+
if (a) return a;
|
|
355
|
+
const o = K(n, t), u = U(n), c = z(o, s, u.am), d = e ? { ...W(), ...c } : c, m = { effectiveHourFormat: o, dayPeriodLabels: u, descriptors: d };
|
|
356
|
+
return w.set(i, m), m;
|
|
357
|
+
}
|
|
358
|
+
class bt {
|
|
359
|
+
constructor(t, r) {
|
|
360
|
+
this._values = {}, this._hasSurfacedInputError = !1, this.getPartDisplay = (e, s) => {
|
|
361
|
+
const i = this.getPart(e, s);
|
|
362
|
+
if (s === "dayPeriod" && (i === "am" || i === "pm")) {
|
|
363
|
+
const a = this.options.getDayPeriodLabels?.();
|
|
364
|
+
if (a) return a[i];
|
|
365
|
+
}
|
|
366
|
+
return i;
|
|
367
|
+
}, this.handleKeyDown = (e, s, i) => {
|
|
368
|
+
e.key === "Enter" && this.options.onEnter && (e.preventDefault(), e.target instanceof HTMLInputElement && this.setPart(s, i, e.target.value.replace(/[^0-9]/g, ""))), Z(e, this.options.isReadonly()) && e.preventDefault();
|
|
369
|
+
}, this.handleDayPeriodKeyDown = (e) => {
|
|
370
|
+
(e.key === "ArrowUp" || e.key === "ArrowDown") && e.preventDefault(), e.key === "Enter" && e.preventDefault();
|
|
371
|
+
}, this.handleFocus = (e) => {
|
|
372
|
+
this.host.dispatchEvent(new CustomEvent("focus", { detail: e }));
|
|
373
|
+
}, this.handleKeyUp = (e, s, i) => {
|
|
374
|
+
if (this.options.isReadonly()) return;
|
|
375
|
+
const a = window.getComputedStyle(this.host).direction === "rtl", o = e.target, u = o, c = this.getGroupInputs(s), d = c.indexOf(o), m = this.options.getDescriptor(i);
|
|
376
|
+
switch (o instanceof HTMLInputElement && u.value.length === u.maxLength && F(e.key) && (d === c.length - 1 ? this.autoAdvanceFromGroupEnd(s) : c[d + 1].focus()), e.key) {
|
|
377
|
+
case "Enter": {
|
|
378
|
+
this.options.onEnter?.(e, s);
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
case "ArrowUp":
|
|
382
|
+
case "ArrowDown": {
|
|
383
|
+
if (m?.kind === "dayPeriod") {
|
|
384
|
+
this.toggleDayPeriod(s, i);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
const h = tt(
|
|
388
|
+
m,
|
|
389
|
+
u.value,
|
|
390
|
+
e.key === "ArrowUp" ? "up" : "down"
|
|
391
|
+
);
|
|
392
|
+
this.setPart(s, i, h), this.selectPart(o), this.options.commitGroup(s);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case "ArrowLeft":
|
|
396
|
+
case "ArrowRight": {
|
|
397
|
+
const h = [...c].sort(
|
|
398
|
+
(k, _) => k.getBoundingClientRect().left - _.getBoundingClientRect().left
|
|
399
|
+
), g = h.indexOf(o), y = e.key === "ArrowRight" ? g + 1 : g - 1;
|
|
400
|
+
y >= 0 && y < h.length ? (h[y].focus(), this.selectPart(h[y])) : this.navigatePastGroupEdge(e.key, s, a);
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}, this.handleChange = (e, s, i) => {
|
|
405
|
+
if (e.stopImmediatePropagation(), this.options.isReadonly() || this.options.getDescriptor(i)?.kind === "dayPeriod") return;
|
|
406
|
+
const u = e.target.value.replace(/[^0-9]/g, "");
|
|
407
|
+
this.setPart(s, i, u), this.options.commitGroup(s);
|
|
408
|
+
}, this.handleBlur = (e, s, i) => {
|
|
409
|
+
const a = this.options.getDescriptor(i);
|
|
410
|
+
if (a?.kind !== "dayPeriod") {
|
|
411
|
+
const o = e.target, u = parseInt(o.value, 10);
|
|
412
|
+
!isNaN(u) && (u > 0 || a?.min === 0) ? o.value = u.toString().padStart(a?.maxLength ?? 2, "0") : this.options.onEmptyPartBlur();
|
|
413
|
+
}
|
|
414
|
+
this.host.dispatchEvent(new CustomEvent("blur"));
|
|
415
|
+
}, this.toggleDayPeriod = (e, s) => {
|
|
416
|
+
if (this.options.isReadonly() || this.options.isDisabled()) return;
|
|
417
|
+
const i = this.getPart(e, s);
|
|
418
|
+
this.setPart(e, s, i === "am" ? "pm" : "am"), this.options.commitGroup(e);
|
|
419
|
+
}, this.host = t, this.options = r, t.addController(this);
|
|
420
|
+
}
|
|
421
|
+
hostConnected() {
|
|
422
|
+
}
|
|
423
|
+
get values() {
|
|
424
|
+
return this._values;
|
|
425
|
+
}
|
|
426
|
+
getPart(t, r) {
|
|
427
|
+
return G(this._values, t, r);
|
|
428
|
+
}
|
|
429
|
+
setPart(t, r, e) {
|
|
430
|
+
this._values = L(this._values, t, r, e), this.host.requestUpdate();
|
|
431
|
+
}
|
|
432
|
+
clearGroup(t) {
|
|
433
|
+
this._values = j(this._values, t), this.host.requestUpdate();
|
|
434
|
+
}
|
|
435
|
+
/** Writes clamp corrections back into the state. */
|
|
436
|
+
applyWriteBacks(t, r) {
|
|
437
|
+
for (const [e, s] of Object.entries(r))
|
|
438
|
+
s !== void 0 && this.setPart(t, e, s);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Seeds each group's day-period toggle to 'am' when the effective format is
|
|
442
|
+
* 12h (the twins' seedDayPeriods). Requests an update only when something
|
|
443
|
+
* was actually seeded, matching the conditional setPartValue calls.
|
|
444
|
+
*
|
|
445
|
+
* @param {readonly string[]} [groups] - The groups to seed; defaults to all.
|
|
446
|
+
*/
|
|
447
|
+
seedDayPeriods(t = this.options.groups) {
|
|
448
|
+
this.seedWith(t, this.options.getHourFormat?.() ?? "24");
|
|
449
|
+
}
|
|
450
|
+
seedWith(t, r) {
|
|
451
|
+
const e = X(this._values, t, r);
|
|
452
|
+
e !== this._values && (this._values = e, this.host.requestUpdate());
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Seeds a group's parts from an ISO value; a null/empty value clears the
|
|
456
|
+
* group (re-seeding its day period for time-aware shapes) and an
|
|
457
|
+
* unparseable one leaves the state untouched.
|
|
458
|
+
*
|
|
459
|
+
* @param {string} group - The group to seed.
|
|
460
|
+
* @param {string | null} iso - The ISO value, or null/'' to clear.
|
|
461
|
+
* @param {GroupSeedShape} shape - Which parts the value carries.
|
|
462
|
+
* @param {HourFormat} [hourFormat] - The effective hour format; defaults to
|
|
463
|
+
* the `getHourFormat` option (then '24').
|
|
464
|
+
*/
|
|
465
|
+
setGroupFromISO(t, r, e, s) {
|
|
466
|
+
const i = s ?? this.options.getHourFormat?.() ?? "24";
|
|
467
|
+
if (!r) {
|
|
468
|
+
this.clearGroup(t), e !== "date" && this.seedWith([t], i);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (e === "date") {
|
|
472
|
+
const o = b(r);
|
|
473
|
+
if (isNaN(o.getTime())) return;
|
|
474
|
+
this.setPart(t, "year", String(o.getFullYear()).padStart(4, "0")), this.setPart(t, "month", String(o.getMonth() + 1).padStart(2, "0")), this.setPart(t, "day", String(o.getDate()).padStart(2, "0"));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (e === "time") {
|
|
478
|
+
let o = P(r);
|
|
479
|
+
if (!o) {
|
|
480
|
+
const u = l(r);
|
|
481
|
+
if (isNaN(u.getTime())) return;
|
|
482
|
+
o = { hours: u.getHours(), minutes: u.getMinutes(), seconds: u.getSeconds() };
|
|
483
|
+
}
|
|
484
|
+
this.writeTimeParts(t, o.hours, o.minutes, i);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const a = l(r);
|
|
488
|
+
isNaN(a.getTime()) || (this.setPart(t, "day", String(a.getDate()).padStart(2, "0")), this.setPart(t, "month", String(a.getMonth() + 1).padStart(2, "0")), this.setPart(t, "year", String(a.getFullYear()).padStart(4, "0")), this.writeTimeParts(t, a.getHours(), a.getMinutes(), i));
|
|
489
|
+
}
|
|
490
|
+
writeTimeParts(t, r, e, s) {
|
|
491
|
+
if (s === "12") {
|
|
492
|
+
const { hour12: i, period: a } = Y(r);
|
|
493
|
+
this.setPart(t, "hour", i.toString().padStart(2, "0")), this.setPart(t, "dayPeriod", a);
|
|
494
|
+
} else
|
|
495
|
+
this.setPart(t, "hour", r.toString().padStart(2, "0"));
|
|
496
|
+
this.setPart(t, "minute", e.toString().padStart(2, "0"));
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Focusable part elements of a group in DOM order. Numeric parts are
|
|
500
|
+
* inputs; dayPeriod parts are toggle buttons.
|
|
501
|
+
*/
|
|
502
|
+
getGroupInputs(t) {
|
|
503
|
+
return this.options.groups.length > 1 ? Array.from(this.host.querySelectorAll(`[data-group="${t}"]`)) : Array.from(this.host.querySelectorAll(`.${this.options.blockClass}__part`));
|
|
504
|
+
}
|
|
505
|
+
/** Selects an input's text; a no-op for non-input parts (the toggle button). */
|
|
506
|
+
selectPart(t) {
|
|
507
|
+
t instanceof HTMLInputElement && t.select();
|
|
508
|
+
}
|
|
509
|
+
focusFirst(t) {
|
|
510
|
+
requestAnimationFrame(() => {
|
|
511
|
+
this.getGroupInputs(t)[0]?.focus();
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Auto-advance past the last input of a group, or into the next
|
|
516
|
+
* group's first input, if it has more than one group (like ranged inputs).
|
|
517
|
+
*/
|
|
518
|
+
autoAdvanceFromGroupEnd(t) {
|
|
519
|
+
const r = this.options.groups;
|
|
520
|
+
if (r.length > 1) {
|
|
521
|
+
const e = r[r.indexOf(t) + 1];
|
|
522
|
+
e !== void 0 && this.getGroupInputs(e)[0]?.focus();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
this.getGroupInputs(t)[0]?.focus();
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* ArrowLeft/ArrowRight past a group's visual edge.
|
|
529
|
+
*/
|
|
530
|
+
navigatePastGroupEdge(t, r, e) {
|
|
531
|
+
const s = this.options.groups;
|
|
532
|
+
if (s.length <= 1) return;
|
|
533
|
+
const i = s[0], a = s[s.length - 1];
|
|
534
|
+
if (t === "ArrowLeft") {
|
|
535
|
+
const o = e ? a : i;
|
|
536
|
+
if (r !== o) {
|
|
537
|
+
const u = this.getGroupInputs(o), c = u[u.length - 1];
|
|
538
|
+
c && (c.focus(), this.selectPart(c));
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
const o = e ? i : a;
|
|
542
|
+
if (r !== o) {
|
|
543
|
+
const u = this.getGroupInputs(o);
|
|
544
|
+
u[0] && (u[0].focus(), this.selectPart(u[0]));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/** Whether an inputError has been surfaced and not yet cleared. */
|
|
549
|
+
get hasSurfacedInputError() {
|
|
550
|
+
return this._hasSurfacedInputError;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Surfaces an inputError through `onInputErrorSurfaced` and remembers it so
|
|
554
|
+
* it can later be cleared.
|
|
555
|
+
*/
|
|
556
|
+
surfaceInputError(t) {
|
|
557
|
+
this._hasSurfacedInputError = !0, this.options.onInputErrorSurfaced?.(t);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Clears a previously-surfaced inputError by echoing the given (unchanged)
|
|
561
|
+
* value through `onSurfacedErrorCleared`; a no-op when nothing is surfaced.
|
|
562
|
+
*/
|
|
563
|
+
clearSurfacedInputError(t) {
|
|
564
|
+
this._hasSurfacedInputError && (this._hasSurfacedInputError = !1, this.options.onSurfacedErrorCleared?.(t));
|
|
565
|
+
}
|
|
566
|
+
resetSurfacedInputError() {
|
|
567
|
+
this._hasSurfacedInputError = !1;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const et = (n, t) => D`<span class="${t}__separator">${n.value}</span>`;
|
|
571
|
+
function vt(n, t, r) {
|
|
572
|
+
const e = t.formatParts, s = t.groups.length > 1, i = (d) => s ? `${n}-${d.type}` : d.type, a = (d, m) => {
|
|
573
|
+
if (d.type === "literal")
|
|
574
|
+
return et(d, t.blockClass);
|
|
575
|
+
const h = t.getDescriptor(d.type);
|
|
576
|
+
if (!h) return "";
|
|
577
|
+
const g = n === t.groups[0] && m === 0 ? 0 : -1;
|
|
578
|
+
return nt(n, h, g, t, r);
|
|
579
|
+
}, o = (d) => d.type === "hour" || d.type === "minute" || d.type === "second", u = e.findIndex(o);
|
|
580
|
+
if (u === -1)
|
|
581
|
+
return T(e, i, a);
|
|
582
|
+
let c = e.length - 1;
|
|
583
|
+
for (; !o(e[c]); ) c--;
|
|
584
|
+
return D`
|
|
585
|
+
${T(e.slice(0, u), i, a)}
|
|
586
|
+
<div class="gui-parts__time-cluster ${t.blockClass}__time-cluster" dir="ltr">
|
|
587
|
+
${T(e.slice(u, c + 1), i, (d, m) => a(d, u + m))}
|
|
588
|
+
</div>
|
|
589
|
+
${T(e.slice(c + 1), i, (d, m) => a(d, c + 1 + m))}
|
|
590
|
+
`;
|
|
591
|
+
}
|
|
592
|
+
function nt(n, t, r, e, s) {
|
|
593
|
+
const i = e.blockClass, a = t.type;
|
|
594
|
+
if (t.kind === "dayPeriod")
|
|
595
|
+
return rt(n, t, r, e, s);
|
|
596
|
+
const o = a === "year" ? `gui-parts__year ${i}__year` : "";
|
|
597
|
+
return D`
|
|
598
|
+
<div class="gui-parts__touch-target ${i}__touch-target">
|
|
599
|
+
<input
|
|
600
|
+
type="text"
|
|
601
|
+
inputmode="numeric"
|
|
602
|
+
class="gui-parts__part ${i}__part ${o}"
|
|
603
|
+
data-type=${a}
|
|
604
|
+
data-group=${e.groups.length > 1 ? n : N}
|
|
605
|
+
maxlength=${t.maxLength}
|
|
606
|
+
placeholder=${t.placeholder}
|
|
607
|
+
tabindex=${r}
|
|
608
|
+
?required=${e.required}
|
|
609
|
+
?disabled=${e.disabled}
|
|
610
|
+
?readonly=${e.partsReadonly}
|
|
611
|
+
autocomplete="off"
|
|
612
|
+
.value=${H(e.getDisplayValue(n, a))}
|
|
613
|
+
@keydown=${(u) => s.handleKeyDown(u, n, a)}
|
|
614
|
+
@keyup=${(u) => s.handleKeyUp(u, n, a)}
|
|
615
|
+
@focus=${s.handleFocus}
|
|
616
|
+
@blur=${(u) => s.handleBlur(u, n, a)}
|
|
617
|
+
@change=${(u) => s.handleChange(u, n, a)}
|
|
618
|
+
/>
|
|
619
|
+
<div class="gui-parts__visual-underline ${i}__visual-underline"></div>
|
|
620
|
+
</div>
|
|
621
|
+
`;
|
|
622
|
+
}
|
|
623
|
+
function rt(n, t, r, e, s) {
|
|
624
|
+
const i = e.blockClass, a = t.type;
|
|
625
|
+
return D`
|
|
626
|
+
<div class="gui-parts__touch-target ${i}__touch-target">
|
|
627
|
+
<button
|
|
628
|
+
type="button"
|
|
629
|
+
class="gui-parts__part gui-parts__dayperiod ${i}__part ${i}__dayperiod"
|
|
630
|
+
data-type=${a}
|
|
631
|
+
data-group=${e.groups.length > 1 ? n : N}
|
|
632
|
+
tabindex=${r}
|
|
633
|
+
?disabled=${e.disabled}
|
|
634
|
+
aria-label=${e.dayPeriodAriaLabel ?? "AM/PM"}
|
|
635
|
+
@click=${() => s.toggleDayPeriod(n, a)}
|
|
636
|
+
@keydown=${s.handleDayPeriodKeyDown}
|
|
637
|
+
@keyup=${(o) => s.handleKeyUp(o, n, a)}
|
|
638
|
+
@focus=${s.handleFocus}
|
|
639
|
+
@blur=${(o) => s.handleBlur(o, n, a)}
|
|
640
|
+
>
|
|
641
|
+
${e.getDisplayValue(n, a)}
|
|
642
|
+
</button>
|
|
643
|
+
<div class="gui-parts__visual-underline ${i}__visual-underline"></div>
|
|
644
|
+
</div>
|
|
645
|
+
`;
|
|
646
|
+
}
|
|
647
|
+
export {
|
|
648
|
+
Dt as A,
|
|
649
|
+
bt as G,
|
|
650
|
+
lt as N,
|
|
651
|
+
ct as a,
|
|
652
|
+
Et as b,
|
|
653
|
+
yt as c,
|
|
654
|
+
It as d,
|
|
655
|
+
K as e,
|
|
656
|
+
_t as f,
|
|
657
|
+
Nt as g,
|
|
658
|
+
q as h,
|
|
659
|
+
St as i,
|
|
660
|
+
Tt as j,
|
|
661
|
+
dt as k,
|
|
662
|
+
Pt as l,
|
|
663
|
+
gt as m,
|
|
664
|
+
W as n,
|
|
665
|
+
pt as o,
|
|
666
|
+
l as p,
|
|
667
|
+
kt as q,
|
|
668
|
+
vt as r,
|
|
669
|
+
f as s,
|
|
670
|
+
ht as t,
|
|
671
|
+
ut as u,
|
|
672
|
+
$t as v,
|
|
673
|
+
wt as w,
|
|
674
|
+
ft as x,
|
|
675
|
+
mt as y,
|
|
676
|
+
S as z
|
|
677
|
+
};
|