@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.33 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
*-------------------------------------------------------------------------------------------
*/
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@progress/kendo-date-math"),l=require("../models/NavigationAction.js"),u=require("../../utils.js"),m=require("../models/SelectionRange.js"),v=[[]],f=4,y=3,V=r=>r>4?-5:r<2?-2:-7,p=r=>r<7?5:r<10?7:2,N={[l.Action.Left]:r=>n.addMonths(r,-1),[l.Action.Up]:r=>n.addMonths(r,V(r.getMonth())),[l.Action.Right]:r=>n.addMonths(r,1),[l.Action.Down]:r=>n.addMonths(r,p(r.getMonth())),[l.Action.PrevView]:r=>n.addYears(r,-1),[l.Action.NextView]:r=>n.addYears(r,1),[l.Action.FirstInView]:r=>n.firstMonthOfYear(r),[l.Action.LastInView]:r=>n.lastMonthOfYear(r)};class L{constructor(e){this._intl=e}addToDate(e,t){return n.addYears(e,t)}datesList(e,t){return u.range(0,t).map(a=>n.addYears(e,a))}data(e){const{cellUID:t,focusedDate:a,isActiveView:c,max:i,min:o,selectedDate:g,selectionRange:h=m.EMPTY_SELECTIONRANGE,viewDate:d}=e;if(!d)return v;const A=this.abbrMonthNames(),Y=n.firstMonthOfYear(d),I=n.lastMonthOfYear(d),w=Y.getFullYear(),F=u.range(0,f),T=u.getToday();return u.range(0,y).map(R=>{const q=n.addMonths(Y,R*f);return F.map(D=>{const s=this.normalize(n.addMonths(q,D),o,i);if(w<s.getFullYear())return null;const E=this.isEqual(s,h.start),S=this.isEqual(s,h.end),M=!E&&!S&&u.isInSelectionRange(s,h),b=c&&(Array.isArray(g)?this.isSelectedFromArray(s,g,o,i):u.isInRange(g,o,i)&&this.isEqual(s,g));return{formattedValue:A[s.getMonth()],id:`${t}${s.getTime()}`,isFocused:this.isEqual(s,a),isSelected:b,isInRange:u.isInRange(s,o,i),isWeekend:!1,isRangeStart:E,isRangeMid:M,isRangeEnd:S,isRangeSplitEnd:M&&this.isEqual(s,I),isRangeSplitStart:M&&this.isEqual(s,Y),isToday:this.isEqual(s,T),title:this.cellTitle(s),value:s}})})}isSelectedFromArray(e,t,a,c){let i=!1;return t.forEach(o=>{u.isInRange(e,a,c)&&this.isEqual(e,o)&&(i=!0)}),i}isEqual(e,t){return!e||!t?!1:e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()}isInArray(e,t){if(!t.length)return!1;const a=e.getFullYear();return t[0].getFullYear()<=a&&a<=t[t.length-1].getFullYear()}isInRange(e,t,a){const c=n.createDate(e.getFullYear(),e.getMonth(),1),i=!t||n.createDate(t.getFullYear(),t.getMonth(),1)<=c,o=!a||c<=n.createDate(a.getFullYear(),a.getMonth(),1);return i&&o}isInSameView(e,t){return n.durationInYears(e,t)===0}isRangeStart(e){return e.getFullYear()%10===0}move(e,t){const a=N[t];return a?a(e):e}cellTitle(e){return`${e.getFullYear()} ${this.value(e)}`}navigationTitle(e){return this.title(e)}title(e){return e?e.getFullYear().toString():""}rowLength(e){return f}skip(e,t){return n.durationInYears(t,e)}total(e,t){return n.durationInYears(e,t)+1}value(e){return e?this.abbrMonthNames()[e.getMonth()]:""}viewDate(e,t,a=1){return n.durationInYears(e,t)<a?n.addYears(e,-1):e}abbrMonthNames(){return this._intl.dateFormatNames({nameType:"abbreviated",type:"months"})}normalize(e,t,a){return e<t&&this.isEqual(e,t)?n.cloneDate(t):e>a&&this.isEqual(e,a)?n.cloneDate(a):e}}exports.YearViewService=L;