@golemui/gui-lit 1.0.3 → 1.1.1-rc.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 +26 -0
- package/{button.element-3a7rRHbA.js → button.element-CJay43iR.js} +16 -13
- package/calendar-D31xNsxx.js +267 -0
- package/{range-calendar.element-_1bHW_c1.js → calendar.element-BhFrCsns.js} +16 -16
- package/{checkbox.element-CVskoXEc.js → checkbox.element-DAAVB651.js} +49 -49
- package/{currency.element-5GSakkxF.js → currency.element-D8A2ObpM.js} +15 -11
- package/{date-CDUlLuYy.js → date-DBuYpvcO.js} +88 -29
- package/date-input-DLiMreSS.js +204 -0
- package/date-picker.element-DeUQtbLg.js +357 -0
- package/date-time-calendar-DzU-FtVl.js +374 -0
- package/date-time-calendar.element-BLBcVsFu.js +95 -0
- package/date-time-input-DZaz2heD.js +246 -0
- package/date-time-picker.element-BUbLdV6i.js +440 -0
- package/date-time.element-B5onfSBG.js +93 -0
- package/{date.element-BZO0UQez.js → date.element-BsKhLrEc.js} +27 -19
- package/day-status-CsWStVQV.js +554 -0
- package/{dropdown.element-CyJbVAA5.js → dropdown.element-CXpMwJsU.js} +53 -37
- package/{errors-QjKhr6mA.js → errors-Byb2dIhK.js} +3 -2
- package/focus-leave.controller-2gV0pQd5.js +73 -0
- package/index.js +1635 -948
- package/index.umd.cjs +2046 -601
- 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-D730tmGN.js +297 -0
- package/{list.element-Co3V3Cn5.js → list.element-eo3DIOrp.js} +23 -23
- package/{markdown.element-p-kC47D7.js → markdown.element-FbtwdnAv.js} +310 -218
- package/{number.element-CBr47IiY.js → number.element-BEpOCzXy.js} +76 -61
- package/package.json +6 -6
- package/part-templates-VORbpgs2.js +691 -0
- package/{password.element-n-R9RbkB.js → password.element-CBaB8h5b.js} +19 -17
- package/pill-ranges-DpvWwP-3.js +48 -0
- package/{pills-B66qz_KX.js → pills-BDMO2NiR.js} +84 -59
- package/popup.controller-B33OvX_y.js +86 -0
- package/{radiogroup.element-CeQn623u.js → radiogroup.element-KWzBx8mx.js} +55 -51
- package/range-calendar-DO_woqcF.js +466 -0
- package/{calendar.element-DcnTyvfg.js → range-calendar.element-DHLZhpnj.js} +37 -29
- package/range-commit-8-MmYUyo.js +14 -0
- package/range-date-input-Br7XqQPK.js +311 -0
- package/{range-date-input.element-BqzAF0O3.js → range-date-input.element-BdD4SlB4.js} +12 -8
- package/range-date-picker.element-DWRHiAoC.js +434 -0
- package/range-date-time-calendar-B3EMgN1E.js +734 -0
- package/range-date-time-calendar.element-Coea6RF4.js +97 -0
- package/range-date-time-input-Cu-T_nuC.js +353 -0
- package/range-date-time-input.element-Cti44iuW.js +87 -0
- package/range-date-time-picker.element-CDN2RL1y.js +472 -0
- package/range-selection-CU3hxLJE.js +25 -0
- package/range-time-input-BP9ZL9O8.js +348 -0
- package/range-time-input.element-B7wtHJoQ.js +84 -0
- package/range-time-picker.element-CPIAiQPC.js +470 -0
- package/{repeater.element-CtNgB4F5.js → repeater.element-BM1Keckd.js} +1 -1
- package/{select.element-jcDF1h-g.js → select.element-eepcXTpL.js} +117 -107
- package/{tabs.element-BvAyI71N.js → tabs.element-CvcIA8P3.js} +1 -0
- package/{tags.element-CX3vQL8L.js → tags.element-CPHgotb0.js} +21 -14
- package/templates-Dmr34nwp.js +88 -0
- package/{textarea.element-HThYqdR_.js → textarea.element-CiNEy9uq.js} +8 -7
- package/{textinput.element-CkXNzMUg.js → textinput.element-AL2Nr768.js} +10 -9
- package/time-input-5dkSm8UW.js +201 -0
- package/time-list-DLcq8BAp.js +217 -0
- package/time-picker-g337F8d0.js +299 -0
- package/time-picker.element-DLihegjg.js +89 -0
- package/time.element-BneqgMlQ.js +85 -0
- package/{toggle.element-C1kCw5H8.js → toggle.element-Cz91CRdp.js} +44 -43
- 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/list-D1oKnH89.js +0 -283
- 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/templates-Dk1jxLwS.js +0 -75
package/list-D1oKnH89.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { html as c, LitElement as p, nothing as u } from "lit";
|
|
2
|
-
import { classMap as m } from "lit/directives/class-map.js";
|
|
3
|
-
import "@golemui/core";
|
|
4
|
-
import { property as a, state as d, query as f, customElement as v } from "lit/decorators.js";
|
|
5
|
-
const T = (e) => {
|
|
6
|
-
const t = {
|
|
7
|
-
"gui-list__item": !0,
|
|
8
|
-
"gui-list__item-selected": !!e.selected,
|
|
9
|
-
"gui-list__item-focused": !!e.focused,
|
|
10
|
-
"gui-list__item-disabled": !!e.disabled
|
|
11
|
-
};
|
|
12
|
-
return c`
|
|
13
|
-
<div
|
|
14
|
-
role="option"
|
|
15
|
-
class=${m(t)}
|
|
16
|
-
aria-selected=${e.selected ? "true" : "false"}
|
|
17
|
-
aria-disabled=${e.disabled ? "true" : "false"}
|
|
18
|
-
>
|
|
19
|
-
${e.template}
|
|
20
|
-
</div>
|
|
21
|
-
`;
|
|
22
|
-
}, g = (e) => e !== null && typeof e == "object" && Object.prototype.hasOwnProperty.call(e, "template") && Object.prototype.hasOwnProperty.call(e, "value");
|
|
23
|
-
function b(e) {
|
|
24
|
-
const t = typeof e;
|
|
25
|
-
return t === "string" || t === "number";
|
|
26
|
-
}
|
|
27
|
-
const y = (e, { valueField: t }) => {
|
|
28
|
-
if (e === null || typeof e != "object")
|
|
29
|
-
return !1;
|
|
30
|
-
const i = e, o = t ?? "value";
|
|
31
|
-
return !!Object.prototype.hasOwnProperty.call(i, o);
|
|
32
|
-
};
|
|
33
|
-
function w(e, { valueField: t }) {
|
|
34
|
-
if (e === null || typeof e != "object")
|
|
35
|
-
throw new Error("Provided value is not an object");
|
|
36
|
-
const i = e, o = t ?? "value", s = Object.prototype.hasOwnProperty.call(i, o) ? o : void 0;
|
|
37
|
-
if (!s)
|
|
38
|
-
throw new Error("No valueField exists on the object");
|
|
39
|
-
return (n) => {
|
|
40
|
-
if (n === null || typeof n != "object")
|
|
41
|
-
throw new Error("Item is not an object");
|
|
42
|
-
return {
|
|
43
|
-
template: n,
|
|
44
|
-
value: s ? n[s] : ""
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const _ = (e, t) => {
|
|
49
|
-
if (Array.isArray(e) && e.length > 0 && !g(e[0])) {
|
|
50
|
-
if (b(e[0]))
|
|
51
|
-
return e.map((i) => ({
|
|
52
|
-
template: i,
|
|
53
|
-
value: i
|
|
54
|
-
}));
|
|
55
|
-
if (y(e[0], t)) {
|
|
56
|
-
const i = w(e[0], t);
|
|
57
|
-
return e.map(i);
|
|
58
|
-
} else
|
|
59
|
-
throw new Error("Invalid list item shape");
|
|
60
|
-
}
|
|
61
|
-
return e;
|
|
62
|
-
};
|
|
63
|
-
var I = Object.defineProperty, x = Object.getOwnPropertyDescriptor, l = (e, t, i, o) => {
|
|
64
|
-
for (var s = o > 1 ? void 0 : o ? x(t, i) : t, n = e.length - 1, h; n >= 0; n--)
|
|
65
|
-
(h = e[n]) && (s = (o ? h(t, i, s) : h(s)) || s);
|
|
66
|
-
return o && s && I(t, i, s), s;
|
|
67
|
-
};
|
|
68
|
-
let r = class extends p {
|
|
69
|
-
constructor() {
|
|
70
|
-
super(...arguments), this.uid = void 0, this.touched = !1, this.required = !1, this.disabled = !1, this.readOnly = !1, this.value = void 0, this.valueField = void 0, this.label = void 0, this.hint = void 0, this.items = [], this.itemHeight = void 0, this.height = void 0, this._items = [], this._scrollTop = 0, this._viewportHeight = 0, this._focusedIndex = -1, this.buffer = 5;
|
|
71
|
-
}
|
|
72
|
-
willUpdate(e) {
|
|
73
|
-
super.willUpdate(e), e.has("items") && this.updateItems(), (e.has("items") || e.has("_scrollTop") || e.has("height")) && this.emitRangeChange();
|
|
74
|
-
}
|
|
75
|
-
firstUpdated() {
|
|
76
|
-
this.measureViewport(), new ResizeObserver(() => this.measureViewport()).observe(this.viewportElement);
|
|
77
|
-
}
|
|
78
|
-
render() {
|
|
79
|
-
const e = this.height ?? 300, t = this.itemHeight ?? 40, i = (this.items?.length ?? 0) * t, { offsetY: o } = this.calculateRange(), s = this._focusedIndex >= 0 ? `${this.uid}-item-${this._focusedIndex}` : void 0;
|
|
80
|
-
return c`
|
|
81
|
-
<div
|
|
82
|
-
role="listbox"
|
|
83
|
-
id=${this.uid}
|
|
84
|
-
tabindex=${this.disabled ? -1 : 0}
|
|
85
|
-
class="gui-list__scroll-viewport"
|
|
86
|
-
style="max-height: ${e}px; overflow-y: auto; position: relative; display: block;"
|
|
87
|
-
@scroll="${this.onScroll}"
|
|
88
|
-
@keydown="${this.onKeyDown}"
|
|
89
|
-
@focus="${this.onFocus}"
|
|
90
|
-
@focusout="${this.onFocusOut}"
|
|
91
|
-
aria-required=${this.required ? "true" : u}
|
|
92
|
-
aria-disabled=${this.disabled || this.readOnly ? "true" : u}
|
|
93
|
-
aria-activedescendant="${s ?? u}"
|
|
94
|
-
aria-label=${this.label ?? u}
|
|
95
|
-
aria-description=${this.hint ?? u}
|
|
96
|
-
>
|
|
97
|
-
<div
|
|
98
|
-
class="gui-list__spacer"
|
|
99
|
-
style="height: ${i}px; width: 1px; opacity: 0; pointer-events: none;"
|
|
100
|
-
></div>
|
|
101
|
-
|
|
102
|
-
<div
|
|
103
|
-
class="gui-list__content"
|
|
104
|
-
style="transform: translateY(${o}px); position: absolute; top: 0; left: 0; width: 100%;"
|
|
105
|
-
>
|
|
106
|
-
<slot></slot>
|
|
107
|
-
</div>
|
|
108
|
-
</div>
|
|
109
|
-
`;
|
|
110
|
-
}
|
|
111
|
-
focus(e) {
|
|
112
|
-
this.viewportElement ? this.viewportElement.focus(e) : super.focus(e);
|
|
113
|
-
}
|
|
114
|
-
focusItemAtIndex(e) {
|
|
115
|
-
this._focusedIndex = e;
|
|
116
|
-
}
|
|
117
|
-
scrollToSelectedIndex() {
|
|
118
|
-
const e = this._items.findIndex((t) => t.value === this.value);
|
|
119
|
-
this.scrollToIndex(e);
|
|
120
|
-
}
|
|
121
|
-
onKeyDown(e) {
|
|
122
|
-
if (this.disabled || this.readOnly) return;
|
|
123
|
-
const t = this.itemHeight ?? 40, i = Math.ceil(this._viewportHeight / t), o = this.items.length - 1;
|
|
124
|
-
let s = !1;
|
|
125
|
-
switch (e.key) {
|
|
126
|
-
case "ArrowDown":
|
|
127
|
-
this.setFocusedIndex(Math.min(this._focusedIndex + 1, o)), s = !0;
|
|
128
|
-
break;
|
|
129
|
-
case "ArrowUp":
|
|
130
|
-
this.setFocusedIndex(Math.max(this._focusedIndex - 1, 0)), s = !0;
|
|
131
|
-
break;
|
|
132
|
-
case "PageDown":
|
|
133
|
-
this.setFocusedIndex(Math.min(this._focusedIndex + i, o)), s = !0;
|
|
134
|
-
break;
|
|
135
|
-
case "PageUp":
|
|
136
|
-
this.setFocusedIndex(Math.max(this._focusedIndex - i, 0)), s = !0;
|
|
137
|
-
break;
|
|
138
|
-
case "Home":
|
|
139
|
-
this.setFocusedIndex(0), s = !0;
|
|
140
|
-
break;
|
|
141
|
-
case "End":
|
|
142
|
-
this.setFocusedIndex(o), s = !0;
|
|
143
|
-
break;
|
|
144
|
-
case "Enter":
|
|
145
|
-
case " ": {
|
|
146
|
-
const n = this._items[this._focusedIndex];
|
|
147
|
-
this._focusedIndex >= 0 && n != null && this.selectItem(n), s = !0;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
s && e.preventDefault();
|
|
152
|
-
}
|
|
153
|
-
onFocus() {
|
|
154
|
-
if (!this.value || !this.items.length) return;
|
|
155
|
-
const e = this._items.findIndex((t) => t.value === this.value);
|
|
156
|
-
this._focusedIndex = e, this.scrollToIndex(e), this.dispatchEvent(
|
|
157
|
-
new CustomEvent("gui-focus-change", {
|
|
158
|
-
detail: { index: e },
|
|
159
|
-
bubbles: !0,
|
|
160
|
-
composed: !0
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
onFocusOut(e) {
|
|
165
|
-
e.relatedTarget && this.contains(e.relatedTarget) || (this._focusedIndex = -1, this.dispatchEvent(
|
|
166
|
-
new CustomEvent("gui-focus-change", {
|
|
167
|
-
detail: { index: -1 },
|
|
168
|
-
bubbles: !0,
|
|
169
|
-
composed: !0
|
|
170
|
-
})
|
|
171
|
-
), this.dispatchEvent(new CustomEvent("blur", { bubbles: !0, composed: !0 })));
|
|
172
|
-
}
|
|
173
|
-
scrollToIndex(e) {
|
|
174
|
-
const t = this.itemHeight ?? 40, i = this.height ?? 300, o = e * t, s = o + t, n = this.viewportElement.scrollTop, h = n + i;
|
|
175
|
-
o < n ? this.viewportElement.scrollTop = o : s > h && (this.viewportElement.scrollTop = s - i);
|
|
176
|
-
}
|
|
177
|
-
selectItem(e) {
|
|
178
|
-
this.dispatchEvent(
|
|
179
|
-
new CustomEvent("change", {
|
|
180
|
-
detail: { value: e.value },
|
|
181
|
-
bubbles: !0,
|
|
182
|
-
composed: !0
|
|
183
|
-
})
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
setFocusedIndex(e) {
|
|
187
|
-
e < 0 || e >= this.items.length || (this._focusedIndex = e, this.scrollToIndex(e), this.dispatchEvent(
|
|
188
|
-
new CustomEvent("gui-focus-change", {
|
|
189
|
-
detail: { index: e },
|
|
190
|
-
bubbles: !0,
|
|
191
|
-
composed: !0
|
|
192
|
-
})
|
|
193
|
-
));
|
|
194
|
-
}
|
|
195
|
-
updateItems() {
|
|
196
|
-
this._items = _(this.items, { valueField: this.valueField }), this.dispatchEvent(
|
|
197
|
-
new CustomEvent("gui-update-items", {
|
|
198
|
-
detail: this._items,
|
|
199
|
-
bubbles: !0,
|
|
200
|
-
composed: !0
|
|
201
|
-
})
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
emitRangeChange() {
|
|
205
|
-
const { startIndex: e, endIndex: t } = this.calculateRange();
|
|
206
|
-
this.dispatchEvent(
|
|
207
|
-
new CustomEvent("gui-range-change", {
|
|
208
|
-
detail: { startIndex: e, endIndex: t },
|
|
209
|
-
bubbles: !0,
|
|
210
|
-
composed: !0
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
measureViewport() {
|
|
215
|
-
this.viewportElement && (this._viewportHeight = this.viewportElement.offsetHeight, this.emitRangeChange());
|
|
216
|
-
}
|
|
217
|
-
onScroll(e) {
|
|
218
|
-
const t = e.target;
|
|
219
|
-
this._scrollTop = t.scrollTop;
|
|
220
|
-
}
|
|
221
|
-
calculateRange() {
|
|
222
|
-
const e = this.itemHeight ?? 40, t = this.items?.length ?? 0, i = Math.ceil(this._viewportHeight / e), o = Math.floor(this._scrollTop / e), s = Math.max(0, o - this.buffer), n = Math.min(t, o + i + this.buffer), h = s * e;
|
|
223
|
-
return { startIndex: s, endIndex: n, offsetY: h };
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
l([
|
|
227
|
-
a({ type: String })
|
|
228
|
-
], r.prototype, "uid", 2);
|
|
229
|
-
l([
|
|
230
|
-
a({ type: Boolean })
|
|
231
|
-
], r.prototype, "touched", 2);
|
|
232
|
-
l([
|
|
233
|
-
a({ type: Boolean })
|
|
234
|
-
], r.prototype, "required", 2);
|
|
235
|
-
l([
|
|
236
|
-
a({ type: Boolean })
|
|
237
|
-
], r.prototype, "disabled", 2);
|
|
238
|
-
l([
|
|
239
|
-
a({ type: Boolean, attribute: "readonly" })
|
|
240
|
-
], r.prototype, "readOnly", 2);
|
|
241
|
-
l([
|
|
242
|
-
a({ type: String })
|
|
243
|
-
], r.prototype, "value", 2);
|
|
244
|
-
l([
|
|
245
|
-
a({ type: String })
|
|
246
|
-
], r.prototype, "valueField", 2);
|
|
247
|
-
l([
|
|
248
|
-
a({ type: String })
|
|
249
|
-
], r.prototype, "label", 2);
|
|
250
|
-
l([
|
|
251
|
-
a({ type: String })
|
|
252
|
-
], r.prototype, "hint", 2);
|
|
253
|
-
l([
|
|
254
|
-
a({ type: Array })
|
|
255
|
-
], r.prototype, "items", 2);
|
|
256
|
-
l([
|
|
257
|
-
a({ type: Number })
|
|
258
|
-
], r.prototype, "itemHeight", 2);
|
|
259
|
-
l([
|
|
260
|
-
a({ type: Number })
|
|
261
|
-
], r.prototype, "height", 2);
|
|
262
|
-
l([
|
|
263
|
-
d()
|
|
264
|
-
], r.prototype, "_items", 2);
|
|
265
|
-
l([
|
|
266
|
-
d()
|
|
267
|
-
], r.prototype, "_scrollTop", 2);
|
|
268
|
-
l([
|
|
269
|
-
d()
|
|
270
|
-
], r.prototype, "_viewportHeight", 2);
|
|
271
|
-
l([
|
|
272
|
-
d()
|
|
273
|
-
], r.prototype, "_focusedIndex", 2);
|
|
274
|
-
l([
|
|
275
|
-
f(".gui-list__scroll-viewport")
|
|
276
|
-
], r.prototype, "viewportElement", 2);
|
|
277
|
-
r = l([
|
|
278
|
-
v("gui-list")
|
|
279
|
-
], r);
|
|
280
|
-
typeof customElements < "u" && !customElements.get("gui-list") && customElements.define("gui-list", r);
|
|
281
|
-
export {
|
|
282
|
-
T as d
|
|
283
|
-
};
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { html as b, nothing as p } from "lit";
|
|
2
|
-
import { property as D, state as v, customElement as $ } from "lit/decorators.js";
|
|
3
|
-
import { classMap as M } from "lit/directives/class-map.js";
|
|
4
|
-
import { p as h, i as d, t as O, a as w, b as f, g as A, m as E, c as _ } from "./date-CDUlLuYy.js";
|
|
5
|
-
import { A as P } from "./abstract-calendar-D0-077XJ.js";
|
|
6
|
-
import "./pills-B66qz_KX.js";
|
|
7
|
-
var C = Object.defineProperty, k = Object.getOwnPropertyDescriptor, g = (e, i, s, n) => {
|
|
8
|
-
for (var a = n > 1 ? void 0 : n ? k(i, s) : i, t = e.length - 1, r; t >= 0; t--)
|
|
9
|
-
(r = e[t]) && (a = (n ? r(i, s, a) : r(a)) || a);
|
|
10
|
-
return n && a && C(i, s, a), a;
|
|
11
|
-
};
|
|
12
|
-
let c = class extends P {
|
|
13
|
-
constructor() {
|
|
14
|
-
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) => {
|
|
15
|
-
if (this.disabled || this.readOnly) return;
|
|
16
|
-
const s = this.getSortedPills().find(
|
|
17
|
-
(a) => `${a.start}-${a.end ?? a.start}` === e.detail.key
|
|
18
|
-
);
|
|
19
|
-
if (!s) return;
|
|
20
|
-
const n = (this.value ?? []).filter(
|
|
21
|
-
(a) => !(a.start === s.start && (a.end ?? null) === (s.end ?? null))
|
|
22
|
-
);
|
|
23
|
-
this.value = n, this.dispatchEvent(
|
|
24
|
-
new CustomEvent("change", {
|
|
25
|
-
detail: { value: this.value },
|
|
26
|
-
bubbles: !0,
|
|
27
|
-
composed: !0
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
}, this.onPillClickEvent = (e) => {
|
|
31
|
-
const s = this.getSortedPills().find((n) => `${n.start}-${n.end ?? n.start}` === e.detail.key);
|
|
32
|
-
s && this.navigateToDate(s.start);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
createRenderRoot() {
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
connectedCallback() {
|
|
39
|
-
super.connectedCallback(), this.classList.add("gui-field");
|
|
40
|
-
}
|
|
41
|
-
willUpdate(e) {
|
|
42
|
-
if (e.has("value") && !e.has("focusDate")) {
|
|
43
|
-
if (this._skipValueNavigation)
|
|
44
|
-
this._skipValueNavigation = !1;
|
|
45
|
-
else if (this.value) {
|
|
46
|
-
const i = Array.isArray(this.value) ? this.value : [{ start: this.value }];
|
|
47
|
-
if (i.length > 0 && i[0].start) {
|
|
48
|
-
const s = h(i[0].start);
|
|
49
|
-
!isNaN(s.getTime()) && !d(s, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = s);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (e.has("focusDate") && this.focusDate) {
|
|
54
|
-
const i = h(this.focusDate);
|
|
55
|
-
isNaN(i.getTime()) || (d(i, this._currentDate, this.numberOfMonths ?? 1) || (this._currentDate = i), this.focusDate = void 0);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
renderDay(e) {
|
|
59
|
-
const i = {
|
|
60
|
-
"gui-calendar__day-button": !0,
|
|
61
|
-
today: e.isToday,
|
|
62
|
-
"other-month": !e.isCurrentMonth,
|
|
63
|
-
"range-start": e.isRangeStart && !e.isOneDayRange,
|
|
64
|
-
"range-end": e.isRangeEnd && !e.isOneDayRange,
|
|
65
|
-
selected: e.isOneDayRange,
|
|
66
|
-
"in-range": e.isInRange,
|
|
67
|
-
"is-anchor": e.isAnchor,
|
|
68
|
-
"is-selecting": e.isSelecting,
|
|
69
|
-
disabled: e.isDisabled
|
|
70
|
-
};
|
|
71
|
-
return b`
|
|
72
|
-
<button
|
|
73
|
-
type="button"
|
|
74
|
-
role="gridcell"
|
|
75
|
-
class=${M(i)}
|
|
76
|
-
tabindex=${e.isFocusable ? 0 : -1}
|
|
77
|
-
?disabled=${!e.isCurrentMonth || e.isDisabled}
|
|
78
|
-
data-date=${O(e.date)}
|
|
79
|
-
@click=${(s) => this.selectDate(e, s)}
|
|
80
|
-
@mouseover=${() => this.onMouseOver(e)}
|
|
81
|
-
@focus=${() => this.onMouseOver(e)}
|
|
82
|
-
@keydown=${(s) => this.handleKeydown(s, e)}
|
|
83
|
-
aria-selected=${e.isRangeStart || e.isRangeEnd || e.isInRange ? "true" : "false"}
|
|
84
|
-
>
|
|
85
|
-
${e.dayLabel}
|
|
86
|
-
</button>
|
|
87
|
-
`;
|
|
88
|
-
}
|
|
89
|
-
getDaysInMonth(e) {
|
|
90
|
-
const i = new Date(this._currentDate);
|
|
91
|
-
i.setDate(1), i.setMonth(i.getMonth() + e);
|
|
92
|
-
const s = this.generateDateGrid(e), n = i.getMonth();
|
|
93
|
-
let a = s.map((t) => {
|
|
94
|
-
const r = t.getMonth() === n, l = this.isDisabled(t), o = w(t), { isRangeStart: u, isRangeEnd: m, isInRange: y, isSelecting: R } = this.checkDateStatus(t), S = o || u, T = this._anchorDate ? f(t, this._anchorDate) : !1;
|
|
95
|
-
return {
|
|
96
|
-
date: t,
|
|
97
|
-
dayLabel: A(this.localeId, t),
|
|
98
|
-
isCurrentMonth: r,
|
|
99
|
-
isToday: o,
|
|
100
|
-
isRangeStart: u,
|
|
101
|
-
isRangeEnd: m,
|
|
102
|
-
isInRange: y,
|
|
103
|
-
isDisabled: l,
|
|
104
|
-
isOneDayRange: u && m,
|
|
105
|
-
isAnchor: T,
|
|
106
|
-
isFocusable: S,
|
|
107
|
-
isSelecting: R && r
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
for (let t = 0; t < 2; t++)
|
|
111
|
-
a.slice(-7).every((l) => !l.isCurrentMonth) && (a = a.slice(0, -7));
|
|
112
|
-
if (e === 0 && !a.some((t) => t.isFocusable)) {
|
|
113
|
-
const t = this.numberOfMonths ?? 1, r = d(/* @__PURE__ */ new Date(), this._currentDate, t), l = this.value?.some(
|
|
114
|
-
(o) => d(h(o.start), this._currentDate, t)
|
|
115
|
-
) ?? !1;
|
|
116
|
-
if (!r && !l) {
|
|
117
|
-
const o = a.find((u) => u.isCurrentMonth && !u.isDisabled);
|
|
118
|
-
o && (o.isFocusable = !0);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return a;
|
|
122
|
-
}
|
|
123
|
-
checkDateStatus(e) {
|
|
124
|
-
let i = !1, s = !1, n = !1, a = !1;
|
|
125
|
-
if (this._isSelecting && this._nextDate && this._anchorDate) {
|
|
126
|
-
const t = this._nextDate.date, r = new Date(this._anchorDate);
|
|
127
|
-
t.getTime() > r.getTime() ? a = e.getTime() >= r.getTime() && e.getTime() <= t.getTime() : a = e.getTime() >= t.getTime() && e.getTime() <= r.getTime();
|
|
128
|
-
}
|
|
129
|
-
if (this.value && Array.isArray(this.value))
|
|
130
|
-
for (const t of this.value) {
|
|
131
|
-
const r = h(t.start);
|
|
132
|
-
if (f(e, r) && (i = !0, s = !t.end), t.end) {
|
|
133
|
-
const l = h(t.end);
|
|
134
|
-
f(e, l) && (s = !0);
|
|
135
|
-
const o = e.getTime(), u = r.getTime(), m = l.getTime();
|
|
136
|
-
o > u && o < m && (n = !0);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return { isRangeStart: i, isRangeEnd: s, isInRange: n, isSelecting: a };
|
|
140
|
-
}
|
|
141
|
-
selectDate(e, i = null) {
|
|
142
|
-
if (!e.isCurrentMonth || this.disabled || this.readOnly) return;
|
|
143
|
-
const s = e.date;
|
|
144
|
-
if (!this._anchorDate) {
|
|
145
|
-
this._isSelecting = !0, this._anchorDate = s;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
let n = this._anchorDate, a = s;
|
|
149
|
-
s < n && (n = s, a = this._anchorDate);
|
|
150
|
-
const t = this.calculateValidRanges(n, a), r = [...this.value || [], ...t];
|
|
151
|
-
this._skipValueNavigation = !0, this.value = E(r), this._isSelecting = !1, this._nextDate = null, this._anchorDate = null, this.dispatchEvent(
|
|
152
|
-
new CustomEvent("change", {
|
|
153
|
-
detail: { value: this.value },
|
|
154
|
-
bubbles: !0,
|
|
155
|
-
composed: !0
|
|
156
|
-
})
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Calculates and returns an array of valid date ranges between the given start date and end date.
|
|
161
|
-
* A date range is considered valid if no dates within the range are disabled.
|
|
162
|
-
*
|
|
163
|
-
* @param {Date} startDate - The starting date for the range calculation.
|
|
164
|
-
* @param {Date} endDate - The ending date for the range calculation.
|
|
165
|
-
* @return {DateRange[]} An array of valid date ranges where each range defines consecutive, non-disabled dates.
|
|
166
|
-
*/
|
|
167
|
-
calculateValidRanges(e, i) {
|
|
168
|
-
const s = [], n = new Date(e), a = new Date(i);
|
|
169
|
-
n.setHours(0, 0, 0, 0), a.setHours(0, 0, 0, 0);
|
|
170
|
-
let t = null;
|
|
171
|
-
for (; n <= a; ) {
|
|
172
|
-
if (!this.isDisabled(n))
|
|
173
|
-
t || (t = new Date(n));
|
|
174
|
-
else if (t) {
|
|
175
|
-
const l = new Date(n);
|
|
176
|
-
l.setDate(n.getDate() - 1), s.push(_(t, l)), t = null;
|
|
177
|
-
}
|
|
178
|
-
n.setDate(n.getDate() + 1);
|
|
179
|
-
}
|
|
180
|
-
return t && s.push(_(t, i)), s;
|
|
181
|
-
}
|
|
182
|
-
onMouseOver(e) {
|
|
183
|
-
this._isSelecting && (this._nextDate = e);
|
|
184
|
-
}
|
|
185
|
-
// --- Pills ---
|
|
186
|
-
renderAboveCalendar() {
|
|
187
|
-
if (this.hidePills) return p;
|
|
188
|
-
const e = this.getSortedPills();
|
|
189
|
-
if (e.length === 0) return p;
|
|
190
|
-
const i = e.map((s) => {
|
|
191
|
-
const n = this.formatDateForDisplay(s.start), a = s.end ? this.formatDateForDisplay(s.end) : n, t = `${n} - ${a}`;
|
|
192
|
-
return {
|
|
193
|
-
key: `${s.start}-${s.end ?? s.start}`,
|
|
194
|
-
label: t,
|
|
195
|
-
ariaLabel: `${this.removePillAriaLabel ?? "Remove date"} ${t}`
|
|
196
|
-
};
|
|
197
|
-
});
|
|
198
|
-
return b`
|
|
199
|
-
<gui-pills
|
|
200
|
-
class="gui-range-calendar__pills"
|
|
201
|
-
.items=${i}
|
|
202
|
-
.removable=${!0}
|
|
203
|
-
.clickable=${!0}
|
|
204
|
-
.bubble=${!1}
|
|
205
|
-
?disabled=${this.disabled}
|
|
206
|
-
?readonly=${this.readOnly}
|
|
207
|
-
.removeAriaLabel=${this.removePillAriaLabel ?? "Remove date"}
|
|
208
|
-
@pillremove=${this.onPillRemoveEvent}
|
|
209
|
-
@pillclick=${this.onPillClickEvent}
|
|
210
|
-
></gui-pills>
|
|
211
|
-
`;
|
|
212
|
-
}
|
|
213
|
-
formatDateForDisplay(e) {
|
|
214
|
-
const i = h(e);
|
|
215
|
-
return isNaN(i.getTime()) ? e : new Intl.DateTimeFormat(this.localeId ?? "en", {
|
|
216
|
-
year: "numeric",
|
|
217
|
-
month: "2-digit",
|
|
218
|
-
day: "2-digit"
|
|
219
|
-
}).format(i);
|
|
220
|
-
}
|
|
221
|
-
getSortedPills() {
|
|
222
|
-
return !this.value || !Array.isArray(this.value) ? [] : [...this.value].sort(
|
|
223
|
-
(e, i) => h(e.start).getTime() - h(i.start).getTime()
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
navigateToDate(e) {
|
|
227
|
-
const i = h(e);
|
|
228
|
-
!isNaN(i.getTime()) && !d(i, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = i);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
g([
|
|
232
|
-
D({ type: Array })
|
|
233
|
-
], c.prototype, "value", 2);
|
|
234
|
-
g([
|
|
235
|
-
D({ type: String })
|
|
236
|
-
], c.prototype, "focusDate", 2);
|
|
237
|
-
g([
|
|
238
|
-
D({ type: Boolean })
|
|
239
|
-
], c.prototype, "hidePills", 2);
|
|
240
|
-
g([
|
|
241
|
-
D({ type: String })
|
|
242
|
-
], c.prototype, "removePillAriaLabel", 2);
|
|
243
|
-
g([
|
|
244
|
-
v()
|
|
245
|
-
], c.prototype, "_anchorDate", 2);
|
|
246
|
-
g([
|
|
247
|
-
v()
|
|
248
|
-
], c.prototype, "_nextDate", 2);
|
|
249
|
-
g([
|
|
250
|
-
v()
|
|
251
|
-
], c.prototype, "_isSelecting", 2);
|
|
252
|
-
c = g([
|
|
253
|
-
$("gui-range-calendar")
|
|
254
|
-
], c);
|
|
255
|
-
typeof customElements < "u" && !customElements.get("gui-range-calendar") && customElements.define("gui-range-calendar", c);
|