UNPKG

@progress/kendo-vue-dateinputs

Version:
129 lines (128 loc) 3.73 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 { addDecades as g, firstYearOfDecade as c, lastYearOfDecade as w, addYears as u, durationInDecades as f, cloneDate as p } from "@progress/kendo-date-math"; import { Action as l } from "../models/NavigationAction.mjs"; import { EMPTY_SELECTIONRANGE as M } from "../models/SelectionRange.mjs"; import { range as Y, getToday as N, isInSelectionRange as O, isInRange as F } from "../../utils.mjs"; const _ = [[]], m = 4, $ = 3, b = { [l.Left]: (i) => u(i, -1), [l.Up]: (i) => u(i, -4), [l.Right]: (i) => u(i, 1), [l.Down]: (i) => u(i, 4), [l.PrevView]: (i) => g(i, -1), [l.NextView]: (i) => g(i, 1), [l.FirstInView]: (i) => c(i), [l.LastInView]: (i) => w(i) }; class U { addToDate(e, t) { return g(e, t); } datesList(e, t) { return Y(0, t).map((r) => g(c(e), r)); } data(e) { const { cellUID: t, focusedDate: r, isActiveView: o, max: s, min: a, selectedDate: d, selectionRange: h = M, viewDate: E } = e; if (!E) return _; const q = Y(0, m), D = c(E), T = w(E), A = N(); return Y(0, $).map((V) => { const y = u(D, V * m); return q.map((L) => { const n = this.normalize(u(y, L), a, s); if (!this.isInSameView(n, T)) return null; const I = this.isEqual(n, h.start), R = this.isEqual(n, h.end), S = !I && !R && O(n, h), v = o && (Array.isArray(d) ? this.isSelectedFromArray(n, d, a, s) : F(d, a, s) && this.isEqual(n, d)); return { formattedValue: this.value(n), id: `${t}${n.getTime()}`, isFocused: this.isEqual(n, r), isSelected: v, isWeekend: !1, isInRange: F(n, a, s), isRangeStart: I, isRangeMid: S, isRangeEnd: R, isRangeSplitEnd: S && this.isEqual(n, T), isRangeSplitStart: S && this.isEqual(n, D), isToday: this.isEqual(n, A), title: this.cellTitle(n), value: n }; }); }); } isSelectedFromArray(e, t, r, o) { let s = !1; return t.forEach((a) => { F(e, r, o) && this.isEqual(e, a) && (s = !0); }), s; } isEqual(e, t) { return !e || !t ? !1 : e.getFullYear() === t.getFullYear(); } isInArray(e, t) { if (!t.length) return !1; const r = e.getFullYear(); return t[0].getFullYear() <= r && r <= t[t.length - 1].getFullYear() + 9; } isInRange(e, t, r) { const o = e.getFullYear(), s = !t || t.getFullYear() <= o, a = !r || o <= r.getFullYear(); return s && a; } isRangeStart(e) { return e.getFullYear() % 100 === 0; } isInSameView(e, t) { return f(e, t) === 0; } move(e, t) { const r = b[t]; return r ? r(e) : e; } cellTitle(e) { return e.getFullYear().toString(); } navigationTitle(e) { return e ? c(e).getFullYear().toString() : ""; } title(e) { return e ? `${c(e).getFullYear()} - ${w(e).getFullYear()}` : ""; } rowLength(e) { return m; } skip(e, t) { return f(t, e); } total(e, t) { return f(e, t) + 1; } value(e) { return e ? e.getFullYear().toString() : ""; } viewDate(e, t, r = 1) { return f(e, t) < r ? g(e, -1) : e; } normalize(e, t, r) { return e < t && this.isEqual(e, t) ? p(t) : e > r && this.isEqual(e, r) ? p(r) : e; } } export { U as DecadeViewService };