@mhmo91/schmancy 0.4.39 → 0.4.41

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 (41) hide show
  1. package/ai/date-range.md +27 -1
  2. package/ai/store.md +31 -0
  3. package/dist/ai/date-range.md +27 -1
  4. package/dist/ai/store.md +31 -0
  5. package/dist/{avatar-sXepW60q.cjs → avatar-B3sAx50a.cjs} +2 -2
  6. package/dist/{avatar-sXepW60q.cjs.map → avatar-B3sAx50a.cjs.map} +1 -1
  7. package/dist/{avatar-CnJrdjfS.js → avatar-FYp7eVVT.js} +2 -2
  8. package/dist/{avatar-CnJrdjfS.js.map → avatar-FYp7eVVT.js.map} +1 -1
  9. package/dist/badge.cjs +1 -1
  10. package/dist/badge.js +1 -1
  11. package/dist/content-drawer.cjs +1 -1
  12. package/dist/content-drawer.js +1 -1
  13. package/dist/date-range-Bd0bZ5EG.cjs +133 -0
  14. package/dist/date-range-Bd0bZ5EG.cjs.map +1 -0
  15. package/dist/date-range-CTx08Buk.js +652 -0
  16. package/dist/date-range-CTx08Buk.js.map +1 -0
  17. package/dist/date-range.cjs +1 -1
  18. package/dist/date-range.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +3 -3
  21. package/dist/nav-drawer.cjs +1 -1
  22. package/dist/nav-drawer.js +1 -1
  23. package/dist/{selector-hook-DPe2CGKx.js → selector-hook-CIpuCUbr.js} +122 -122
  24. package/dist/{selector-hook-DPe2CGKx.js.map → selector-hook-CIpuCUbr.js.map} +1 -1
  25. package/dist/selector-hook-DB8RFC1y.cjs +2 -0
  26. package/dist/{selector-hook-Bf_lCnGW.cjs.map → selector-hook-DB8RFC1y.cjs.map} +1 -1
  27. package/dist/store.cjs +1 -1
  28. package/dist/store.js +1 -1
  29. package/dist/teleport.cjs +1 -1
  30. package/dist/teleport.js +1 -1
  31. package/package.json +2 -2
  32. package/types/src/autocomplete/autocomplete.d.ts +2 -3
  33. package/types/src/badge/badge.d.ts +3 -0
  34. package/types/src/date-range/date-range.d.ts +2 -1
  35. package/types/src/input/index.d.ts +1 -2
  36. package/types/src/input/input.d.ts +21 -0
  37. package/dist/date-range-CJq5E8y0.cjs +0 -131
  38. package/dist/date-range-CJq5E8y0.cjs.map +0 -1
  39. package/dist/date-range-DQ057kVi.js +0 -638
  40. package/dist/date-range-DQ057kVi.js.map +0 -1
  41. package/dist/selector-hook-Bf_lCnGW.cjs +0 -2
@@ -1,638 +0,0 @@
1
- import { fromEvent as ne, takeUntil as te, debounceTime as ge, timer as ve } from "rxjs";
2
- import "lit/directives/class-map.js";
3
- import "lit/directives/style-map.js";
4
- import { $ as le } from "./litElement.mixin-BH9PTyUD.js";
5
- import "./tailwind.mixin-CaIkmP6j.js";
6
- import { property as w, customElement as me, state as I } from "lit/decorators.js";
7
- import { g as pe } from "./_commonjsHelpers-Dw9sPFZy.js";
8
- import { html as U } from "lit";
9
- import { $ as G } from "./dialog-service-DFMlRcXf.js";
10
- import { ifDefined as K } from "lit/directives/if-defined.js";
11
- var ie, oe = { exports: {} }, be = (ie || (ie = 1, oe.exports = function() {
12
- var t = 1e3, a = 6e4, e = 36e5, o = "millisecond", h = "second", i = "minute", p = "hour", y = "day", S = "week", D = "month", b = "quarter", T = "year", v = "date", P = "Invalid Date", z = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, R = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, fe = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(c) {
13
- var n = ["th", "st", "nd", "rd"], s = c % 100;
14
- return "[" + c + (n[(s - 20) % 10] || n[s] || n[0]) + "]";
15
- } }, X = function(c, n, s) {
16
- var d = String(c);
17
- return !d || d.length >= n ? c : "" + Array(n + 1 - d.length).join(s) + c;
18
- }, ye = { s: X, z: function(c) {
19
- var n = -c.utcOffset(), s = Math.abs(n), d = Math.floor(s / 60), r = s % 60;
20
- return (n <= 0 ? "+" : "-") + X(d, 2, "0") + ":" + X(r, 2, "0");
21
- }, m: function c(n, s) {
22
- if (n.date() < s.date()) return -c(s, n);
23
- var d = 12 * (s.year() - n.year()) + (s.month() - n.month()), r = n.clone().add(d, D), l = s - r < 0, m = n.clone().add(d + (l ? -1 : 1), D);
24
- return +(-(d + (s - r) / (l ? r - m : m - r)) || 0);
25
- }, a: function(c) {
26
- return c < 0 ? Math.ceil(c) || 0 : Math.floor(c);
27
- }, p: function(c) {
28
- return { M: D, y: T, w: S, d: y, D: v, h: p, m: i, s: h, ms: o, Q: b }[c] || String(c || "").toLowerCase().replace(/s$/, "");
29
- }, u: function(c) {
30
- return c === void 0;
31
- } }, j = "en", H = {};
32
- H[j] = fe;
33
- var se = "$isDayjsObject", ee = function(c) {
34
- return c instanceof B || !(!c || !c[se]);
35
- }, Q = function c(n, s, d) {
36
- var r;
37
- if (!n) return j;
38
- if (typeof n == "string") {
39
- var l = n.toLowerCase();
40
- H[l] && (r = l), s && (H[l] = s, r = l);
41
- var m = n.split("-");
42
- if (!r && m.length > 1) return c(m[0]);
43
- } else {
44
- var g = n.name;
45
- H[g] = n, r = g;
46
- }
47
- return !d && r && (j = r), r || !d && j;
48
- }, M = function(c, n) {
49
- if (ee(c)) return c.clone();
50
- var s = typeof n == "object" ? n : {};
51
- return s.date = c, s.args = arguments, new B(s);
52
- }, f = ye;
53
- f.l = Q, f.i = ee, f.w = function(c, n) {
54
- return M(c, { locale: n.$L, utc: n.$u, x: n.$x, $offset: n.$offset });
55
- };
56
- var B = function() {
57
- function c(s) {
58
- this.$L = Q(s.locale, null, !0), this.parse(s), this.$x = this.$x || s.x || {}, this[se] = !0;
59
- }
60
- var n = c.prototype;
61
- return n.parse = function(s) {
62
- this.$d = function(d) {
63
- var r = d.date, l = d.utc;
64
- if (r === null) return /* @__PURE__ */ new Date(NaN);
65
- if (f.u(r)) return /* @__PURE__ */ new Date();
66
- if (r instanceof Date) return new Date(r);
67
- if (typeof r == "string" && !/Z$/i.test(r)) {
68
- var m = r.match(z);
69
- if (m) {
70
- var g = m[2] - 1 || 0, $ = (m[7] || "0").substring(0, 3);
71
- return l ? new Date(Date.UTC(m[1], g, m[3] || 1, m[4] || 0, m[5] || 0, m[6] || 0, $)) : new Date(m[1], g, m[3] || 1, m[4] || 0, m[5] || 0, m[6] || 0, $);
72
- }
73
- }
74
- return new Date(r);
75
- }(s), this.init();
76
- }, n.init = function() {
77
- var s = this.$d;
78
- this.$y = s.getFullYear(), this.$M = s.getMonth(), this.$D = s.getDate(), this.$W = s.getDay(), this.$H = s.getHours(), this.$m = s.getMinutes(), this.$s = s.getSeconds(), this.$ms = s.getMilliseconds();
79
- }, n.$utils = function() {
80
- return f;
81
- }, n.isValid = function() {
82
- return this.$d.toString() !== P;
83
- }, n.isSame = function(s, d) {
84
- var r = M(s);
85
- return this.startOf(d) <= r && r <= this.endOf(d);
86
- }, n.isAfter = function(s, d) {
87
- return M(s) < this.startOf(d);
88
- }, n.isBefore = function(s, d) {
89
- return this.endOf(d) < M(s);
90
- }, n.$g = function(s, d, r) {
91
- return f.u(s) ? this[d] : this.set(r, s);
92
- }, n.unix = function() {
93
- return Math.floor(this.valueOf() / 1e3);
94
- }, n.valueOf = function() {
95
- return this.$d.getTime();
96
- }, n.startOf = function(s, d) {
97
- var r = this, l = !!f.u(d) || d, m = f.p(s), g = function(E, Y) {
98
- var A = f.w(r.$u ? Date.UTC(r.$y, Y, E) : new Date(r.$y, Y, E), r);
99
- return l ? A : A.endOf(y);
100
- }, $ = function(E, Y) {
101
- return f.w(r.toDate()[E].apply(r.toDate("s"), (l ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(Y)), r);
102
- }, F = this.$W, x = this.$M, C = this.$D, V = "set" + (this.$u ? "UTC" : "");
103
- switch (m) {
104
- case T:
105
- return l ? g(1, 0) : g(31, 11);
106
- case D:
107
- return l ? g(1, x) : g(0, x + 1);
108
- case S:
109
- var L = this.$locale().weekStart || 0, W = (F < L ? F + 7 : F) - L;
110
- return g(l ? C - W : C + (6 - W), x);
111
- case y:
112
- case v:
113
- return $(V + "Hours", 0);
114
- case p:
115
- return $(V + "Minutes", 1);
116
- case i:
117
- return $(V + "Seconds", 2);
118
- case h:
119
- return $(V + "Milliseconds", 3);
120
- default:
121
- return this.clone();
122
- }
123
- }, n.endOf = function(s) {
124
- return this.startOf(s, !1);
125
- }, n.$set = function(s, d) {
126
- var r, l = f.p(s), m = "set" + (this.$u ? "UTC" : ""), g = (r = {}, r[y] = m + "Date", r[v] = m + "Date", r[D] = m + "Month", r[T] = m + "FullYear", r[p] = m + "Hours", r[i] = m + "Minutes", r[h] = m + "Seconds", r[o] = m + "Milliseconds", r)[l], $ = l === y ? this.$D + (d - this.$W) : d;
127
- if (l === D || l === T) {
128
- var F = this.clone().set(v, 1);
129
- F.$d[g]($), F.init(), this.$d = F.set(v, Math.min(this.$D, F.daysInMonth())).$d;
130
- } else g && this.$d[g]($);
131
- return this.init(), this;
132
- }, n.set = function(s, d) {
133
- return this.clone().$set(s, d);
134
- }, n.get = function(s) {
135
- return this[f.p(s)]();
136
- }, n.add = function(s, d) {
137
- var r, l = this;
138
- s = Number(s);
139
- var m = f.p(d), g = function(x) {
140
- var C = M(l);
141
- return f.w(C.date(C.date() + Math.round(x * s)), l);
142
- };
143
- if (m === D) return this.set(D, this.$M + s);
144
- if (m === T) return this.set(T, this.$y + s);
145
- if (m === y) return g(1);
146
- if (m === S) return g(7);
147
- var $ = (r = {}, r[i] = a, r[p] = e, r[h] = t, r)[m] || 1, F = this.$d.getTime() + s * $;
148
- return f.w(F, this);
149
- }, n.subtract = function(s, d) {
150
- return this.add(-1 * s, d);
151
- }, n.format = function(s) {
152
- var d = this, r = this.$locale();
153
- if (!this.isValid()) return r.invalidDate || P;
154
- var l = s || "YYYY-MM-DDTHH:mm:ssZ", m = f.z(this), g = this.$H, $ = this.$m, F = this.$M, x = r.weekdays, C = r.months, V = r.meridiem, L = function(Y, A, N, J) {
155
- return Y && (Y[A] || Y(d, l)) || N[A].slice(0, J);
156
- }, W = function(Y) {
157
- return f.s(g % 12 || 12, Y, "0");
158
- }, E = V || function(Y, A, N) {
159
- var J = Y < 12 ? "AM" : "PM";
160
- return N ? J.toLowerCase() : J;
161
- };
162
- return l.replace(R, function(Y, A) {
163
- return A || function(N) {
164
- switch (N) {
165
- case "YY":
166
- return String(d.$y).slice(-2);
167
- case "YYYY":
168
- return f.s(d.$y, 4, "0");
169
- case "M":
170
- return F + 1;
171
- case "MM":
172
- return f.s(F + 1, 2, "0");
173
- case "MMM":
174
- return L(r.monthsShort, F, C, 3);
175
- case "MMMM":
176
- return L(C, F);
177
- case "D":
178
- return d.$D;
179
- case "DD":
180
- return f.s(d.$D, 2, "0");
181
- case "d":
182
- return String(d.$W);
183
- case "dd":
184
- return L(r.weekdaysMin, d.$W, x, 2);
185
- case "ddd":
186
- return L(r.weekdaysShort, d.$W, x, 3);
187
- case "dddd":
188
- return x[d.$W];
189
- case "H":
190
- return String(g);
191
- case "HH":
192
- return f.s(g, 2, "0");
193
- case "h":
194
- return W(1);
195
- case "hh":
196
- return W(2);
197
- case "a":
198
- return E(g, $, !0);
199
- case "A":
200
- return E(g, $, !1);
201
- case "m":
202
- return String($);
203
- case "mm":
204
- return f.s($, 2, "0");
205
- case "s":
206
- return String(d.$s);
207
- case "ss":
208
- return f.s(d.$s, 2, "0");
209
- case "SSS":
210
- return f.s(d.$ms, 3, "0");
211
- case "Z":
212
- return m;
213
- }
214
- return null;
215
- }(Y) || m.replace(":", "");
216
- });
217
- }, n.utcOffset = function() {
218
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
219
- }, n.diff = function(s, d, r) {
220
- var l, m = this, g = f.p(d), $ = M(s), F = ($.utcOffset() - this.utcOffset()) * a, x = this - $, C = function() {
221
- return f.m(m, $);
222
- };
223
- switch (g) {
224
- case T:
225
- l = C() / 12;
226
- break;
227
- case D:
228
- l = C();
229
- break;
230
- case b:
231
- l = C() / 3;
232
- break;
233
- case S:
234
- l = (x - F) / 6048e5;
235
- break;
236
- case y:
237
- l = (x - F) / 864e5;
238
- break;
239
- case p:
240
- l = x / e;
241
- break;
242
- case i:
243
- l = x / a;
244
- break;
245
- case h:
246
- l = x / t;
247
- break;
248
- default:
249
- l = x;
250
- }
251
- return r ? l : f.a(l);
252
- }, n.daysInMonth = function() {
253
- return this.endOf(D).$D;
254
- }, n.$locale = function() {
255
- return H[this.$L];
256
- }, n.locale = function(s, d) {
257
- if (!s) return this.$L;
258
- var r = this.clone(), l = Q(s, d, !0);
259
- return l && (r.$L = l), r;
260
- }, n.clone = function() {
261
- return f.w(this.$d, this);
262
- }, n.toDate = function() {
263
- return new Date(this.valueOf());
264
- }, n.toJSON = function() {
265
- return this.isValid() ? this.toISOString() : null;
266
- }, n.toISOString = function() {
267
- return this.$d.toISOString();
268
- }, n.toString = function() {
269
- return this.$d.toUTCString();
270
- }, c;
271
- }(), re = B.prototype;
272
- return M.prototype = re, [["$ms", o], ["$s", h], ["$m", i], ["$H", p], ["$W", y], ["$M", D], ["$y", T], ["$D", v]].forEach(function(c) {
273
- re[c[1]] = function(n) {
274
- return this.$g(n, c[0], c[1]);
275
- };
276
- }), M.extend = function(c, n) {
277
- return c.$i || (c(n, B, M), c.$i = !0), M;
278
- }, M.locale = Q, M.isDayjs = ee, M.unix = function(c) {
279
- return M(1e3 * c);
280
- }, M.en = H[j], M.Ls = H, M.p = {}, M;
281
- }()), oe.exports);
282
- const u = pe(be);
283
- var de, Z, ae, ue = { exports: {} };
284
- const $e = pe(de ? ue.exports : (de = 1, ue.exports = (Z = "month", ae = "quarter", function(t, a) {
285
- var e = a.prototype;
286
- e.quarter = function(i) {
287
- return this.$utils().u(i) ? Math.ceil((this.month() + 1) / 3) : this.month(this.month() % 3 + 3 * (i - 1));
288
- };
289
- var o = e.add;
290
- e.add = function(i, p) {
291
- return i = Number(i), this.$utils().p(p) === ae ? this.add(3 * i, Z) : o.bind(this)(i, p);
292
- };
293
- var h = e.startOf;
294
- e.startOf = function(i, p) {
295
- var y = this.$utils(), S = !!y.u(p) || p;
296
- if (y.p(i) === ae) {
297
- var D = this.quarter() - 1;
298
- return S ? this.month(3 * D).startOf(Z).startOf("day") : this.month(3 * D + 2).endOf(Z).endOf("day");
299
- }
300
- return h.bind(this)(i, p);
301
- };
302
- })));
303
- function he(t, a, e) {
304
- let o = t.quarter() + e * a, h = 0;
305
- for (; o > 4; ) o -= 4, h += 1;
306
- for (; o < 1; ) o += 4, h -= 1;
307
- const i = t.add(h, "year").month(3 * (o - 1)), p = i.daysInMonth(), y = Math.min(t.date(), p);
308
- return i.date(y);
309
- }
310
- function De(t, a) {
311
- return t.map((e) => ({ label: `Last ${e} Days`, range: { dateFrom: u().subtract(e - 1, "days").startOf("day").format(a), dateTo: u().endOf("day").format(a) }, step: "day" }));
312
- }
313
- function Te(t, a) {
314
- return t.map((e) => ({ label: `Last ${e} Weeks`, range: { dateFrom: u().subtract(e, "weeks").startOf("week").format(a), dateTo: u().endOf("day").format(a) }, step: "week" }));
315
- }
316
- function Me(t, a) {
317
- return t.map((e) => ({ label: `Last ${e} Months`, range: { dateFrom: u().subtract(e, "months").startOf("month").format(a), dateTo: u().endOf("day").format(a) }, step: "month" }));
318
- }
319
- function Fe(t, a) {
320
- return t.map((e) => ({ label: `Last ${e} Quarters`, range: { dateFrom: u().subtract(e, "quarters").startOf("quarter").format(a), dateTo: u().endOf("day").format(a) }, step: "quarter" }));
321
- }
322
- function ce(t, a) {
323
- if (!t) return null;
324
- const e = u(t);
325
- return e.isValid() ? e.format(a) : null;
326
- }
327
- function Oe(t, a, e) {
328
- const o = ce(t, e), h = ce(a, e);
329
- return { dateFrom: o, dateTo: h, isValid: o !== null && h !== null };
330
- }
331
- var we = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, _ = (t, a, e, o) => {
332
- for (var h, i = o > 1 ? void 0 : o ? Se(a, e) : a, p = t.length - 1; p >= 0; p--) (h = t[p]) && (i = (o ? h(a, e, i) : h(i)) || i);
333
- return o && i && we(a, e, i), i;
334
- };
335
- let q = class extends le() {
336
- constructor() {
337
- super(...arguments), this.type = "date", this.dateFrom = { label: "From", value: "" }, this.dateTo = { label: "To", value: "" }, this.activePreset = null, this.presetCategories = [];
338
- }
339
- handleFromDateChange(t) {
340
- const a = t.target;
341
- this.dateFrom = { ...this.dateFrom, value: a.value }, this.dateTo.value && u(this.dateFrom.value).isAfter(u(this.dateTo.value)) && (this.dateTo = { ...this.dateTo, value: this.dateFrom.value }), this.dispatchEvent(new CustomEvent("date-change", { detail: { dateFrom: this.dateFrom.value, dateTo: this.dateTo.value }, bubbles: !0, composed: !0 }));
342
- }
343
- handleToDateChange(t) {
344
- const a = t.target;
345
- this.dateTo = { ...this.dateTo, value: a.value }, this.dispatchEvent(new CustomEvent("date-change", { detail: { dateFrom: this.dateFrom.value, dateTo: this.dateTo.value }, bubbles: !0, composed: !0 }));
346
- }
347
- handlePresetSelection(t, a) {
348
- a.stopPropagation(), this.dispatchEvent(new CustomEvent("preset-select", { detail: { preset: t }, bubbles: !0, composed: !0 })), G.dismiss();
349
- }
350
- applyManualDateSelection(t) {
351
- t.stopPropagation();
352
- const a = u(this.dateFrom.value), e = u(this.dateTo.value);
353
- a.isValid() && e.isValid() ? (this.dispatchEvent(new CustomEvent("apply-dates", { detail: { dateFrom: this.dateFrom.value, dateTo: this.dateTo.value, swapIfNeeded: a.isAfter(e) }, bubbles: !0, composed: !0 })), G.dismiss()) : this.dispatchEvent(new CustomEvent("announce", { detail: { message: "Invalid date format. Please check your input." }, bubbles: !0, composed: !0 }));
354
- }
355
- render() {
356
- return U`
357
- <div class="w-full min-h-[400px] max-h-[80vh] flex flex-col p-4">
358
- <!-- Custom Range Section with Inline Calendars -->
359
- <schmancy-surface type="container" class="rounded-xl p-4 mb-6">
360
- <div class="flex flex-col gap-4">
361
- <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
362
- <!-- From Date Calendar -->
363
- <div class="flex flex-col gap-2">
364
- <schmancy-typography type="label" token="md" class="text-surface-onVariant">
365
- ${this.dateFrom.label || "From"}
366
- </schmancy-typography>
367
- <schmancy-input
368
- type="${this.type}"
369
- .value="${this.dateFrom.value}"
370
- min="${K(this.minDate)}"
371
- max="${K(this.maxDate)}"
372
- @change="${this.handleFromDateChange}"
373
- ></schmancy-input>
374
- </div>
375
-
376
- <!-- To Date Calendar -->
377
- <div class="flex flex-col gap-2">
378
- <schmancy-typography type="label" token="md" class="text-surface-onVariant">
379
- ${this.dateTo.label || "To"}
380
- </schmancy-typography>
381
- <schmancy-input
382
- type="${this.type}"
383
- .value="${this.dateTo.value}"
384
- min="${K(this.dateFrom.value)}"
385
- max="${K(this.maxDate)}"
386
- @change="${this.handleToDateChange}"
387
- ></schmancy-input>
388
- </div>
389
- </div>
390
-
391
- <!-- Apply Button - Now at the bottom for logical flow -->
392
- <div class="flex justify-end mt-2">
393
- <schmancy-button
394
- variant="filled"
395
- @click="${(t) => this.applyManualDateSelection(t)}"
396
- ?disabled="${!this.dateFrom.value || !this.dateTo.value}"
397
- >
398
- Apply
399
- </schmancy-button>
400
- </div>
401
- </div>
402
- </schmancy-surface>
403
-
404
- <!-- Presets Section -->
405
- <div class="flex-1 overflow-y-auto overflow-x-hidden min-h-0">
406
- <div class="grid grid-cols-2 md:grid-cols-5 gap-6">
407
- ${this.presetCategories.map((t) => U`
408
- <div class="space-y-3">
409
- <schmancy-typography type="title" token="md" class="text-surface-onVariant font-medium">
410
- ${t.name}
411
- </schmancy-typography>
412
- <div class="space-y-1">
413
- ${t.presets.map((a) => U`
414
- <schmancy-button
415
- variant="${this.activePreset === a.label ? "filled" : "text"}"
416
- class="w-full justify-start text-left"
417
- @click="${(e) => this.handlePresetSelection(a, e)}"
418
- aria-pressed="${this.activePreset === a.label}"
419
- aria-label="${a.label}: ${a.range.dateFrom} to ${a.range.dateTo}"
420
- title="${a.range.dateFrom} to ${a.range.dateTo}"
421
- >
422
- <span class="truncate">${a.label}</span>
423
- </schmancy-button>
424
- `)}
425
- </div>
426
- </div>
427
- `)}
428
- </div>
429
- </div>
430
- </div>
431
- `;
432
- }
433
- };
434
- _([w({ type: String })], q.prototype, "type", 2), _([w({ type: Object })], q.prototype, "dateFrom", 2), _([w({ type: Object })], q.prototype, "dateTo", 2), _([w({ type: String })], q.prototype, "minDate", 2), _([w({ type: String })], q.prototype, "maxDate", 2), _([w({ type: String })], q.prototype, "activePreset", 2), _([w({ type: Array })], q.prototype, "presetCategories", 2), q = _([me("schmancy-date-range-dialog")], q);
435
- var ke = Object.defineProperty, xe = Object.getOwnPropertyDescriptor, k = (t, a, e, o) => {
436
- for (var h, i = o > 1 ? void 0 : o ? xe(a, e) : a, p = t.length - 1; p >= 0; p--) (h = t[p]) && (i = (o ? h(a, e, i) : h(i)) || i);
437
- return o && i && ke(a, e, i), i;
438
- };
439
- u.extend($e);
440
- let O = class extends le() {
441
- constructor() {
442
- super(...arguments), this.type = "date", this.dateFrom = { label: "From", value: "" }, this.dateTo = { label: "To", value: "" }, this.customPresets = [], this.disabled = !1, this.required = !1, this.placeholder = "Select date range", this.clearable = !0, this.isOpen = !1, this.selectedDateRange = "", this.activePreset = null, this.announceMessage = "", this.isMobile = !1, this.presetRanges = [], this.presetCategories = [], this.memoizedPresets = /* @__PURE__ */ new Map();
443
- }
444
- connectedCallback() {
445
- super.connectedCallback(), this.initPresetRanges(), this.checkMobileView();
446
- const t = this.getDateFormat(), a = Oe(this.dateFrom.value, this.dateTo.value, t);
447
- if (a.isValid) this.dateFrom.value = a.dateFrom, this.dateTo.value = a.dateTo, this.updateSelectedDateRange();
448
- else {
449
- const e = u().format(t);
450
- this.dateFrom.value = e, this.dateTo.value = e, this.updateSelectedDateRange();
451
- }
452
- this.setupEventHandlers();
453
- }
454
- setupEventHandlers() {
455
- ne(document, "keydown").pipe(te(this.disconnecting)).subscribe((t) => {
456
- this.handleKeyboardNavigation(t);
457
- }), ne(window, "resize").pipe(ge(150), te(this.disconnecting)).subscribe(() => {
458
- this.checkMobileView();
459
- });
460
- }
461
- disconnectedCallback() {
462
- super.disconnectedCallback();
463
- }
464
- updated(t) {
465
- super.updated(t), !t.has("dateFrom") && !t.has("dateTo") || this.dateFrom?.value === void 0 && this.dateTo?.value === void 0 || this.updateSelectedDateRange();
466
- }
467
- initPresetRanges() {
468
- const t = this.getDateFormat(), a = `${this.type}-${t}-${JSON.stringify(this.customPresets)}`;
469
- if (this.memoizedPresets.has(a)) {
470
- const e = this.memoizedPresets.get(a);
471
- return this.presetCategories = e, this.presetRanges = [], void e.forEach((o) => {
472
- this.presetRanges.push(...o.presets);
473
- });
474
- }
475
- if (this.presetCategories = function(e, o = !1) {
476
- const h = [];
477
- return o && h.push({ name: "Hours", presets: [{ label: "Last 24 Hours", range: { dateFrom: u().subtract(24, "hours").format(e), dateTo: u().format(e) }, step: "hour" }, { label: "Last 12 Hours", range: { dateFrom: u().subtract(12, "hours").format(e), dateTo: u().format(e) }, step: "hour" }] }), h.push({ name: "Days", presets: [{ label: "Today", range: { dateFrom: u().startOf("day").format(e), dateTo: u().endOf("day").format(e) }, step: "day" }, { label: "Yesterday", range: { dateFrom: u().subtract(1, "days").startOf("day").format(e), dateTo: u().subtract(1, "days").endOf("day").format(e) }, step: "day" }, ...De([7, 14, 30, 60, 90], e)] }), h.push({ name: "Weeks", presets: [{ label: "This Week", range: { dateFrom: u().startOf("week").format(e), dateTo: u().endOf("week").format(e) }, step: "week" }, { label: "Last Week", range: { dateFrom: u().subtract(1, "weeks").startOf("week").format(e), dateTo: u().subtract(1, "weeks").endOf("week").format(e) }, step: "week" }, ...Te([2, 4], e)] }), h.push({ name: "Months", presets: [{ label: "This Month", range: { dateFrom: u().startOf("month").format(e), dateTo: u().endOf("month").format(e) }, step: "month" }, { label: "Last Month", range: { dateFrom: u().subtract(1, "month").startOf("month").format(e), dateTo: u().subtract(1, "month").endOf("month").format(e) }, step: "month" }, ...Me([3, 6], e)] }), h.push({ name: "Quarters", presets: [{ label: "This Quarter", range: { dateFrom: u().startOf("quarter").format(e), dateTo: u().endOf("quarter").format(e) }, step: "quarter" }, { label: "Last Quarter", range: { dateFrom: u().subtract(1, "quarter").startOf("quarter").format(e), dateTo: u().subtract(1, "quarter").endOf("quarter").format(e) }, step: "quarter" }, ...Fe([2, 4], e)] }), h.push({ name: "Years", presets: [{ label: "This Year", range: { dateFrom: u().startOf("year").format(e), dateTo: u().endOf("year").format(e) }, step: "year" }, { label: "Last Year", range: { dateFrom: u().subtract(1, "year").startOf("year").format(e), dateTo: u().subtract(1, "year").endOf("year").format(e) }, step: "year" }, { label: "Year to Date", range: { dateFrom: u().startOf("year").format(e), dateTo: u().endOf("day").format(e) }, step: "day" }] }), h;
478
- }(t, this.type === "datetime-local"), this.presetRanges = [], this.presetCategories.forEach((e) => {
479
- this.presetRanges.push(...e.presets);
480
- }), this.customPresets && this.customPresets.length > 0) {
481
- const e = { name: "Custom", presets: this.customPresets.map((o) => ({ label: o.label, range: { dateFrom: o.dateFrom, dateTo: o.dateTo }, step: "day" })) };
482
- this.presetCategories.push(e), this.presetRanges.push(...e.presets);
483
- }
484
- this.memoizedPresets.set(a, [...this.presetCategories]);
485
- }
486
- getDateFormat() {
487
- return this.format || (this.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DDTHH:mm");
488
- }
489
- updateSelectedDateRange() {
490
- const t = this.presetRanges.find((a) => a.range.dateFrom === this.dateFrom.value && a.range.dateTo === this.dateTo.value);
491
- if (t) return this.selectedDateRange = t.label, void (this.activePreset = t.label);
492
- this.checkAndUpdateActivePreset(this.dateFrom.value, this.dateTo.value), this.activePreset = null, this.selectedDateRange = function(a, e, o, h) {
493
- if (!a || !e) return h;
494
- const i = u(a), p = u(e);
495
- if (!i.isValid() || !p.isValid()) return h;
496
- const y = o === "datetime-local" ? i.format(" h:mm A") : "", S = o === "datetime-local" ? p.format(" h:mm A") : "";
497
- return i.isSame(p, "day") ? `${i.format("MMM D, YYYY")}${y}` : i.isSame(p, "month") && i.isSame(p, "year") ? `${i.format("MMM D")}-${p.format("D, YYYY")}${S}` : i.isSame(p, "year") ? `${i.format("MMM D")} - ${p.format("MMM D, YYYY")}${S}` : `${i.format("MMM D, YYYY")}${y} - ${p.format("MMM D, YYYY")}${S}`;
498
- }(this.dateFrom.value, this.dateTo.value, this.type, this.placeholder);
499
- }
500
- setDateRange(t, a) {
501
- this.dateFrom.value = t, this.dateTo.value = a, this.updateSelectedDateRange(), this.announceToScreenReader(`Date range updated: ${this.selectedDateRange}`), this.dispatchEvent(new CustomEvent("change", { detail: { dateFrom: t, dateTo: a }, bubbles: !0, composed: !0 }));
502
- }
503
- toggleDropdown(t) {
504
- t.stopPropagation(), this.disabled || (this.isOpen ? this.closeDropdown() : this.openDropdown());
505
- }
506
- openDropdown() {
507
- if (this.disabled) return;
508
- this.isOpen = !0;
509
- const t = U`
510
- <schmancy-date-range-dialog
511
- .type="${this.type}"
512
- .dateFrom="${this.dateFrom}"
513
- .dateTo="${this.dateTo}"
514
- .minDate="${this.minDate}"
515
- .maxDate="${this.maxDate}"
516
- .activePreset="${this.activePreset}"
517
- .presetCategories="${this.presetCategories}"
518
- @preset-select="${(a) => {
519
- this.activePreset = a.detail.preset.label, this.setDateRange(a.detail.preset.range.dateFrom, a.detail.preset.range.dateTo);
520
- }}"
521
- @date-change="${() => this.updateSelectedDateRange()}"
522
- @apply-dates="${(a) => {
523
- const { dateFrom: e, dateTo: o, swapIfNeeded: h } = a.detail;
524
- h ? this.setDateRange(o, e) : this.setDateRange(e, o);
525
- }}"
526
- @announce="${(a) => this.announceToScreenReader(a.detail.message)}"
527
- ></schmancy-date-range-dialog>
528
- `;
529
- G.component(t, { title: "Select Date Range", width: this.isMobile ? "100vw" : "800px", hideActions: !0 }).then(() => {
530
- this.isOpen = !1;
531
- });
532
- }
533
- closeDropdown() {
534
- G.dismiss(), this.isOpen = !1;
535
- }
536
- shiftDateRange(t, a) {
537
- if (a.stopPropagation(), !this.dateFrom.value || !this.dateTo.value) return;
538
- const e = u(this.dateFrom.value), o = u(this.dateTo.value);
539
- if (!e.isValid() || !o.isValid()) return;
540
- const h = this.getDateFormat(), i = t > 0 ? 1 : -1, p = this.presetRanges.find((v) => v.label === this.activePreset), { unit: y, amount: S } = function(v, P, z) {
541
- if (z) return { unit: z, amount: 1 };
542
- const R = P.diff(v, "day");
543
- return R >= 360 ? { unit: "year", amount: Math.round(R / 365) } : R >= 90 ? { unit: "quarter", amount: Math.round(R / 90) } : R >= 30 ? { unit: "month", amount: Math.round(R / 30) } : R >= 7 ? { unit: "week", amount: Math.round(R / 7) } : { unit: "day", amount: R + 1 };
544
- }(e, o, p?.step), D = function(v, P) {
545
- return { isFullMonth: v.date() === 1 && P.isSame(v.endOf("month"), "day"), isFullQuarter: v.isSame(v.startOf("quarter"), "day") && P.isSame(P.endOf("quarter"), "day"), isFullYear: v.isSame(v.startOf("year"), "day") && P.isSame(P.endOf("year"), "day"), isFullWeek: v.day() === 0 && P.day() === 6 && P.diff(v, "days") === 6 };
546
- }(e, o);
547
- let b, T;
548
- if (y === "quarter") b = he(e, S, i), T = he(o, S, i), D.isFullQuarter && (b = b.startOf("quarter"), T = b.endOf("quarter"));
549
- else if (y === "hour") {
550
- const v = o.diff(e, "hour");
551
- b = i > 0 ? e.add(v, "hour") : e.subtract(v, "hour"), T = i > 0 ? o.add(v, "hour") : o.subtract(v, "hour");
552
- } else i > 0 ? (b = e.add(S, y), T = o.add(S, y)) : (b = e.subtract(S, y), T = o.subtract(S, y)), y === "year" && D.isFullYear ? (b = b.startOf("year"), T = b.endOf("year")) : y === "month" && D.isFullMonth ? (b = b.startOf("month"), T = b.endOf("month")) : y === "week" && D.isFullWeek && (b = b.startOf("week"), T = b.endOf("week"));
553
- this.setDateRange(b.format(h), T.format(h)), this.checkAndUpdateActivePreset(b.format(h), T.format(h));
554
- }
555
- handleKeyboardNavigation(t) {
556
- const a = t.key;
557
- if (this.dateFrom.value && this.dateTo.value && !this.disabled) switch (a) {
558
- case "PageUp":
559
- (t.target === this || this.contains(t.target)) && (this.shiftDateRange(-1, t), t.preventDefault());
560
- break;
561
- case "PageDown":
562
- (t.target === this || this.contains(t.target)) && (this.shiftDateRange(1, t), t.preventDefault());
563
- break;
564
- case "Home":
565
- if (t.ctrlKey && (t.target === this || this.contains(t.target))) {
566
- const e = u(this.dateFrom.value), o = u(this.dateTo.value), h = e.startOf("month"), i = o.diff(e, "day");
567
- this.setDateRange(h.format(this.getDateFormat()), h.add(i, "day").format(this.getDateFormat())), t.preventDefault();
568
- }
569
- break;
570
- case "End":
571
- if (t.ctrlKey && (t.target === this || this.contains(t.target))) {
572
- const e = u(this.dateFrom.value), o = u(this.dateTo.value), h = o.diff(e, "day"), i = o.endOf("month");
573
- this.setDateRange(i.subtract(h, "day").format(this.getDateFormat()), i.format(this.getDateFormat())), t.preventDefault();
574
- }
575
- }
576
- }
577
- checkAndUpdateActivePreset(t, a) {
578
- const e = this.presetRanges.find((o) => o.range.dateFrom === t && o.range.dateTo === a);
579
- this.activePreset = e ? e.label : null;
580
- }
581
- checkMobileView() {
582
- this.isMobile = window.innerWidth < 768;
583
- }
584
- announceToScreenReader(t) {
585
- this.announceMessage = t, ve(100).pipe(te(this.disconnecting)).subscribe(() => {
586
- this.announceMessage = "";
587
- });
588
- }
589
- render() {
590
- return U`
591
- <div class="relative ${this.disabled ? "opacity-60 pointer-events-none" : ""}">
592
- <!-- Screen reader announcements -->
593
- <div class="sr-only" role="status" aria-live="polite" aria-atomic="true">
594
- ${this.announceMessage}
595
- </div>
596
-
597
- <!-- Trigger using the preferred schmancy-grid pattern -->
598
- <section @click=${(t) => t.stopPropagation()} class="flex" >
599
- <schmancy-icon-button
600
- type="button"
601
- aria-label="Previous ${this.activePreset ? this.activePreset.toLowerCase() : "date range"}"
602
- @click=${(t) => this.shiftDateRange(-1, t)}
603
- ?disabled=${this.disabled || !this.dateFrom.value || !this.dateTo.value}
604
- >
605
- arrow_left
606
- </schmancy-icon-button>
607
-
608
- <schmancy-button
609
- class="w-max"
610
- variant="outlined"
611
- type="button"
612
- aria-haspopup="menu"
613
- aria-expanded=${this.isOpen}
614
- aria-label="Select date range. Current: ${this.selectedDateRange || "No date selected"}"
615
- @click=${(t) => this.toggleDropdown(t)}
616
- >
617
- ${this.selectedDateRange || this.placeholder}
618
- </schmancy-button>
619
-
620
- <schmancy-icon-button
621
- type="button"
622
- aria-label="Next ${this.activePreset ? this.activePreset.toLowerCase() : "date range"}"
623
- @click=${(t) => this.shiftDateRange(1, t)}
624
- ?disabled=${this.disabled || !this.dateFrom.value || !this.dateTo.value}
625
- >
626
- arrow_right
627
- </schmancy-icon-button>
628
- </section>
629
- </div>
630
- `;
631
- }
632
- };
633
- k([w({ type: String })], O.prototype, "type", 2), k([w({ type: Object })], O.prototype, "dateFrom", 2), k([w({ type: Object })], O.prototype, "dateTo", 2), k([w({ type: String })], O.prototype, "minDate", 2), k([w({ type: String })], O.prototype, "maxDate", 2), k([w({ type: Array })], O.prototype, "customPresets", 2), k([w({ type: String })], O.prototype, "format", 2), k([w({ type: Boolean })], O.prototype, "disabled", 2), k([w({ type: Boolean })], O.prototype, "required", 2), k([w({ type: String })], O.prototype, "placeholder", 2), k([w({ type: Boolean })], O.prototype, "clearable", 2), k([I()], O.prototype, "isOpen", 2), k([I()], O.prototype, "selectedDateRange", 2), k([I()], O.prototype, "activePreset", 2), k([I()], O.prototype, "announceMessage", 2), k([I()], O.prototype, "isMobile", 2), O = k([me("schmancy-date-range")], O);
634
- export {
635
- O as S,
636
- Oe as v
637
- };
638
- //# sourceMappingURL=date-range-DQ057kVi.js.map