UNPKG

@progress/kendo-vue-dateinputs

Version:
261 lines (260 loc) 7.36 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 { defineComponent as w, inject as D, createVNode as r, h as u, isVNode as S, createTextVNode as R } from "vue"; import { weekInYear as y, cloneDate as l } from "@progress/kendo-date-math"; import { provideIntlService as b } from "@progress/kendo-vue-intl"; import { getTemplate as c } from "@progress/kendo-vue-common"; import { CalendarCell as $ } from "./CalendarCell.mjs"; import { CalendarWeekCell as C } from "./CalendarWeekCell.mjs"; import { CalendarViewEnum as p } from "../models/CalendarViewEnum.mjs"; import { getToday as h, setTime as V } from "../../utils.mjs"; import { WeekNamesService as W } from "../services/WeekNamesService.mjs"; function M(t) { return typeof t == "function" || Object.prototype.toString.call(t) === "[object Object]" && !S(t); } const A = /* @__PURE__ */ w({ name: "KendoView", inject: { kendoIntlService: { default: null } }, props: { activeRangeEnd: { type: String }, activeView: { type: Number, required: !0 }, cell: [String, Function, Object], cellUID: { type: String, required: !0 }, direction: { type: String, default: "vertical" }, isActive: { type: Boolean, default: void 0 }, focusedDate: { type: Date, required: !0 }, max: { type: Date, required: !0 }, min: { type: Date, required: !0 }, selectedDate: { type: [Date, Array, Object], default: function() { return h(); } }, selectionRange: Object, showWeekNumbers: { type: Boolean, default: !1 }, viewDate: { type: Date, required: !0 }, weekCell: [String, Function, Object], bus: Object, service: Object, onChange: Function, onWeekcellclick: Function, onCellenter: Function, onViewmousedown: Function }, computed: { isHorizontal() { return this.$props.direction === "horizontal"; }, isMonthView() { return this.$props.activeView === p.month; }, weekNumber() { return !!(this.$props.showWeekNumbers && this.$props.activeView === p.month); } }, methods: { getWeekNumber(t) { return this.weekNumber ? y(t, this._intl.firstDay()) : null; }, firstDate(t) { const i = this.firstWeekDateContext(t); return i ? i.value : null; }, firstWeekDateContext(t) { if (!this.weekNumber) return null; let i = 0, n = t[i]; for (; !n && i < t.length; ) n = t[++i]; return n; }, handleClick(t, i) { const n = { value: l(t), target: this, event: i }; this.$emit("change", n); }, handleWeekCellClick(t, i) { const n = { value: t, event: i }; this.$emit("weekcellclick", n); }, handleMouseDown(t, i) { const n = { value: l(t), target: this, event: i }; this.$emit("viewmousedown", n); }, handleMouseEnter(t) { this.$emit("cellenter", l(t)); }, handleMouseLeave(t) { this.$emit("cellleave", l(t)); } }, setup() { return { kendoIntlService: D("kendoIntlService", {}) }; }, render() { this._intl = b(this), this._weekService = new W(this._intl); const t = (a) => r("td", { key: a, class: "k-calendar-td k-empty" }, [R(" ")]), i = h(), n = this.$props.isActive ? this.$props.focusedDate : null, m = V(this.$props.viewDate, i), k = this.$props.service.data({ cellUID: this.$props.cellUID, min: this.$props.min, max: this.$props.max, focusedDate: n, isActiveView: !this.$props.bus.canMoveDown(this.$props.activeView), selectedDate: this.$props.selectedDate, selectionRange: this.$props.selectionRange, viewDate: m }), f = function(a, e) { if (!this.firstDate(a)) return t(`week-cell-${e}`); const s = this.getWeekNumber(this.firstDate(a)), o = `kendo-vue-calendar-week-cell-${s}`, v = r(C, { class: "k-calendar-td k-alt", value: s, onClick: this.handleWeekCellClick, key: o }, M(s) ? s : { default: () => [s] }); return c.call(this, { h: u, template: this.$props.weekCell, defaultRendering: v, defaultSlots: s, additionalListeners: { click: this.handleWeekCellClick }, additionalProps: { value: s, key: o } }); }, g = function(a) { return a.map(function(e, d) { if (!e) return t(d); const s = `kendo-vue-calendar-cell-${e.value.getTime()}`, o = r($, { "aria-selected": e.isSelected, formattedValue: e.formattedValue, id: e.id, isFocused: e.isFocused, isSelected: e.isSelected, isInRange: e.isInRange, isWeekend: e.isWeekend, isRangeStart: e.isRangeStart, isRangeMid: e.isRangeMid, isRangeEnd: e.isRangeEnd, isRangeSplitStart: e.isRangeSplitStart, isRangeSplitEnd: e.isRangeSplitEnd, isToday: e.isToday, title: e.title, value: e.value, isDisabled: !e.isInRange, view: this.$props.activeView, onClick: this.handleClick, onMousedown: this.handleMouseDown, onMouseenter: this.handleMouseEnter, onMouseleave: this.handleMouseLeave, key: s }, { default: () => [e.formattedValue] }); return c.call(this, { h: u, template: this.$props.cell, defaultRendering: o, defaultSlots: e.formattedValue, additionalListeners: { click: this.handleClick, mousedown: this.handleMouseDown, mouseenter: this.handleMouseEnter, mouseleave: this.handleMouseLeave }, additionalProps: { formattedValue: e.formattedValue, id: e.id, isFocused: e.isFocused, isSelected: e.isSelected, isInRange: e.isInRange, isWeekend: e.isWeekend, isRangeStart: e.isRangeStart, isRangeMid: e.isRangeMid, isRangeEnd: e.isRangeEnd, isRangeSplitStart: e.isRangeSplitStart, isRangeSplitEnd: e.isRangeSplitEnd, isToday: e.isToday, title: e.title, value: e.value, isDisabled: !e.isInRange, view: this.$props.activeView, key: s } }); }, this); }; return r("tbody", { class: "k-calendar-tbody", role: "rowgroup" }, [k.map(function(a, e) { return r("tr", { class: "k-calendar-tr", role: "row", key: e }, [this.weekNumber && f.call(this, a, e), g.call(this, a)]); }, this)]); } }); export { A as View };