@mhmo91/schmancy 0.4.38 → 0.4.40

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