@mhmo91/schmancy 0.4.5 → 0.4.7

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