UNPKG

@progress/kendo-vue-dateinputs

Version:
140 lines (139 loc) 4.13 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import "@progress/kendo-vue-intl"; import { addMonths as h, firstDayOfMonth as y, lastDayOfMonth as D, dayOfWeek as F, addDays as g, getDate as u, durationInMonths as d, addWeeks as I } from "@progress/kendo-date-math"; import { Action as o } from "../models/NavigationAction.mjs"; import { EMPTY_SELECTIONRANGE as O } from "../models/SelectionRange.mjs"; import { range as w, getToday as W, isInSelectionRange as Y, isInRange as T } from "../../utils.mjs"; const U = [[]], S = 7, _ = 6, $ = 6, C = 0, G = { [o.Left]: (r) => g(r, -1), [o.Up]: (r) => I(r, -1), [o.Right]: (r) => g(r, 1), [o.Down]: (r) => I(r, 1), [o.PrevView]: (r) => h(r, -1), [o.NextView]: (r) => h(r, 1), [o.FirstInView]: (r) => y(r), [o.LastInView]: (r) => D(r) }; class X { constructor(t) { this.intl = t; } addToDate(t, e) { return h(t, e); } datesList(t, e) { return w(0, e).map((n) => h(t, n)); } data(t) { const { cellUID: e, focusedDate: n, isActiveView: l, max: s, min: a, selectedDate: c, selectionRange: m = O, viewDate: f } = t; if (!f) return U; const M = y(f), p = D(f), N = F(M, this.intl.firstDay(), -1), b = w(0, S), q = W(); return w(0, _).map((V) => { const v = g(N, V * S); return b.map((L) => { const i = this.normalize(g(v, L), a, s); if (i < M || i > p) return null; const R = this.isEqual(i, m.start), A = this.isEqual(i, m.end), E = !R && !A && Y(i, m), k = l && (Array.isArray(c) ? this.isSelectedFromArray(i, c, a, s) : T(c, a, s) && this.isEqual(i, c)); return { formattedValue: this.value(i), id: `${e}${i.getTime()}`, isFocused: this.isEqual(i, n), isSelected: k, isInRange: T(i, a, s), isWeekend: this.isWeekend(i), isRangeStart: R, isRangeMid: E, isRangeEnd: A, isRangeSplitStart: E && this.isEqual(i, M), isRangeSplitEnd: E && this.isEqual(i, p), isToday: this.isEqual(i, q), title: this.cellTitle(i), value: i }; }); }); } isEqual(t, e) { return !t || !e ? !1 : u(t).getTime() === u(e).getTime(); } isSelectedFromArray(t, e, n, l) { let s = !1; return e.forEach((a) => { T(t, n, l) && this.isEqual(t, a) && (s = !0); }), s; } isInArray(t, e) { return !!e.length && y(e[0]) <= t && t <= D(e[e.length - 1]); } isInRange(t, e, n) { const l = u(t), s = !e || u(e) <= l, a = !n || l <= u(n); return s && a; } isInSameView(t, e) { return d(t, e) === 0; } isRangeStart(t) { return !t.getMonth(); } move(t, e) { const n = G[e]; return n ? n(t) : t; } cellTitle(t) { return this.intl.formatDate(t, "D"); } navigationTitle(t) { return t ? this.isRangeStart(t) ? t.getFullYear().toString() : this.abbrMonthNames()[t.getMonth()] : ""; } title(t) { return `${this.wideMonthNames()[t.getMonth()]} ${t.getFullYear()}`; } rowLength(t) { return S + (t ? 1 : 0); } skip(t, e) { return d(e, t); } total(t, e) { return d(t, e) + 1; } value(t) { return t ? t.getDate().toString() : ""; } viewDate(t, e, n = 1) { return d(t, e) < n ? h(t, -1) : t; } isWeekend(t) { const e = t.getDay(); return e === $ || e === C; } abbrMonthNames() { return this.intl.dateFormatNames({ nameType: "abbreviated", type: "months" }); } normalize(t, e, n) { return t < e && this.isEqual(t, e) ? u(e) : t > n && this.isEqual(t, n) ? u(n) : t; } wideMonthNames() { return this.intl.dateFormatNames({ nameType: "wide", type: "months", standAlone: !0 }); } } export { X as MonthViewService };