vue-renderless-calendar
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,9 @@ | ||
## v2.3.0 | ||
### Added | ||
- Added type definitions | ||
- Added sourcemaps for dev mode | ||
### Fixed | ||
- Fixed incorrect behavior of `isOneDayBefore`, `isOneDayAfter`, `isOneDayBeforeLast`, `isOneDayBeforeFirst` methods | ||
## v2.2.0 | ||
@@ -2,0 +10,0 @@ |
@@ -1,1 +0,1 @@ | ||
var t="single",e="range",n="single",r="double",a="custom";function i(t,e){return[e]}function o(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function s(t,e){return 2===t.length?[e]:function(t,e){if(0===t.length)return[e];var n=t[0],r=t[1];return 1===t.length?o(n,e):n.formatted===e.formatted?[n,e]:r.formatted===e.formatted?[r,e]:o(Math.abs(n.ms-e.ms)<Math.abs(r.ms-e.ms)?r:n,e)}(t,e)}function u(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function h(t,e){var n=e[0],r=e[1];return m(t,n)&&d(t,r)}function c(t,e){return l(e,t)}function f(t,e){return l(t,e)}function l(t,e){return u(t).valueOf()-u(e).valueOf()==864e5}function d(t,e){return t<e}function m(t,e){return t>e}function D(t,e){return t===e}function v(t,e){return t===e}function g(t,e){return new Date(t,e)}function y(t,e){var n=e.disabledDates;void 0===n&&(n=[]);var r=e.maxDate;void 0===r&&(r="");var a=e.minDate;return void 0===a&&(a=""),a&&d(t,a)||r&&m(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function M(t){return t<10?"0"+t:t}function p(t,e,n,r){void 0===r&&(r={});var a=r.isOtherMonthDay;void 0===a&&(a=!1);var i=new Date(t,e,n);this.ms=i.valueOf(),this.dayOfWeek=(i.getDay()+6)%7,this.year=i.getFullYear(),this.month=i.getMonth(),this.day=i.getDate(),this.actualMonthNumber=this.month+1,this.formatted=[this.year,this.actualMonthNumber,this.day].map(M).join("-"),this.isWeekend=function(t){var e=t.getDay();return 0===e||6===e}(i),this.isToday=function(t){var e=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(i),this.isOtherMonthDay=a}p.fromString=function(t){var e=t.split("-");return new p(e[0],e[1]-1,e[2])},p.prototype.isBetween=function(t){var e=t.currentHoveredDate,n=t.captureThirdDate,r=t.selectedDates;if(0===r.length)return!1;var a=this.formatted,i=r[0],o=r[1],s=e&&e.formatted,u=i&&i.formatted,c=o&&o.formatted;return!o&&s?h(a,[u,s])||h(a,[s,u]):n&&s?h(a,[u,s])||h(a,[s,c]):h(a,[u,c])},p.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return D(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var w={};function O(t){for(var e,n=t.numberOfMonths,r=t.viewMode,i=t.month,o=t.year,s=[],u=i+(r===a?n:w[r]),h=i,c=o,f=i;h<u;){var l=g(c,f),d=l.getFullYear(),m=l.getMonth(),D=S(d,m),y=function(t,e,n){var r=[],a=n-1,i=31;for(;r.length!==t;){var o=new p(e,a,i,{isOtherMonthDay:!0});v(n,o.month)||r.unshift(o),i--}return r}((e=D[0]).dayOfWeek,e.year,e.month),M=Y(D[D.length-1]);s.push({dates:y.concat(D,M),month:m,year:d}),c=d,f=m+1,h++}return s}function S(t,e){for(var n=[],r=1;r<=31;r++)n.push(new p(t,e,r));return n.filter((function(t){return v(e,t.month)}))}function Y(t){return function(t,e,n){for(var r=[],a=n+1,i=1;i<=t;i++){var o=new p(e,a,i,{isOtherMonthDay:!0});r.push(o)}return r}(6-t.dayOfWeek,t.year,t.month)}function F(t){var e=t.currentYear,n=t.currentMonth,r=t.minDate,a=t.maxDate;return 1===t.step?function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],o=r[2],s=new Date(a,i-1,o),u=s.getFullYear(),h=s.getMonth(),c=n+1;return D(u,e)&&d(h,c)}(a,e,n):function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],o=r[2],s=new Date(a,i-1,o),u=s.getFullYear(),h=s.getMonth(),c=n-1;return D(u,e)&&m(h,c)}(r,e,n)}w[n]=1,w[r]=2;var b={};b[n]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},b[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth(),r=g(t.getFullYear(),t.getMonth()+1),a=r.getFullYear(),i=r.getMonth();return[{year:e,month:n},{year:a,month:i}]},b[a]=function(t){for(var e=new Date,n=[],r=e.getMonth()+t,a=e.getMonth();a<r;a++){var i=g(e.getFullYear(),a);n.push({year:i.getFullYear(),month:i.getMonth()})}return n};var x={};x[n]={prevPage:function(){},nextPage:function(){}},x[r]={prevPage:function(){},nextPage:function(){}};var N={};function B(t){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t=navigator.language),N.hasOwnProperty(t)||(N[t]=function(t){var e=new Date,n=e.getFullYear(),r=e.getMonth(),a=e.getDay(),i=[].concat(Array(12)).map((function(e,r){var a=new Date(n,r);return{short:a.toLocaleString(t,{month:"short"}),full:a.toLocaleString(t,{month:"long"})}})),o=e.getDate()-a+(0===a?-6:1),s=[].concat(Array(7)).map((function(e,a){var i=new Date(n,r,o+a);return{short:i.toLocaleString(t,{weekday:"short"}),full:i.toLocaleString(t,{weekday:"long"})}}));return{months:i,days:s}}(t)),N[t]}var P={name:"RenderlessCalendar",props:{viewMode:{type:String,validator:function(t){return-1!==[n,r,a].indexOf(t)},default:n},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(n){return-1!==[t,e].indexOf(n)},default:t},locale:{type:[String,Object],default:""},minDate:{type:String,default:""},maxDate:{type:String,default:""},preventOutOfRange:{default:!0,type:Boolean},captureThirdDate:{type:Boolean,default:!1},dateSelectStrategy:{type:Function,default:null},defaultSelectedDates:{type:Array,default:function(){return[]}},captureHover:{type:Boolean,default:!0},disabledDates:{type:Array,default:function(){return[]}},markedDates:{type:Array,default:function(){return[]}}},data:function(){return{today:new Date,calendar:null,selectedDates:[],currentMonth:null,currentYear:null,currentHoveredDate:null,viewState:[]}},created:function(){var t,e;this.selectedDates=this.defaultSelectedDates.map(p.fromString),this.currentMonth=this.today.getMonth(),this.currentYear=this.today.getFullYear(),this.viewState=(t=this.viewMode,e=this.customNumberOfMonths,b[t](e)),this.viewNavigator=function(t){return x[t]}(this.viewMode),this.calendar=Object.freeze(O({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear}))},computed:{localeStrings:function(){return"string"==typeof this.locale?B(this.locale):this.locale},weekDayNames:function(){return this.localeStrings.days},monthNames:function(){return this.localeStrings.months.map((function(t,e){return{short:t.short,full:t.full,id:e}}))},monthsList:function(){return function(t){for(var e=t.currentMonth,n=t.currentYear,r=t.monthNames,a=t.viewState,i=e,o=[],s=i;s<=i+12;s++){var u=new Date(n,s),h=u.getFullYear(),c=u.getMonth(),f=r[c];o.push({isActive:a.some(l(h,c)),id:h+"-"+c,short:f.short,full:f.full,month:c,year:h})}return o;function l(t,e){return function(n){return n.year===t&&n.month===e}}}({currentMonth:this.currentMonth,currentYear:this.currentYear,monthNames:this.monthNames,viewState:this.viewState})},canGoToPrevMonth:function(){var t=this.viewState[0],e=t.month,n=t.year;return!F({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:-1})},canGoToNextMonth:function(){var t=this.viewState[this.viewState.length-1],e=t.month,n=t.year;return!F({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:1})}},methods:{onDateSelect:function(t){y(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})||this.setDates(this.dateChangeHangler(this.selectedDates,t))},onDateMouseOver:function(t){this.currentHoveredDate=t},onDateMouseOut:function(){this.currentHoveredDate=null},setDates:function(t){this.selectedDates=t,this.$emit("onDateChange",t)},resetDates:function(t){this.setDates(function(t,e){return Number.isNaN(e)?[]:t.filter((function(t,n){return n!==e}))}(this.selectedDates,t))},prevPage:function(){var t=this.viewState,e=this.viewMode,a=this.customNumberOfMonths,i=t[0],o=i.year,s=i.month,u=[];if(!this.shouldPreventMonthChange(o,s,-1)){var h=g(o,s-1),c=O({numberOfMonths:a,year:h.getFullYear(),month:h.getMonth(),viewMode:e});if(e===n)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===r){var f=t[0];u=[{year:h.getFullYear(),month:h.getMonth()},f]}this.calendar=c,this.viewState=u}},nextPage:function(){var t=this.viewMode,e=this.viewState,a=this.customNumberOfMonths,i=[],o=t===n?e[0]:e[1],s=o.year,u=o.month;if(!this.shouldPreventMonthChange(s,u,1)){if(t===r){var h=e[0];s=h.year,u=h.month}var c=g(s,u+1),f=O({numberOfMonths:a,year:c.getFullYear(),month:c.getMonth(),viewMode:t});if(t===n)i=[{year:c.getFullYear(),month:c.getMonth()}];else if(t===r){var l=e[1],d=g(s,u+2);i=[l,{year:d.getFullYear(),month:d.getMonth()}]}this.calendar=f,this.viewState=i}},shouldPreventMonthChange:function(t,e,n){return this.preventOutOfRange&&F({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,a=t.year,i=this.viewMode,o=this.customNumberOfMonths,s=[];if(i===n&&(s=[{month:e,year:a}]),i===r){var u=g(a,e+1);s=[{month:e,year:a},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=O({numberOfMonths:o,viewMode:i,month:e,year:a}),this.viewState=s},isBetween:function(t){return this.captureHover&&t.isBetween({currentHoveredDate:this.currentHoveredDate,captureThirdDate:this.captureThirdDate,selectedDates:this.selectedDates})},isSelected:function(t){return t.isSelected(this.selectedDates)},isDisabled:function(t){return y(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})},isOneDayAfter:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return f(e,t.formatted)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(e,t.formatted)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&c(e.formatted,t.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&f(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&c(e.formatted,t.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&f(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&D(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&D(t.formatted,e.formatted)},isMarked:function(t){return function(t,e){return-1!==e.indexOf(t)}(t.formatted,this.markedDates)},getModifiers:function(t){return{isBetween:this.isBetween(t),isSelected:this.isSelected(t),isDisabled:this.isDisabled(t),isOneDayAfter:this.isOneDayAfter(t),isOneDayBefore:this.isOneDayBefore(t),isOneDayBeforeFirst:this.isOneDayBeforeFirst(t),isOneDayAfterFirst:this.isOneDayAfterFirst(t),isOneDayBeforeLast:this.isOneDayBeforeLast(t),isOneDayAfterLast:this.isOneDayAfterLast(t),isFirst:this.isFirst(t),isLast:this.isLast(t),isMarked:this.isMarked(t)}}},watch:{mode:{handler:function(n){this.dateChangeHangler=this.dateSelectStrategy||function(n){switch(n){case t:return i;case e:return s;default:throw new Error("unkown mode: "+n)}}(n)},immediate:!0},defaultSelectedDates:function(t){this.selectedDates=t.map(p.fromString)}},render:function(){return this.$scopedSlots.default({weekDayNames:this.weekDayNames,monthNames:this.monthNames,monthsList:this.monthsList,calendar:this.calendar,selectedDates:this.selectedDates,currentMonth:this.currentMonth,currentYear:this.currentYear,canGoToPrevMonth:this.canGoToPrevMonth,canGoToNextMonth:this.canGoToNextMonth,prevPage:this.prevPage,nextPage:this.nextPage,resetDates:this.resetDates,setMonth:this.setMonth,onDateMouseOut:this.onDateMouseOut,onDateMouseOver:this.onDateMouseOver,onDateSelect:this.onDateSelect,getModifiers:this.getModifiers})}};export{P as RenderlessCalendar}; | ||
var t="single",e="range",n="single",r="double",a="custom";function i(t,e){return[e]}function s(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function o(t,e){return 2===t.length?[e]:function(t,e){if(0===t.length)return[e];var n=t[0],r=t[1];return 1===t.length?s(n,e):n.formatted===e.formatted?[n,e]:r.formatted===e.formatted?[r,e]:s(Math.abs(n.ms-e.ms)<Math.abs(r.ms-e.ms)?r:n,e)}(t,e)}function u(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function h(t,e){var n=e[0],r=e[1];return m(t,n)&&d(t,r)}function f(t,e){return l(e,t)}function c(t,e){return l(t,e)}function l(t,e){return u(t).valueOf()-u(e).valueOf()==864e5}function d(t,e){return t<e}function m(t,e){return t>e}function D(t,e){return t===e}function v(t,e){return t===e}function y(t,e){return new Date(t,e)}function g(t,e){var n=e.disabledDates;void 0===n&&(n=[]);var r=e.maxDate;void 0===r&&(r="");var a=e.minDate;return void 0===a&&(a=""),a&&d(t,a)||r&&m(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function M(t){return t<10?"0"+t:t}function O(t,e,n,r){void 0===r&&(r={isOtherMonthDay:!1,firstDayOfWeek:1});var a=r.isOtherMonthDay,i=r.firstDayOfWeek,s=new Date(t,e,n);this.ms=s.valueOf(),this.dayOfWeek=(s.getDay()-i+7)%7,this.year=s.getFullYear(),this.month=s.getMonth(),this.day=s.getDate(),this.actualMonthNumber=this.month+1,this.formatted=[this.year,this.actualMonthNumber,this.day].map(M).join("-"),this.isWeekend=function(t){var e=t.getDay();return 0===e||6===e}(s),this.isToday=function(t){var e=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(s),this.isOtherMonthDay=a}O.fromString=function(t,e){void 0===e&&(e={firstDayOfWeek:1});var n=e.firstDayOfWeek,r=t.split("-");return new O(r[0],r[1]-1,r[2],{firstDayOfWeek:n})},O.prototype.isBetween=function(t){var e=t.currentHoveredDate,n=t.captureThirdDate,r=t.selectedDates;if(0===r.length)return!1;var a=this.formatted,i=r[0],s=r[1],o=e&&e.formatted,u=i&&i.formatted,f=s&&s.formatted;return!s&&o?h(a,[u,o])||h(a,[o,u]):n&&o?h(a,[u,o])||h(a,[o,f]):h(a,[u,f])},O.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return D(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var p={};function w(t){for(var e=t.numberOfMonths,n=t.viewMode,r=t.month,i=t.year,s=t.firstDayOfWeek,o=[],u=r+(n===a?e:p[n]),h=r,f=i,c=r;h<u;){var l=y(f,c),d=l.getFullYear(),m=l.getMonth(),D=k(d,m,s),v=S(D[0],s),g=b(D[D.length-1],s);o.push({dates:v.concat(D,g),month:m,year:d}),f=d,c=m+1,h++}return o}function S(t,e){return void 0===e&&(e=1),function(t,e,n,r){void 0===r&&(r=1);var a=[],i=n-1,s=31;for(;a.length<t;){var o=new O(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});v(n,o.month)||a.unshift(o),s--}return a}(t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function k(t,e,n){void 0===n&&(n=1);for(var r=[],a=1;a<=31;a++)r.push(new O(t,e,a,{firstDayOfWeek:n}));return r.filter((function(t){return v(e,t.month)}))}function b(t,e){return void 0===e&&(e=1),function(t,e,n,r){void 0===r&&(r=1);for(var a=[],i=n+1,s=1;s<=t;s++){var o=new O(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});a.push(o)}return a}(6-t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function Y(t){var e=t.currentYear,n=t.currentMonth,r=t.minDate,a=t.maxDate;return 1===t.step?function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n+1;return D(u,e)&&d(h,f)}(a,e,n):function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n-1;return D(u,e)&&m(h,f)}(r,e,n)}p[n]=1,p[r]=2;var F={};F[n]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},F[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth(),r=y(t.getFullYear(),t.getMonth()+1),a=r.getFullYear(),i=r.getMonth();return[{year:e,month:n},{year:a,month:i}]},F[a]=function(t){for(var e=new Date,n=[],r=e.getMonth()+t,a=e.getMonth();a<r;a++){var i=y(e.getFullYear(),a);n.push({year:i.getFullYear(),month:i.getMonth()})}return n};var N={};N[n]={prevPage:function(){},nextPage:function(){}},N[r]={prevPage:function(){},nextPage:function(){}};var W={};function x(t,e){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t=navigator.language),W.hasOwnProperty(t)||(W[t]=function(t,e){void 0===e&&(e=1);var n=e%7,r=new Date,a=r.getFullYear(),i=r.getMonth(),s=r.getDay(),o=Array(12).fill().map((function(e,n){var r=new Date(a,n);return{short:r.toLocaleString(t,{month:"short"}),full:r.toLocaleString(t,{month:"long"})}})),u=r.getDate()-s+n,h=Array(7).fill().map((function(e,n){var r=new Date(a,i,u+n);return{short:r.toLocaleString(t,{weekday:"short"}),full:r.toLocaleString(t,{weekday:"long"})}}));return{months:o,days:h}}(t,e)),W[t]}var B={name:"RenderlessCalendar",props:{viewMode:{type:String,validator:function(t){return-1!==[n,r,a].indexOf(t)},default:n},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(n){return-1!==[t,e].indexOf(n)},default:t},locale:{type:[String,Object],default:""},minDate:{type:String,default:""},maxDate:{type:String,default:""},preventOutOfRange:{default:!0,type:Boolean},captureThirdDate:{type:Boolean,default:!1},dateSelectStrategy:{type:Function,default:null},defaultSelectedDates:{type:Array,default:function(){return[]}},captureHover:{type:Boolean,default:!0},disabledDates:{type:Array,default:function(){return[]}},markedDates:{type:Array,default:function(){return[]}},firstDayOfWeek:{type:Number,default:1}},data:function(){return{today:new Date,calendar:null,selectedDates:[],currentMonth:null,currentYear:null,currentHoveredDate:null,viewState:[]}},created:function(){var t,e;this.selectedDates=this.defaultSelectedDates.map(O.fromString),this.currentMonth=this.today.getMonth(),this.currentYear=this.today.getFullYear(),this.viewState=(t=this.viewMode,e=this.customNumberOfMonths,F[t](e)),this.viewNavigator=function(t){return N[t]}(this.viewMode),this.calendar=Object.freeze(w({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear,firstDayOfWeek:this.firstDayOfWeek}))},computed:{localeStrings:function(){return"string"==typeof this.locale?x(this.locale,this.firstDayOfWeek):this.locale},weekDayNames:function(){return this.localeStrings.days},monthNames:function(){return this.localeStrings.months.map((function(t,e){return{short:t.short,full:t.full,id:e}}))},monthsList:function(){return function(t){for(var e=t.currentMonth,n=t.currentYear,r=t.monthNames,a=t.viewState,i=e,s=[],o=i;o<=i+12;o++){var u=new Date(n,o),h=u.getFullYear(),f=u.getMonth(),c=r[f];s.push({isActive:a.some(l(h,f)),id:h+"-"+f,short:c.short,full:c.full,month:f,year:h})}return s;function l(t,e){return function(n){return n.year===t&&n.month===e}}}({currentMonth:this.currentMonth,currentYear:this.currentYear,monthNames:this.monthNames,viewState:this.viewState})},canGoToPrevMonth:function(){var t=this.viewState[0],e=t.month,n=t.year;return!Y({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:-1})},canGoToNextMonth:function(){var t=this.viewState[this.viewState.length-1],e=t.month,n=t.year;return!Y({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:1})}},methods:{onDateSelect:function(t){g(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})||this.setDates(this.dateChangeHangler(this.selectedDates,t))},onDateMouseOver:function(t){this.currentHoveredDate=t},onDateMouseOut:function(){this.currentHoveredDate=null},setDates:function(t){this.selectedDates=t,this.$emit("onDateChange",t)},resetDates:function(t){this.setDates(function(t,e){return Number.isNaN(e)?[]:t.filter((function(t,n){return n!==e}))}(this.selectedDates,t))},prevPage:function(){var t=this.viewState,e=this.viewMode,a=this.customNumberOfMonths,i=t[0],s=i.year,o=i.month,u=[];if(!this.shouldPreventMonthChange(s,o,-1)){var h=y(s,o-1),f=w({numberOfMonths:a,year:h.getFullYear(),month:h.getMonth(),viewMode:e,firstDayOfWeek:this.firstDayOfWeek});if(e===n)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===r){var c=t[0];u=[{year:h.getFullYear(),month:h.getMonth()},c]}this.calendar=f,this.viewState=u}},nextPage:function(){var t=this.viewMode,e=this.viewState,a=this.customNumberOfMonths,i=[],s=t===n?e[0]:e[1],o=s.year,u=s.month;if(!this.shouldPreventMonthChange(o,u,1)){if(t===r){var h=e[0];o=h.year,u=h.month}var f=y(o,u+1),c=w({numberOfMonths:a,year:f.getFullYear(),month:f.getMonth(),viewMode:t,firstDayOfWeek:this.firstDayOfWeek});if(t===n)i=[{year:f.getFullYear(),month:f.getMonth()}];else if(t===r){var l=e[1],d=y(o,u+2);i=[l,{year:d.getFullYear(),month:d.getMonth()}]}this.calendar=c,this.viewState=i}},shouldPreventMonthChange:function(t,e,n){return this.preventOutOfRange&&Y({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,a=t.year,i=this.viewMode,s=this.customNumberOfMonths,o=[];if(i===n&&(o=[{month:e,year:a}]),i===r){var u=y(a,e+1);o=[{month:e,year:a},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=w({numberOfMonths:s,viewMode:i,month:e,year:a,firstDayOfWeek:this.firstDayOfWeek}),this.viewState=o},isBetween:function(t){return this.captureHover&&t.isBetween({currentHoveredDate:this.currentHoveredDate,captureThirdDate:this.captureThirdDate,selectedDates:this.selectedDates})},isSelected:function(t){return t.isSelected(this.selectedDates)},isDisabled:function(t){return g(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})},isOneDayAfter:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(t.formatted,e)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return f(t.formatted,e)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&f(t.formatted,e.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&c(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&f(t.formatted,e.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&c(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&D(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&D(t.formatted,e.formatted)},isMarked:function(t){return function(t,e){return-1!==e.indexOf(t)}(t.formatted,this.markedDates)},getModifiers:function(t){return{isBetween:this.isBetween(t),isSelected:this.isSelected(t),isDisabled:this.isDisabled(t),isOneDayAfter:this.isOneDayAfter(t),isOneDayBefore:this.isOneDayBefore(t),isOneDayBeforeFirst:this.isOneDayBeforeFirst(t),isOneDayAfterFirst:this.isOneDayAfterFirst(t),isOneDayBeforeLast:this.isOneDayBeforeLast(t),isOneDayAfterLast:this.isOneDayAfterLast(t),isFirst:this.isFirst(t),isLast:this.isLast(t),isMarked:this.isMarked(t)}}},watch:{mode:{handler:function(n){this.dateChangeHangler=this.dateSelectStrategy||function(n){switch(n){case t:return i;case e:return o;default:throw new Error("unkown mode: "+n)}}(n)},immediate:!0},firstDayOfWeek:function(t){var e=this.viewState[0],n=e.month,r=e.year;this.calendar=Object.freeze(w({numberOfMonths:this.customNumberOfMonths,viewMode:this.viewMode,firstDayOfWeek:t,month:n,year:r}))},defaultSelectedDates:function(t){this.selectedDates=t.map(O.fromString)}},render:function(){return this.$scopedSlots.default({weekDayNames:this.weekDayNames,monthNames:this.monthNames,monthsList:this.monthsList,calendar:this.calendar,selectedDates:this.selectedDates,currentMonth:this.currentMonth,currentYear:this.currentYear,canGoToPrevMonth:this.canGoToPrevMonth,canGoToNextMonth:this.canGoToNextMonth,prevPage:this.prevPage,nextPage:this.nextPage,resetDates:this.resetDates,setMonth:this.setMonth,onDateMouseOut:this.onDateMouseOut,onDateMouseOver:this.onDateMouseOver,onDateSelect:this.onDateSelect,getModifiers:this.getModifiers})}};export{B as RenderlessCalendar}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="single",e="range",n="single",r="double",a="custom";function i(t,e){return[e]}function o(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function s(t,e){return 2===t.length?[e]:function(t,e){if(0===t.length)return[e];var n=t[0],r=t[1];return 1===t.length?o(n,e):n.formatted===e.formatted?[n,e]:r.formatted===e.formatted?[r,e]:o(Math.abs(n.ms-e.ms)<Math.abs(r.ms-e.ms)?r:n,e)}(t,e)}function u(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function h(t,e){var n=e[0],r=e[1];return m(t,n)&&d(t,r)}function c(t,e){return l(e,t)}function f(t,e){return l(t,e)}function l(t,e){return u(t).valueOf()-u(e).valueOf()==864e5}function d(t,e){return t<e}function m(t,e){return t>e}function D(t,e){return t===e}function v(t,e){return t===e}function g(t,e){return new Date(t,e)}function y(t,e){var n=e.disabledDates;void 0===n&&(n=[]);var r=e.maxDate;void 0===r&&(r="");var a=e.minDate;return void 0===a&&(a=""),a&&d(t,a)||r&&m(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function M(t){return t<10?"0"+t:t}function p(t,e,n,r){void 0===r&&(r={});var a=r.isOtherMonthDay;void 0===a&&(a=!1);var i=new Date(t,e,n);this.ms=i.valueOf(),this.dayOfWeek=(i.getDay()+6)%7,this.year=i.getFullYear(),this.month=i.getMonth(),this.day=i.getDate(),this.actualMonthNumber=this.month+1,this.formatted=[this.year,this.actualMonthNumber,this.day].map(M).join("-"),this.isWeekend=function(t){var e=t.getDay();return 0===e||6===e}(i),this.isToday=function(t){var e=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(i),this.isOtherMonthDay=a}p.fromString=function(t){var e=t.split("-");return new p(e[0],e[1]-1,e[2])},p.prototype.isBetween=function(t){var e=t.currentHoveredDate,n=t.captureThirdDate,r=t.selectedDates;if(0===r.length)return!1;var a=this.formatted,i=r[0],o=r[1],s=e&&e.formatted,u=i&&i.formatted,c=o&&o.formatted;return!o&&s?h(a,[u,s])||h(a,[s,u]):n&&s?h(a,[u,s])||h(a,[s,c]):h(a,[u,c])},p.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return D(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var w={};function O(t){for(var e,n=t.numberOfMonths,r=t.viewMode,i=t.month,o=t.year,s=[],u=i+(r===a?n:w[r]),h=i,c=o,f=i;h<u;){var l=g(c,f),d=l.getFullYear(),m=l.getMonth(),D=S(d,m),y=function(t,e,n){var r=[],a=n-1,i=31;for(;r.length!==t;){var o=new p(e,a,i,{isOtherMonthDay:!0});v(n,o.month)||r.unshift(o),i--}return r}((e=D[0]).dayOfWeek,e.year,e.month),M=Y(D[D.length-1]);s.push({dates:y.concat(D,M),month:m,year:d}),c=d,f=m+1,h++}return s}function S(t,e){for(var n=[],r=1;r<=31;r++)n.push(new p(t,e,r));return n.filter((function(t){return v(e,t.month)}))}function Y(t){return function(t,e,n){for(var r=[],a=n+1,i=1;i<=t;i++){var o=new p(e,a,i,{isOtherMonthDay:!0});r.push(o)}return r}(6-t.dayOfWeek,t.year,t.month)}function F(t){var e=t.currentYear,n=t.currentMonth,r=t.minDate,a=t.maxDate;return 1===t.step?function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],o=r[2],s=new Date(a,i-1,o),u=s.getFullYear(),h=s.getMonth(),c=n+1;return D(u,e)&&d(h,c)}(a,e,n):function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],o=r[2],s=new Date(a,i-1,o),u=s.getFullYear(),h=s.getMonth(),c=n-1;return D(u,e)&&m(h,c)}(r,e,n)}w[n]=1,w[r]=2;var b={};b[n]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},b[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth(),r=g(t.getFullYear(),t.getMonth()+1),a=r.getFullYear(),i=r.getMonth();return[{year:e,month:n},{year:a,month:i}]},b[a]=function(t){for(var e=new Date,n=[],r=e.getMonth()+t,a=e.getMonth();a<r;a++){var i=g(e.getFullYear(),a);n.push({year:i.getFullYear(),month:i.getMonth()})}return n};var x={};x[n]={prevPage:function(){},nextPage:function(){}},x[r]={prevPage:function(){},nextPage:function(){}};var N={};function P(t){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t=navigator.language),N.hasOwnProperty(t)||(N[t]=function(t){var e=new Date,n=e.getFullYear(),r=e.getMonth(),a=e.getDay(),i=[].concat(Array(12)).map((function(e,r){var a=new Date(n,r);return{short:a.toLocaleString(t,{month:"short"}),full:a.toLocaleString(t,{month:"long"})}})),o=e.getDate()-a+(0===a?-6:1),s=[].concat(Array(7)).map((function(e,a){var i=new Date(n,r,o+a);return{short:i.toLocaleString(t,{weekday:"short"}),full:i.toLocaleString(t,{weekday:"long"})}}));return{months:i,days:s}}(t)),N[t]}var B={name:"RenderlessCalendar",props:{viewMode:{type:String,validator:function(t){return-1!==[n,r,a].indexOf(t)},default:n},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(n){return-1!==[t,e].indexOf(n)},default:t},locale:{type:[String,Object],default:""},minDate:{type:String,default:""},maxDate:{type:String,default:""},preventOutOfRange:{default:!0,type:Boolean},captureThirdDate:{type:Boolean,default:!1},dateSelectStrategy:{type:Function,default:null},defaultSelectedDates:{type:Array,default:function(){return[]}},captureHover:{type:Boolean,default:!0},disabledDates:{type:Array,default:function(){return[]}},markedDates:{type:Array,default:function(){return[]}}},data:function(){return{today:new Date,calendar:null,selectedDates:[],currentMonth:null,currentYear:null,currentHoveredDate:null,viewState:[]}},created:function(){var t,e;this.selectedDates=this.defaultSelectedDates.map(p.fromString),this.currentMonth=this.today.getMonth(),this.currentYear=this.today.getFullYear(),this.viewState=(t=this.viewMode,e=this.customNumberOfMonths,b[t](e)),this.viewNavigator=function(t){return x[t]}(this.viewMode),this.calendar=Object.freeze(O({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear}))},computed:{localeStrings:function(){return"string"==typeof this.locale?P(this.locale):this.locale},weekDayNames:function(){return this.localeStrings.days},monthNames:function(){return this.localeStrings.months.map((function(t,e){return{short:t.short,full:t.full,id:e}}))},monthsList:function(){return function(t){for(var e=t.currentMonth,n=t.currentYear,r=t.monthNames,a=t.viewState,i=e,o=[],s=i;s<=i+12;s++){var u=new Date(n,s),h=u.getFullYear(),c=u.getMonth(),f=r[c];o.push({isActive:a.some(l(h,c)),id:h+"-"+c,short:f.short,full:f.full,month:c,year:h})}return o;function l(t,e){return function(n){return n.year===t&&n.month===e}}}({currentMonth:this.currentMonth,currentYear:this.currentYear,monthNames:this.monthNames,viewState:this.viewState})},canGoToPrevMonth:function(){var t=this.viewState[0],e=t.month,n=t.year;return!F({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:-1})},canGoToNextMonth:function(){var t=this.viewState[this.viewState.length-1],e=t.month,n=t.year;return!F({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:1})}},methods:{onDateSelect:function(t){y(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})||this.setDates(this.dateChangeHangler(this.selectedDates,t))},onDateMouseOver:function(t){this.currentHoveredDate=t},onDateMouseOut:function(){this.currentHoveredDate=null},setDates:function(t){this.selectedDates=t,this.$emit("onDateChange",t)},resetDates:function(t){this.setDates(function(t,e){return Number.isNaN(e)?[]:t.filter((function(t,n){return n!==e}))}(this.selectedDates,t))},prevPage:function(){var t=this.viewState,e=this.viewMode,a=this.customNumberOfMonths,i=t[0],o=i.year,s=i.month,u=[];if(!this.shouldPreventMonthChange(o,s,-1)){var h=g(o,s-1),c=O({numberOfMonths:a,year:h.getFullYear(),month:h.getMonth(),viewMode:e});if(e===n)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===r){var f=t[0];u=[{year:h.getFullYear(),month:h.getMonth()},f]}this.calendar=c,this.viewState=u}},nextPage:function(){var t=this.viewMode,e=this.viewState,a=this.customNumberOfMonths,i=[],o=t===n?e[0]:e[1],s=o.year,u=o.month;if(!this.shouldPreventMonthChange(s,u,1)){if(t===r){var h=e[0];s=h.year,u=h.month}var c=g(s,u+1),f=O({numberOfMonths:a,year:c.getFullYear(),month:c.getMonth(),viewMode:t});if(t===n)i=[{year:c.getFullYear(),month:c.getMonth()}];else if(t===r){var l=e[1],d=g(s,u+2);i=[l,{year:d.getFullYear(),month:d.getMonth()}]}this.calendar=f,this.viewState=i}},shouldPreventMonthChange:function(t,e,n){return this.preventOutOfRange&&F({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,a=t.year,i=this.viewMode,o=this.customNumberOfMonths,s=[];if(i===n&&(s=[{month:e,year:a}]),i===r){var u=g(a,e+1);s=[{month:e,year:a},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=O({numberOfMonths:o,viewMode:i,month:e,year:a}),this.viewState=s},isBetween:function(t){return this.captureHover&&t.isBetween({currentHoveredDate:this.currentHoveredDate,captureThirdDate:this.captureThirdDate,selectedDates:this.selectedDates})},isSelected:function(t){return t.isSelected(this.selectedDates)},isDisabled:function(t){return y(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})},isOneDayAfter:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return f(e,t.formatted)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(e,t.formatted)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&c(e.formatted,t.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&f(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&c(e.formatted,t.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&f(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&D(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&D(t.formatted,e.formatted)},isMarked:function(t){return function(t,e){return-1!==e.indexOf(t)}(t.formatted,this.markedDates)},getModifiers:function(t){return{isBetween:this.isBetween(t),isSelected:this.isSelected(t),isDisabled:this.isDisabled(t),isOneDayAfter:this.isOneDayAfter(t),isOneDayBefore:this.isOneDayBefore(t),isOneDayBeforeFirst:this.isOneDayBeforeFirst(t),isOneDayAfterFirst:this.isOneDayAfterFirst(t),isOneDayBeforeLast:this.isOneDayBeforeLast(t),isOneDayAfterLast:this.isOneDayAfterLast(t),isFirst:this.isFirst(t),isLast:this.isLast(t),isMarked:this.isMarked(t)}}},watch:{mode:{handler:function(n){this.dateChangeHangler=this.dateSelectStrategy||function(n){switch(n){case t:return i;case e:return s;default:throw new Error("unkown mode: "+n)}}(n)},immediate:!0},defaultSelectedDates:function(t){this.selectedDates=t.map(p.fromString)}},render:function(){return this.$scopedSlots.default({weekDayNames:this.weekDayNames,monthNames:this.monthNames,monthsList:this.monthsList,calendar:this.calendar,selectedDates:this.selectedDates,currentMonth:this.currentMonth,currentYear:this.currentYear,canGoToPrevMonth:this.canGoToPrevMonth,canGoToNextMonth:this.canGoToNextMonth,prevPage:this.prevPage,nextPage:this.nextPage,resetDates:this.resetDates,setMonth:this.setMonth,onDateMouseOut:this.onDateMouseOut,onDateMouseOver:this.onDateMouseOver,onDateSelect:this.onDateSelect,getModifiers:this.getModifiers})}};exports.RenderlessCalendar=B; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t="single",e="range",n="single",r="double",a="custom";function i(t,e){return[e]}function s(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function o(t,e){return 2===t.length?[e]:function(t,e){if(0===t.length)return[e];var n=t[0],r=t[1];return 1===t.length?s(n,e):n.formatted===e.formatted?[n,e]:r.formatted===e.formatted?[r,e]:s(Math.abs(n.ms-e.ms)<Math.abs(r.ms-e.ms)?r:n,e)}(t,e)}function u(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function h(t,e){var n=e[0],r=e[1];return m(t,n)&&d(t,r)}function f(t,e){return l(e,t)}function c(t,e){return l(t,e)}function l(t,e){return u(t).valueOf()-u(e).valueOf()==864e5}function d(t,e){return t<e}function m(t,e){return t>e}function D(t,e){return t===e}function v(t,e){return t===e}function y(t,e){return new Date(t,e)}function g(t,e){var n=e.disabledDates;void 0===n&&(n=[]);var r=e.maxDate;void 0===r&&(r="");var a=e.minDate;return void 0===a&&(a=""),a&&d(t,a)||r&&m(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function M(t){return t<10?"0"+t:t}function O(t,e,n,r){void 0===r&&(r={isOtherMonthDay:!1,firstDayOfWeek:1});var a=r.isOtherMonthDay,i=r.firstDayOfWeek,s=new Date(t,e,n);this.ms=s.valueOf(),this.dayOfWeek=(s.getDay()-i+7)%7,this.year=s.getFullYear(),this.month=s.getMonth(),this.day=s.getDate(),this.actualMonthNumber=this.month+1,this.formatted=[this.year,this.actualMonthNumber,this.day].map(M).join("-"),this.isWeekend=function(t){var e=t.getDay();return 0===e||6===e}(s),this.isToday=function(t){var e=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(s),this.isOtherMonthDay=a}O.fromString=function(t,e){void 0===e&&(e={firstDayOfWeek:1});var n=e.firstDayOfWeek,r=t.split("-");return new O(r[0],r[1]-1,r[2],{firstDayOfWeek:n})},O.prototype.isBetween=function(t){var e=t.currentHoveredDate,n=t.captureThirdDate,r=t.selectedDates;if(0===r.length)return!1;var a=this.formatted,i=r[0],s=r[1],o=e&&e.formatted,u=i&&i.formatted,f=s&&s.formatted;return!s&&o?h(a,[u,o])||h(a,[o,u]):n&&o?h(a,[u,o])||h(a,[o,f]):h(a,[u,f])},O.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return D(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var p={};function w(t){for(var e=t.numberOfMonths,n=t.viewMode,r=t.month,i=t.year,s=t.firstDayOfWeek,o=[],u=r+(n===a?e:p[n]),h=r,f=i,c=r;h<u;){var l=y(f,c),d=l.getFullYear(),m=l.getMonth(),D=k(d,m,s),v=S(D[0],s),g=b(D[D.length-1],s);o.push({dates:v.concat(D,g),month:m,year:d}),f=d,c=m+1,h++}return o}function S(t,e){return void 0===e&&(e=1),function(t,e,n,r){void 0===r&&(r=1);var a=[],i=n-1,s=31;for(;a.length<t;){var o=new O(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});v(n,o.month)||a.unshift(o),s--}return a}(t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function k(t,e,n){void 0===n&&(n=1);for(var r=[],a=1;a<=31;a++)r.push(new O(t,e,a,{firstDayOfWeek:n}));return r.filter((function(t){return v(e,t.month)}))}function b(t,e){return void 0===e&&(e=1),function(t,e,n,r){void 0===r&&(r=1);for(var a=[],i=n+1,s=1;s<=t;s++){var o=new O(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});a.push(o)}return a}(6-t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function Y(t){var e=t.currentYear,n=t.currentMonth,r=t.minDate,a=t.maxDate;return 1===t.step?function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n+1;return D(u,e)&&d(h,f)}(a,e,n):function(t,e,n){var r=t.split("-"),a=r[0],i=r[1],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n-1;return D(u,e)&&m(h,f)}(r,e,n)}p[n]=1,p[r]=2;var F={};F[n]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},F[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth(),r=y(t.getFullYear(),t.getMonth()+1),a=r.getFullYear(),i=r.getMonth();return[{year:e,month:n},{year:a,month:i}]},F[a]=function(t){for(var e=new Date,n=[],r=e.getMonth()+t,a=e.getMonth();a<r;a++){var i=y(e.getFullYear(),a);n.push({year:i.getFullYear(),month:i.getMonth()})}return n};var x={};x[n]={prevPage:function(){},nextPage:function(){}},x[r]={prevPage:function(){},nextPage:function(){}};var N={};function W(t,e){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t=navigator.language),N.hasOwnProperty(t)||(N[t]=function(t,e){void 0===e&&(e=1);var n=e%7,r=new Date,a=r.getFullYear(),i=r.getMonth(),s=r.getDay(),o=Array(12).fill().map((function(e,n){var r=new Date(a,n);return{short:r.toLocaleString(t,{month:"short"}),full:r.toLocaleString(t,{month:"long"})}})),u=r.getDate()-s+n,h=Array(7).fill().map((function(e,n){var r=new Date(a,i,u+n);return{short:r.toLocaleString(t,{weekday:"short"}),full:r.toLocaleString(t,{weekday:"long"})}}));return{months:o,days:h}}(t,e)),N[t]}var P={name:"RenderlessCalendar",props:{viewMode:{type:String,validator:function(t){return-1!==[n,r,a].indexOf(t)},default:n},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(n){return-1!==[t,e].indexOf(n)},default:t},locale:{type:[String,Object],default:""},minDate:{type:String,default:""},maxDate:{type:String,default:""},preventOutOfRange:{default:!0,type:Boolean},captureThirdDate:{type:Boolean,default:!1},dateSelectStrategy:{type:Function,default:null},defaultSelectedDates:{type:Array,default:function(){return[]}},captureHover:{type:Boolean,default:!0},disabledDates:{type:Array,default:function(){return[]}},markedDates:{type:Array,default:function(){return[]}},firstDayOfWeek:{type:Number,default:1}},data:function(){return{today:new Date,calendar:null,selectedDates:[],currentMonth:null,currentYear:null,currentHoveredDate:null,viewState:[]}},created:function(){var t,e;this.selectedDates=this.defaultSelectedDates.map(O.fromString),this.currentMonth=this.today.getMonth(),this.currentYear=this.today.getFullYear(),this.viewState=(t=this.viewMode,e=this.customNumberOfMonths,F[t](e)),this.viewNavigator=function(t){return x[t]}(this.viewMode),this.calendar=Object.freeze(w({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear,firstDayOfWeek:this.firstDayOfWeek}))},computed:{localeStrings:function(){return"string"==typeof this.locale?W(this.locale,this.firstDayOfWeek):this.locale},weekDayNames:function(){return this.localeStrings.days},monthNames:function(){return this.localeStrings.months.map((function(t,e){return{short:t.short,full:t.full,id:e}}))},monthsList:function(){return function(t){for(var e=t.currentMonth,n=t.currentYear,r=t.monthNames,a=t.viewState,i=e,s=[],o=i;o<=i+12;o++){var u=new Date(n,o),h=u.getFullYear(),f=u.getMonth(),c=r[f];s.push({isActive:a.some(l(h,f)),id:h+"-"+f,short:c.short,full:c.full,month:f,year:h})}return s;function l(t,e){return function(n){return n.year===t&&n.month===e}}}({currentMonth:this.currentMonth,currentYear:this.currentYear,monthNames:this.monthNames,viewState:this.viewState})},canGoToPrevMonth:function(){var t=this.viewState[0],e=t.month,n=t.year;return!Y({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:-1})},canGoToNextMonth:function(){var t=this.viewState[this.viewState.length-1],e=t.month,n=t.year;return!Y({minDate:this.minDate,maxDate:this.maxDate,currentMonth:e,currentYear:n,step:1})}},methods:{onDateSelect:function(t){g(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})||this.setDates(this.dateChangeHangler(this.selectedDates,t))},onDateMouseOver:function(t){this.currentHoveredDate=t},onDateMouseOut:function(){this.currentHoveredDate=null},setDates:function(t){this.selectedDates=t,this.$emit("onDateChange",t)},resetDates:function(t){this.setDates(function(t,e){return Number.isNaN(e)?[]:t.filter((function(t,n){return n!==e}))}(this.selectedDates,t))},prevPage:function(){var t=this.viewState,e=this.viewMode,a=this.customNumberOfMonths,i=t[0],s=i.year,o=i.month,u=[];if(!this.shouldPreventMonthChange(s,o,-1)){var h=y(s,o-1),f=w({numberOfMonths:a,year:h.getFullYear(),month:h.getMonth(),viewMode:e,firstDayOfWeek:this.firstDayOfWeek});if(e===n)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===r){var c=t[0];u=[{year:h.getFullYear(),month:h.getMonth()},c]}this.calendar=f,this.viewState=u}},nextPage:function(){var t=this.viewMode,e=this.viewState,a=this.customNumberOfMonths,i=[],s=t===n?e[0]:e[1],o=s.year,u=s.month;if(!this.shouldPreventMonthChange(o,u,1)){if(t===r){var h=e[0];o=h.year,u=h.month}var f=y(o,u+1),c=w({numberOfMonths:a,year:f.getFullYear(),month:f.getMonth(),viewMode:t,firstDayOfWeek:this.firstDayOfWeek});if(t===n)i=[{year:f.getFullYear(),month:f.getMonth()}];else if(t===r){var l=e[1],d=y(o,u+2);i=[l,{year:d.getFullYear(),month:d.getMonth()}]}this.calendar=c,this.viewState=i}},shouldPreventMonthChange:function(t,e,n){return this.preventOutOfRange&&Y({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,a=t.year,i=this.viewMode,s=this.customNumberOfMonths,o=[];if(i===n&&(o=[{month:e,year:a}]),i===r){var u=y(a,e+1);o=[{month:e,year:a},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=w({numberOfMonths:s,viewMode:i,month:e,year:a,firstDayOfWeek:this.firstDayOfWeek}),this.viewState=o},isBetween:function(t){return this.captureHover&&t.isBetween({currentHoveredDate:this.currentHoveredDate,captureThirdDate:this.captureThirdDate,selectedDates:this.selectedDates})},isSelected:function(t){return t.isSelected(this.selectedDates)},isDisabled:function(t){return g(t.formatted,{disabledDates:this.disabledDates,maxDate:this.maxDate,minDate:this.minDate})},isOneDayAfter:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(t.formatted,e)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return f(t.formatted,e)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&f(t.formatted,e.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&c(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&f(t.formatted,e.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&c(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&D(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&D(t.formatted,e.formatted)},isMarked:function(t){return function(t,e){return-1!==e.indexOf(t)}(t.formatted,this.markedDates)},getModifiers:function(t){return{isBetween:this.isBetween(t),isSelected:this.isSelected(t),isDisabled:this.isDisabled(t),isOneDayAfter:this.isOneDayAfter(t),isOneDayBefore:this.isOneDayBefore(t),isOneDayBeforeFirst:this.isOneDayBeforeFirst(t),isOneDayAfterFirst:this.isOneDayAfterFirst(t),isOneDayBeforeLast:this.isOneDayBeforeLast(t),isOneDayAfterLast:this.isOneDayAfterLast(t),isFirst:this.isFirst(t),isLast:this.isLast(t),isMarked:this.isMarked(t)}}},watch:{mode:{handler:function(n){this.dateChangeHangler=this.dateSelectStrategy||function(n){switch(n){case t:return i;case e:return o;default:throw new Error("unkown mode: "+n)}}(n)},immediate:!0},firstDayOfWeek:function(t){var e=this.viewState[0],n=e.month,r=e.year;this.calendar=Object.freeze(w({numberOfMonths:this.customNumberOfMonths,viewMode:this.viewMode,firstDayOfWeek:t,month:n,year:r}))},defaultSelectedDates:function(t){this.selectedDates=t.map(O.fromString)}},render:function(){return this.$scopedSlots.default({weekDayNames:this.weekDayNames,monthNames:this.monthNames,monthsList:this.monthsList,calendar:this.calendar,selectedDates:this.selectedDates,currentMonth:this.currentMonth,currentYear:this.currentYear,canGoToPrevMonth:this.canGoToPrevMonth,canGoToNextMonth:this.canGoToNextMonth,prevPage:this.prevPage,nextPage:this.nextPage,resetDates:this.resetDates,setMonth:this.setMonth,onDateMouseOut:this.onDateMouseOut,onDateMouseOver:this.onDateMouseOver,onDateSelect:this.onDateSelect,getModifiers:this.getModifiers})}};exports.RenderlessCalendar=P; |
@@ -1,2 +0,2 @@ | ||
import { MONTH_INDEX_CORRECTION } from '../utils/constants'; | ||
import { MONTH_INDEX_CORRECTION, DAYS_IN_WEEK } from '../utils/constants'; | ||
import { prependZero } from '../utils/fns'; | ||
@@ -11,4 +11,5 @@ import { | ||
export default function CalendarDate(year, month, day, { | ||
isOtherMonthDay = false | ||
} = {}) { | ||
isOtherMonthDay, | ||
firstDayOfWeek | ||
} = { isOtherMonthDay: false, firstDayOfWeek: 1 }) { | ||
const date = new Date(year, month, day); | ||
@@ -18,3 +19,4 @@ | ||
this.dayOfWeek = (date.getDay() + 6) % 7; | ||
// + DAYS_IN_WEEK avoids having negative number in the modulo (-1 % 7 -> 6 % 7) | ||
this.dayOfWeek = (date.getDay() - firstDayOfWeek + DAYS_IN_WEEK) % DAYS_IN_WEEK; | ||
@@ -34,5 +36,5 @@ this.year = date.getFullYear(); | ||
CalendarDate.fromString = function (date) { | ||
CalendarDate.fromString = function (date, { firstDayOfWeek } = { firstDayOfWeek: 1 }) { | ||
const [year, month, day] = date.split('-'); | ||
return new CalendarDate(year, month - MONTH_INDEX_CORRECTION, day); | ||
return new CalendarDate(year, month - MONTH_INDEX_CORRECTION, day, { firstDayOfWeek }); | ||
}; | ||
@@ -39,0 +41,0 @@ |
@@ -92,2 +92,6 @@ import { | ||
default: () => [] | ||
}, | ||
firstDayOfWeek: { | ||
type: Number, | ||
default: 1 | ||
} | ||
@@ -120,3 +124,4 @@ }, | ||
viewMode: this.viewMode, | ||
year: this.currentYear | ||
year: this.currentYear, | ||
firstDayOfWeek: this.firstDayOfWeek | ||
})); | ||
@@ -131,13 +136,11 @@ }, | ||
return typeof this.locale === 'string' | ||
? getCalendarStringsForLocale(this.locale) | ||
? getCalendarStringsForLocale(this.locale, this.firstDayOfWeek) | ||
: this.locale; | ||
}, | ||
weekDayNames() { | ||
// @ts-ignore | ||
return this.localeStrings.days; | ||
}, | ||
monthNames() { | ||
// @ts-ignore | ||
return this.localeStrings.months | ||
.map((month, id) => ({ short: month.short, full: month.full, id })); | ||
.map(({ short, full }, id) => ({ short, full, id })); | ||
}, | ||
@@ -217,3 +220,4 @@ monthsList() { | ||
month: prevMonthDate.getMonth(), | ||
viewMode | ||
viewMode, | ||
firstDayOfWeek: this.firstDayOfWeek | ||
}); | ||
@@ -262,3 +266,4 @@ | ||
month: nextMonthDate.getMonth(), | ||
viewMode | ||
viewMode, | ||
firstDayOfWeek: this.firstDayOfWeek | ||
}); | ||
@@ -313,3 +318,4 @@ | ||
month, | ||
year | ||
year, | ||
firstDayOfWeek: this.firstDayOfWeek | ||
}); | ||
@@ -338,3 +344,3 @@ this.viewState = newViewState; | ||
.map(_ => _.formatted) | ||
.some(formatted => isNextDate(formatted, date.formatted)); | ||
.some(formatted => isNextDate(date.formatted, formatted)); | ||
}, | ||
@@ -344,7 +350,7 @@ isOneDayBefore(date) { | ||
.map(_ => _.formatted) | ||
.some(formatted => isPrevDate(formatted, date.formatted)); | ||
.some(formatted => isPrevDate(date.formatted, formatted)); | ||
}, | ||
isOneDayBeforeFirst(date) { | ||
const first = this.selectedDates[0]; | ||
return first && isPrevDate(first.formatted, date.formatted); | ||
return first && isPrevDate(date.formatted, first.formatted); | ||
}, | ||
@@ -357,3 +363,3 @@ isOneDayAfterFirst(date) { | ||
const last = this.selectedDates[1]; | ||
return last && isPrevDate(last.formatted, date.formatted); | ||
return last && isPrevDate(date.formatted, last.formatted); | ||
}, | ||
@@ -400,2 +406,12 @@ isOneDayAfterLast(date) { | ||
}, | ||
firstDayOfWeek(newFirstDoW) { | ||
const [{ month, year }] = this.viewState; | ||
this.calendar = Object.freeze(generateCalendarViewData({ | ||
numberOfMonths: this.customNumberOfMonths, | ||
viewMode: this.viewMode, | ||
firstDayOfWeek: newFirstDoW, | ||
month, | ||
year | ||
})); | ||
}, | ||
defaultSelectedDates(dates) { | ||
@@ -402,0 +418,0 @@ this.selectedDates = dates.map(CalendarDate.fromString); |
export const MAX_DAYS_IN_YEAR = 366; | ||
export const MAX_DAYS_IN_MONTH = 31; | ||
export const NUMBER_OF_MONTHS = 12; | ||
export const DAYS_IN_WEEK = 7; | ||
export const ZERO_BASED_DAYS_IN_WEEK = 6; | ||
@@ -5,0 +6,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { DAYS_IN_WEEK } from './constants'; | ||
const CALENDAR_STRINGS = {}; | ||
@@ -10,5 +12,6 @@ /** | ||
* @param {string} locale | ||
* @param {number} firstDayOfWeek Index of weekday to start the week from (0: sunday, 6: Saturday) | ||
* @return {LocaleStrings} | ||
*/ | ||
export function getCalendarStringsForLocale(locale) { | ||
export function getCalendarStringsForLocale(locale, firstDayOfWeek) { | ||
if (!(/^[a-z]{2,3}(-[A-Za-z]{2})?$/).test(locale)) { | ||
@@ -18,3 +21,3 @@ locale = navigator.language; | ||
if (!CALENDAR_STRINGS.hasOwnProperty(locale)) { | ||
CALENDAR_STRINGS[locale] = generateLocaleStrings(locale); | ||
CALENDAR_STRINGS[locale] = generateLocaleStrings(locale, firstDayOfWeek); | ||
} | ||
@@ -26,5 +29,8 @@ return CALENDAR_STRINGS[locale]; | ||
* @param {string} locale | ||
* @param {number} firstDayOfWeek Index of weekday to start the week from (0: sunday, 6: Saturday) | ||
* @return {LocaleStrings} | ||
*/ | ||
function generateLocaleStrings(locale) { | ||
function generateLocaleStrings(locale, firstDayOfWeek = 1) { | ||
const validFirstDayOfWeek = firstDayOfWeek % DAYS_IN_WEEK; | ||
const today = new Date(); | ||
@@ -35,3 +41,3 @@ const year = today.getFullYear(); | ||
const months = [...Array(12)].map((_, i) => { | ||
const months = Array(12).fill().map((_, i) => { | ||
const d = new Date(year, i); | ||
@@ -43,4 +49,6 @@ return { | ||
}); | ||
const firstMondayDate = today.getDate() - day + (day === 0 ? -6 : 1); | ||
const days = [...Array(7)].map((_, i) => { | ||
// Get day number - index of current weekday + the weekday index we want to start from | ||
// ex: 16 (16th in the month) - 2 (it's a Tuesday) = 14 (previous Sunday number) => + 1 to go to next Monday | ||
const firstMondayDate = today.getDate() - day + validFirstDayOfWeek; | ||
const days = Array(7).fill().map((_, i) => { | ||
const d = new Date(year, month, firstMondayDate + i); | ||
@@ -47,0 +55,0 @@ return { |
@@ -8,3 +8,9 @@ import { | ||
} from './constants'; | ||
import { getMonthDateSafely, isEqual, isGreaterThan, isLessThan, isSameMonth } from './renderless-date.service'; | ||
import { | ||
getMonthDateSafely, | ||
isEqual, | ||
isGreaterThan, | ||
isLessThan, | ||
isSameMonth | ||
} from './renderless-date.service'; | ||
import CalendarDate from '../classes/CalendarDate'; | ||
@@ -21,3 +27,4 @@ | ||
month, | ||
year | ||
year, | ||
firstDayOfWeek | ||
}) { | ||
@@ -39,5 +46,5 @@ const months = viewMode === VIEW_MODE_CUSTOM | ||
const currentMonthDates = getCurrentMonthDates(year, month); | ||
const prevMonthDates = getPrevMonthDates(currentMonthDates[0]); | ||
const nextMonthDates = getNextMonthDates(currentMonthDates[currentMonthDates.length - 1]); | ||
const currentMonthDates = getCurrentMonthDates(year, month, firstDayOfWeek); | ||
const prevMonthDates = getPrevMonthDates(currentMonthDates[0], firstDayOfWeek); | ||
const nextMonthDates = getNextMonthDates(currentMonthDates[currentMonthDates.length - 1], firstDayOfWeek); | ||
@@ -59,11 +66,11 @@ result.push({ | ||
export function getPrevMonthDates(date) { | ||
return _getMonthLastNDays(date.dayOfWeek, date.year, date.month); | ||
export function getPrevMonthDates(date, firstDayOfWeek = 1) { | ||
return _getMonthLastNDays(date.dayOfWeek, date.year, date.month, { firstDayOfWeek }); | ||
} | ||
export function getCurrentMonthDates(year, month) { | ||
export function getCurrentMonthDates(year, month, firstDayOfWeek = 1) { | ||
const dates = []; | ||
for (let day = 1; day <= MAX_DAYS_IN_MONTH; day++) { | ||
dates.push(new CalendarDate(year, month, day)); | ||
dates.push(new CalendarDate(year, month, day, { firstDayOfWeek })); | ||
} | ||
@@ -74,8 +81,8 @@ | ||
export function getNextMonthDates(date) { | ||
export function getNextMonthDates(date, firstDayOfWeek = 1) { | ||
const numberOfDays = ZERO_BASED_DAYS_IN_WEEK - date.dayOfWeek; | ||
return _getMonthFirstNDays(numberOfDays, date.year, date.month); | ||
return _getMonthFirstNDays(numberOfDays, date.year, date.month, { firstDayOfWeek }); | ||
} | ||
export function _getMonthLastNDays(n, year, month) { | ||
export function _getMonthLastNDays(n, year, month, firstDayOfWeek = 1) { | ||
const dates = []; | ||
@@ -86,4 +93,4 @@ const prevMonthNumber = month - 1; | ||
while (dates.length !== n) { | ||
const date = new CalendarDate(year, prevMonthNumber, dayNumber, { isOtherMonthDay: true }); | ||
while (dates.length < n) { | ||
const date = new CalendarDate(year, prevMonthNumber, dayNumber, { isOtherMonthDay: true, firstDayOfWeek }); | ||
@@ -100,3 +107,3 @@ if (!isSameMonth(month, date.month)) { | ||
export function _getMonthFirstNDays(n, year, month) { | ||
export function _getMonthFirstNDays(n, year, month, firstDayOfWeek = 1) { | ||
const dates = []; | ||
@@ -106,3 +113,3 @@ const nextMonthNumber = month + 1; | ||
for (let dayNumber = 1; dayNumber <= n; dayNumber++) { | ||
const date = new CalendarDate(year, nextMonthNumber, dayNumber, { isOtherMonthDay: true }); | ||
const date = new CalendarDate(year, nextMonthNumber, dayNumber, { isOtherMonthDay: true, firstDayOfWeek }); | ||
dates.push(date); | ||
@@ -109,0 +116,0 @@ } |
{ | ||
"name": "vue-renderless-calendar", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "lib/types/index.d.ts", | ||
"author": "Seitmagambet Olzhas <seit7magambet@gmail.com>", | ||
@@ -52,2 +53,3 @@ "description": "Zero dependency Vue renderless calendar with scoped-slots API", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-terser": "^5.2.0", | ||
@@ -54,0 +56,0 @@ "sass-loader": "^7.1.0", |
@@ -32,2 +32,3 @@ # vue-renderless-calendar 📆 | ||
| markedDates | false | Array<String> | [] | Array of `YYYY-MM-DDD` strings with special meaning, that later will be accessed via `isMarked` modifier | | ||
| firstDayOfWeek | false | number | 1 | Index of the weekday to start the week from. From 0 to 6. 0 is Sunday, 6 is Saturday | | ||
@@ -74,3 +75,3 @@ | ||
| isSelected | Boolean | | ||
| isBetween | Boolean | | ||
| isBetween | Boolean | | ||
| isDisabled | Boolean | | ||
@@ -77,0 +78,0 @@ | isMarked | Boolean | |
import { terser } from 'rollup-plugin-terser'; | ||
import buble from 'rollup-plugin-buble'; | ||
import sourcemaps from 'rollup-plugin-sourcemaps'; | ||
import fs from 'fs'; | ||
@@ -36,2 +37,3 @@ import path from 'path'; | ||
{ | ||
sourcemap: !production, | ||
format: 'es', | ||
@@ -42,2 +44,3 @@ dir: 'dist', | ||
{ | ||
sourcemap: !production, | ||
format: 'cjs', | ||
@@ -49,4 +52,5 @@ dir: 'dist' | ||
buble(), | ||
!production && sourcemaps(), | ||
production && terser() | ||
] | ||
}, ...locales]; |
75806
31
1450
103
24