UNPKG

@progress/kendo-vue-dateinputs

Version:
129 lines (128 loc) 3.79 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 { addCenturies as g, firstDecadeOfCentury as h, lastDecadeOfCentury as T, addDecades as c, firstYearOfDecade as o, durationInCenturies 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 m, getToday as N, isInSelectionRange as O, isInRange as w } from "../../utils.mjs"; const _ = [[]], Y = 4, $ = 3, b = { [l.Left]: (i) => c(i, -1), [l.Up]: (i) => c(i, -4), [l.Right]: (i) => c(i, 1), [l.Down]: (i) => c(i, 4), [l.PrevView]: (i) => g(i, -1), [l.NextView]: (i) => g(i, 1), [l.FirstInView]: (i) => h(i), [l.LastInView]: (i) => T(i) }; class W { addToDate(e, t) { return g(e, t); } datesList(e, t) { return m(0, t).map((r) => g(e, r)); } data(e) { const { cellUID: t, focusedDate: r, isActiveView: u, max: s, min: a, selectedDate: d, selectionRange: E = M, viewDate: S } = e; if (!S) return _; const q = m(0, Y), D = h(S), I = T(S), A = N(); return m(0, $).map((V) => { const L = c(D, V * Y); return q.map((C) => { const n = this.normalize(c(L, C), a, s); if (!this.isInSameView(n, I)) return null; const R = this.isEqual(n, E.start), y = this.isEqual(n, E.end), F = !R && !y && O(n, E), v = u && (Array.isArray(d) ? this.isSelectedFromArray(n, d, a, s) : w(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: w(n, a, s), isRangeStart: R, isRangeMid: F, isRangeEnd: y, isRangeSplitEnd: F && this.isEqual(n, I), isRangeSplitStart: F && this.isEqual(n, D), isToday: this.isEqual(n, A), title: this.cellTitle(n), value: n }; }); }); } isSelectedFromArray(e, t, r, u) { let s = !1; return t.forEach((a) => { w(e, r, u) && this.isEqual(e, a) && (s = !0); }), s; } isEqual(e, t) { return !e || !t ? !1 : o(e).getFullYear() === o(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() + 99; } isInRange(e, t, r) { const u = o(e).getFullYear(), s = !t || o(t).getFullYear() <= u, a = !r || u <= o(r).getFullYear(); return s && a; } isInSameView(e, t) { return f(e, t) === 0; } isRangeStart(e) { return e.getFullYear() % 1e3 === 0; } move(e, t) { const r = b[t]; return r ? r(e) : e; } cellTitle(e) { return o(e).getFullYear().toString(); } navigationTitle(e) { return e ? h(e).getFullYear().toString() : ""; } title(e) { return e ? `${h(e).getFullYear()} - ${T(e).getFullYear()}` : ""; } rowLength(e) { return Y; } skip(e, t) { return f(t, e); } total(e, t) { return f(e, t) + 1; } value(e) { return e ? o(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 { W as CenturyViewService };