@golemui/gui-lit 0.14.0 → 0.15.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +4 -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
@@ -1,326 +0,0 @@
1
- import { html as v, nothing as m } from "lit";
2
- import { property as f, state as g, customElement as R } from "lit/decorators.js";
3
- import { classMap as p } from "lit/directives/class-map.js";
4
- import { repeat as M } from "lit-html/directives/repeat.js";
5
- import { i as d, a as $, b, g as A, m as P, c as _ } from "./date-CG1562vW.js";
6
- import { c as w } from "./tabs-DzSCq_98.js";
7
- import { A as k } from "./abstract-calendar-YDgwwbqe.js";
8
- import "@golemui/gui-shared";
9
- var E = Object.defineProperty, V = Object.getOwnPropertyDescriptor, h = (e, t, i, a) => {
10
- for (var n = a > 1 ? void 0 : a ? V(t, i) : t, s = e.length - 1, r; s >= 0; s--)
11
- (r = e[s]) && (n = (a ? r(t, i, n) : r(n)) || n);
12
- return a && n && E(t, i, n), n;
13
- };
14
- let l = class extends k {
15
- constructor() {
16
- 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._isStartVisible = !0, this._isEndVisible = !0, this._skipValueNavigation = !1;
17
- }
18
- createRenderRoot() {
19
- return this;
20
- }
21
- connectedCallback() {
22
- super.connectedCallback(), this.classList.add("gui-field");
23
- }
24
- willUpdate(e) {
25
- if (e.has("value") && !e.has("focusDate")) {
26
- if (this._skipValueNavigation)
27
- this._skipValueNavigation = !1;
28
- else if (this.value) {
29
- const t = Array.isArray(this.value) ? this.value : [{ start: this.value }];
30
- if (t.length > 0 && t[0].start) {
31
- const i = new Date(t[0].start);
32
- !isNaN(i.getTime()) && !d(i, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = i);
33
- }
34
- }
35
- }
36
- if (e.has("focusDate") && this.focusDate) {
37
- const t = new Date(this.focusDate);
38
- isNaN(t.getTime()) || (d(t, this._currentDate, this.numberOfMonths ?? 1) || (this._currentDate = t), this.focusDate = void 0);
39
- }
40
- }
41
- renderDay(e) {
42
- const t = {
43
- "gui-calendar__day-button": !0,
44
- today: e.isToday,
45
- "other-month": !e.isCurrentMonth,
46
- "range-start": e.isRangeStart && !e.isOneDayRange,
47
- "range-end": e.isRangeEnd && !e.isOneDayRange,
48
- selected: e.isOneDayRange,
49
- "in-range": e.isInRange,
50
- "is-anchor": e.isAnchor,
51
- "is-selecting": e.isSelecting,
52
- disabled: e.isDisabled
53
- };
54
- return v`
55
- <button
56
- type="button"
57
- role="gridcell"
58
- class=${p(t)}
59
- tabindex=${e.isFocusable ? 0 : -1}
60
- ?disabled=${!e.isCurrentMonth || e.isDisabled}
61
- data-date=${e.date.toISOString()}
62
- @click=${(i) => this.selectDate(e, i)}
63
- @mouseover=${() => this.onMouseOver(e)}
64
- @focus=${() => this.onMouseOver(e)}
65
- @keydown=${(i) => this.handleKeydown(i, e)}
66
- aria-selected=${e.isRangeStart || e.isRangeEnd || e.isInRange ? "true" : "false"}
67
- >
68
- ${e.dayLabel}
69
- </button>
70
- `;
71
- }
72
- getDaysInMonth(e) {
73
- const t = new Date(this._currentDate);
74
- t.setDate(1), t.setMonth(t.getMonth() + e);
75
- const i = this.generateDateGrid(e), a = t.getMonth();
76
- let n = i.map((s) => {
77
- const r = s.getMonth() === a, o = this.isDisabled(s), c = $(s), { isRangeStart: u, isRangeEnd: D, isInRange: y, isSelecting: O } = this.checkDateStatus(s), S = c || u, T = this._anchorDate ? b(s, this._anchorDate) : !1;
78
- return {
79
- date: s,
80
- dayLabel: A(this.localeId, s),
81
- isCurrentMonth: r,
82
- isToday: c,
83
- isRangeStart: u,
84
- isRangeEnd: D,
85
- isInRange: y,
86
- isDisabled: o,
87
- isOneDayRange: u && D,
88
- isAnchor: T,
89
- isFocusable: S,
90
- isSelecting: O && r
91
- };
92
- });
93
- for (let s = 0; s < 2; s++)
94
- n.slice(-7).every((o) => !o.isCurrentMonth) && (n = n.slice(0, -7));
95
- if (e === 0 && !n.some((s) => s.isFocusable)) {
96
- const s = this.numberOfMonths ?? 1, r = d(/* @__PURE__ */ new Date(), this._currentDate, s), o = this.value?.some(
97
- (c) => d(new Date(c.start), this._currentDate, s)
98
- ) ?? !1;
99
- if (!r && !o) {
100
- const c = n.find((u) => u.isCurrentMonth && !u.isDisabled);
101
- c && (c.isFocusable = !0);
102
- }
103
- }
104
- return n;
105
- }
106
- checkDateStatus(e) {
107
- let t = !1, i = !1, a = !1, n = !1;
108
- if (this._isSelecting && this._nextDate && this._anchorDate) {
109
- const s = this._nextDate.date, r = new Date(this._anchorDate);
110
- s.getTime() > r.getTime() ? n = e.getTime() >= r.getTime() && e.getTime() <= s.getTime() : n = e.getTime() >= s.getTime() && e.getTime() <= r.getTime();
111
- }
112
- if (this.value && Array.isArray(this.value))
113
- for (const s of this.value) {
114
- const r = new Date(s.start);
115
- if (b(e, r) && (t = !0, i = !s.end), s.end) {
116
- const o = new Date(s.end);
117
- b(e, o) && (i = !0);
118
- const c = e.getTime(), u = r.getTime(), D = o.getTime();
119
- c > u && c < D && (a = !0);
120
- }
121
- }
122
- return { isRangeStart: t, isRangeEnd: i, isInRange: a, isSelecting: n };
123
- }
124
- selectDate(e, t = null) {
125
- if (!e.isCurrentMonth || this.disabled || this.readOnly) return;
126
- const i = e.date;
127
- if (!this._anchorDate) {
128
- this._isSelecting = !0, this._anchorDate = i;
129
- return;
130
- }
131
- let a = this._anchorDate, n = i;
132
- i < a && (a = i, n = this._anchorDate);
133
- const s = this.calculateValidRanges(a, n), r = [...this.value || [], ...s];
134
- this._skipValueNavigation = !0, this.value = P(r), this._isSelecting = !1, this._nextDate = null, this._anchorDate = null, this.dispatchEvent(
135
- new CustomEvent("change", {
136
- detail: { value: this.value },
137
- bubbles: !0,
138
- composed: !0
139
- })
140
- );
141
- }
142
- /**
143
- * Calculates and returns an array of valid date ranges between the given start date and end date.
144
- * A date range is considered valid if no dates within the range are disabled.
145
- *
146
- * @param {Date} startDate - The starting date for the range calculation.
147
- * @param {Date} endDate - The ending date for the range calculation.
148
- * @return {DateRange[]} An array of valid date ranges where each range defines consecutive, non-disabled dates.
149
- */
150
- calculateValidRanges(e, t) {
151
- const i = [], a = new Date(e), n = new Date(t);
152
- a.setHours(0, 0, 0, 0), n.setHours(0, 0, 0, 0);
153
- let s = null;
154
- for (; a <= n; ) {
155
- if (!this.isDisabled(a))
156
- s || (s = new Date(a));
157
- else if (s) {
158
- const o = new Date(a);
159
- o.setDate(a.getDate() - 1), i.push(_(s, o)), s = null;
160
- }
161
- a.setDate(a.getDate() + 1);
162
- }
163
- return s && i.push(_(s, t)), i;
164
- }
165
- onMouseOver(e) {
166
- this._isSelecting && (this._nextDate = e);
167
- }
168
- // --- Pills ---
169
- updated() {
170
- this.hidePills || this.setupObservers();
171
- }
172
- disconnectedCallback() {
173
- super.disconnectedCallback(), this.disconnectObservers();
174
- }
175
- renderAboveCalendar() {
176
- if (this.hidePills) return m;
177
- const e = this.getSortedPills();
178
- return e.length === 0 ? m : v`
179
- <div
180
- class=${p({
181
- "gui-range-calendar__pills-wrapper": !0,
182
- "gui-range-calendar--start-shadow": !this._isStartVisible,
183
- "gui-range-calendar--end-shadow": !this._isEndVisible
184
- })}
185
- >
186
- <div class="gui-range-calendar__pills" role="list">
187
- <span class="gui-sentinel gui-sentinel__start"></span>
188
- ${M(
189
- e,
190
- (t) => `${t.start}-${t.end ?? t.start}`,
191
- (t, i) => this.renderPill(t, i)
192
- )}
193
- <span class="gui-sentinel gui-sentinel__end"></span>
194
- </div>
195
- </div>
196
- `;
197
- }
198
- renderPill(e, t) {
199
- const i = this.formatDateForDisplay(e.start), a = e.end ? this.formatDateForDisplay(e.end) : i, n = `${i} - ${a}`;
200
- return v`
201
- <div
202
- class="gui-range-calendar__pill"
203
- role="listitem"
204
- tabindex="0"
205
- aria-label="${this.removePillAriaLabel ?? "Remove date"} ${n}"
206
- @click=${() => this.navigateToDate(e.start)}
207
- @keydown=${(s) => this.handlePillKeydown(s, t)}
208
- >
209
- <span class="gui-range-calendar__pill-text">${n}</span>
210
- <button
211
- type="button"
212
- class="gui-range-calendar__pill-remove"
213
- tabindex="-1"
214
- ?disabled=${this.disabled || this.readOnly}
215
- @click=${(s) => {
216
- s.stopPropagation(), this.removePill(t);
217
- }}
218
- >
219
- <svg
220
- xmlns="http://www.w3.org/2000/svg"
221
- width="16"
222
- height="16"
223
- viewBox="0 0 256 256"
224
- fill="currentColor"
225
- aria-hidden="true"
226
- >
227
- <path
228
- d="M165.66,101.66,139.31,128l26.35,26.34a8,8,0,0,1-11.32,11.32L128,139.31l-26.34,26.35a8,8,0,0,1-11.32-11.32L116.69,128,90.34,101.66a8,8,0,0,1,11.32-11.32L128,116.69l26.34-26.35a8,8,0,0,1,11.32,11.32ZM232,128A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z"
229
- ></path>
230
- </svg>
231
- </button>
232
- </div>
233
- `;
234
- }
235
- formatDateForDisplay(e) {
236
- const t = new Date(e);
237
- return isNaN(t.getTime()) ? e : new Intl.DateTimeFormat(this.localeId ?? "en", {
238
- year: "numeric",
239
- month: "2-digit",
240
- day: "2-digit"
241
- }).format(t);
242
- }
243
- getSortedPills() {
244
- return !this.value || !Array.isArray(this.value) ? [] : [...this.value].sort(
245
- (e, t) => new Date(e.start).getTime() - new Date(t.start).getTime()
246
- );
247
- }
248
- removePill(e) {
249
- if (this.disabled || this.readOnly) return;
250
- const t = this.getSortedPills();
251
- t.splice(e, 1), this.value = [...t], this.dispatchEvent(
252
- new CustomEvent("change", {
253
- detail: { value: this.value },
254
- bubbles: !0,
255
- composed: !0
256
- })
257
- );
258
- }
259
- handlePillKeydown(e, t) {
260
- if (e.key === "Delete" || e.key === "Backspace") {
261
- e.preventDefault(), this.removePill(t);
262
- return;
263
- }
264
- if (e.key === "Enter") {
265
- e.preventDefault();
266
- const i = this.getSortedPills();
267
- i[t] && this.navigateToDate(i[t].start);
268
- return;
269
- }
270
- if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
271
- e.preventDefault();
272
- const i = this.querySelectorAll(
273
- ".gui-range-calendar__pills .gui-range-calendar__pill"
274
- ), a = e.key === "ArrowLeft" ? t - 1 : t + 1;
275
- a >= 0 && a < i.length && i[a].focus();
276
- }
277
- }
278
- navigateToDate(e) {
279
- const t = new Date(e);
280
- !isNaN(t.getTime()) && !d(t, this._currentDate, this.numberOfMonths ?? 1) && (this._currentDate = t);
281
- }
282
- setupObservers() {
283
- const e = this.querySelector(".gui-sentinel__start"), t = this.querySelector(".gui-sentinel__end");
284
- e && !this.startObserver && (this.startObserver = w(
285
- e,
286
- (i) => this._isStartVisible = i
287
- )), t && !this.endObserver && (this.endObserver = w(
288
- t,
289
- (i) => this._isEndVisible = i
290
- )), !e && this.startObserver && (this.startObserver.disconnect(), this.startObserver = void 0, this._isStartVisible = !0), !t && this.endObserver && (this.endObserver.disconnect(), this.endObserver = void 0, this._isEndVisible = !0);
291
- }
292
- disconnectObservers() {
293
- this.startObserver?.disconnect(), this.endObserver?.disconnect(), this.startObserver = void 0, this.endObserver = void 0;
294
- }
295
- };
296
- h([
297
- f({ type: Array })
298
- ], l.prototype, "value", 2);
299
- h([
300
- f({ type: String })
301
- ], l.prototype, "focusDate", 2);
302
- h([
303
- f({ type: Boolean })
304
- ], l.prototype, "hidePills", 2);
305
- h([
306
- f({ type: String })
307
- ], l.prototype, "removePillAriaLabel", 2);
308
- h([
309
- g()
310
- ], l.prototype, "_anchorDate", 2);
311
- h([
312
- g()
313
- ], l.prototype, "_nextDate", 2);
314
- h([
315
- g()
316
- ], l.prototype, "_isSelecting", 2);
317
- h([
318
- g()
319
- ], l.prototype, "_isStartVisible", 2);
320
- h([
321
- g()
322
- ], l.prototype, "_isEndVisible", 2);
323
- l = h([
324
- R("gui-range-calendar")
325
- ], l);
326
- typeof customElements < "u" && !customElements.get("gui-range-calendar") && customElements.define("gui-range-calendar", l);