@progress/kendo-react-dateinputs
Version:
React DateInput is a perfect input component for handling quick and efficient date values. KendoReact Date Inputs package
9 lines (8 loc) • 3.36 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@progress/kendo-date-math"),l=require("../models/NavigationAction.js"),v=require("../models/SelectionRange.js"),h=require("../../utils.js"),O=[[]],f=7,p=6,V=6,k=0,L={[l.Action.Left]:a=>n.addDays(a,-1),[l.Action.Up]:a=>n.addWeeks(a,-1),[l.Action.Right]:a=>n.addDays(a,1),[l.Action.Down]:a=>n.addWeeks(a,1),[l.Action.PrevView]:a=>n.addMonths(a,-1),[l.Action.NextView]:a=>n.addMonths(a,1),[l.Action.FirstInView]:a=>n.firstDayOfMonth(a),[l.Action.LastInView]:a=>n.lastDayOfMonth(a)};class F{constructor(t){this.intl=t}addToDate(t,e){return n.addMonths(t,e)}datesList(t,e){return h.range(0,e).map(s=>n.addMonths(t,s))}data(t){const{cellUID:e,focusedDate:s,isActiveView:c,max:r,min:o,selectedDate:u,selectionRange:d=v.EMPTY_SELECTIONRANGE,viewDate:g}=t;if(!g)return O;const M=n.firstDayOfMonth(g),y=n.lastDayOfMonth(g),w=n.dayOfWeek(M,this.intl.firstDay(),-1),E=h.range(0,f),T=h.getToday();return h.range(0,p).map(I=>{const R=n.addDays(w,I*f);return E.map(q=>{const i=this.normalize(n.addDays(R,q),o,r),m=i<M||i>y,S=this.isEqual(i,d.start),A=this.isEqual(i,d.end),D=!S&&!A&&h.isInSelectionRange(i,d),N=c&&(Array.isArray(u)?this.isSelectedFromArray(i,u,o,r):h.isInRange(u,o,r)&&this.isEqual(i,u)),b=this.isEqual(i,s)&&!m;return{formattedValue:this.value(i),id:`${e}${i.getTime()}`,isFocused:b,isSelected:N,isInRange:h.isInRange(i,o,r),isWeekend:this.isWeekend(i),isRangeStart:S,isRangeMid:D,isRangeEnd:A,isRangeSplitStart:D&&this.isEqual(i,M),isRangeSplitEnd:D&&this.isEqual(i,y),isToday:this.isEqual(i,T),title:this.cellTitle(i),value:i,isOtherMonth:m}})})}isEqual(t,e){return!t||!e?!1:n.getDate(t).getTime()===n.getDate(e).getTime()}isSelectedFromArray(t,e,s,c){let r=!1;return e.forEach(o=>{h.isInRange(t,s,c)&&this.isEqual(t,o)&&(r=!0)}),r}isInArray(t,e){return!!e.length&&n.firstDayOfMonth(e[0])<=t&&t<=n.lastDayOfMonth(e[e.length-1])}isInRange(t,e,s){const c=n.getDate(t),r=!e||n.getDate(e)<=c,o=!s||c<=n.getDate(s);return r&&o}isInSameView(t,e){return n.durationInMonths(t,e)===0}isRangeStart(t){return!t.getMonth()}move(t,e){const s=L[e];return s?s(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 f+(t?1:0)}skip(t,e){return n.durationInMonths(e,t)}total(t,e){return n.durationInMonths(t,e)+1}value(t){return t?t.getDate().toString():""}viewDate(t,e,s=1){return n.durationInMonths(t,e)<s?n.addMonths(t,-1):t}isWeekend(t){const e=t.getDay();return e===V||e===k}abbrMonthNames(){return this.intl.dateFormatNames({nameType:"abbreviated",type:"months"})}normalize(t,e,s){return t<e&&this.isEqual(t,e)?n.getDate(e):t>s&&this.isEqual(t,s)?n.getDate(s):t}wideMonthNames(){return this.intl.dateFormatNames({nameType:"wide",type:"months",standAlone:!0})}}exports.MonthViewService=F;