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