New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vue-renderless-calendar

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-renderless-calendar - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

.eslintrc.js

4

babel.config.js
module.exports = {
presets: [
'@babel/preset-env'
]
presets: ['@babel/preset-env'],
};

@@ -0,7 +1,21 @@

## v2.4.0
### Added
- Added vue@3 support via vue-demi. Replaced scoped-slots api usage
### Fixed
- Omit `window.navigator` reference in SSR environment
## v2.3.0
### Added
- Added type definitions
- Added sourcemaps for dev mode
- Add `firstDayOfWeek` prop
### Fixed
- Fixed incorrect behavior of `isOneDayBefore`, `isOneDayAfter`, `isOneDayBeforeLast`, `isOneDayBeforeFirst` methods

@@ -12,2 +26,3 @@

### Added
- Added CommonJS build output

@@ -25,2 +40,3 @@

### Added
- Added `getModifiers` method that can be imported from scoped slot of `RenderlessCalendar`

@@ -31,2 +47,3 @@ - Added `custom-number-of-months` prop for controlling number of months generated by library

### Changed
- `isBetween` method moved inside to `getModifiers` method, and is no longer exported

@@ -36,3 +53,4 @@ - Updated examples

### Removed
- Removed `RenderlessDate` component due to performance issues
- Removed `infinite` mode

@@ -1,1 +0,1 @@

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};
import{isVue3 as t}from"vue-demi";var e="single",n="range",r="single",a="double",i="custom";function s(t,e){return[e]}function o(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function u(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 h(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function f(t,e){var n=e[0],r=e[1];return D(t,n)&&m(t,r)}function c(t,e){return d(e,t)}function l(t,e){return d(t,e)}function d(t,e){return h(t).valueOf()-h(e).valueOf()==864e5}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 t===e}function g(t,e){return new Date(t,e)}function M(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&&m(t,a)||r&&D(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function O(t){return t<10?"0"+t:t}function p(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(O).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}p.fromString=function(t,e){void 0===e&&(e={firstDayOfWeek:1});var n=e.firstDayOfWeek,r=t.split("-");return new p(r[0],r[1]-1,r[2],{firstDayOfWeek:n})},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],s=r[1],o=e&&e.formatted,u=i&&i.formatted,h=s&&s.formatted;return!s&&o?f(a,[u,o])||f(a,[o,u]):n&&o?f(a,[u,o])||f(a,[o,h]):f(a,[u,h])},p.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return v(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var w={};function S(t){for(var e=t.numberOfMonths,n=t.viewMode,r=t.month,a=t.year,s=t.firstDayOfWeek,o=[],u=r+(n===i?e:w[n]),h=r,f=a,c=r;h<u;){var l=g(f,c),d=l.getFullYear(),m=l.getMonth(),D=b(d,m,s),v=k(D[0],s),y=Y(D[D.length-1],s);o.push({dates:v.concat(D,y),month:m,year:d}),f=d,c=m+1,h++}return o}function k(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 p(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});y(n,o.month)||a.unshift(o),s--}return a}(t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function b(t,e,n){void 0===n&&(n=1);for(var r=[],a=1;a<=31;a++)r.push(new p(t,e,a,{firstDayOfWeek:n}));return r.filter((function(t){return y(e,t.month)}))}function Y(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 p(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});a.push(o)}return a}(6-t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}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],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n+1;return v(u,e)&&m(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 v(u,e)&&D(h,f)}(r,e,n)}w[r]=1,w[a]=2;var N={};N[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},N[a]=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}]},N[i]=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 W={};W[r]={prevPage:function(){},nextPage:function(){}},W[a]={prevPage:function(){},nextPage:function(){}};var x={};function B(t,e){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t="object"==typeof navigator?navigator.language:"en"),x.hasOwnProperty(t)||(x[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)),x[t]}var P={name:"RenderlessCalendar",props:{viewMode:{type:String,validator:function(t){return-1!==[r,a,i].indexOf(t)},default:r},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(t){return-1!==[e,n].indexOf(t)},default:e},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}},emits:["onDateChange"],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,N[t](e)),this.viewNavigator=function(t){return W[t]}(this.viewMode),this.calendar=Object.freeze(S({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear,firstDayOfWeek:this.firstDayOfWeek}))},computed:{localeStrings:function(){return"string"==typeof this.locale?B(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!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){M(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,n=this.customNumberOfMonths,i=t[0],s=i.year,o=i.month,u=[];if(!this.shouldPreventMonthChange(s,o,-1)){var h=g(s,o-1),f=S({numberOfMonths:n,year:h.getFullYear(),month:h.getMonth(),viewMode:e,firstDayOfWeek:this.firstDayOfWeek});if(e===r)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===a){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,n=this.customNumberOfMonths,i=[],s=t===r?e[0]:e[1],o=s.year,u=s.month;if(!this.shouldPreventMonthChange(o,u,1)){if(t===a){var h=e[0];o=h.year,u=h.month}var f=g(o,u+1),c=S({numberOfMonths:n,year:f.getFullYear(),month:f.getMonth(),viewMode:t,firstDayOfWeek:this.firstDayOfWeek});if(t===r)i=[{year:f.getFullYear(),month:f.getMonth()}];else if(t===a){var l=e[1],d=g(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&&F({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,n=t.year,i=this.viewMode,s=this.customNumberOfMonths,o=[];if(i===r&&(o=[{month:e,year:n}]),i===a){var u=g(n,e+1);o=[{month:e,year:n},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=S({numberOfMonths:s,viewMode:i,month:e,year:n,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 M(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 l(t.formatted,e)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(t.formatted,e)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&c(t.formatted,e.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&l(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&c(t.formatted,e.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&l(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&v(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&v(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(t){this.dateChangeHangler=this.dateSelectStrategy||function(t){switch(t){case e:return s;case n:return u;default:throw new Error("unkown mode: "+t)}}(t)},immediate:!0},firstDayOfWeek:function(t){var e=this.viewState[0],n=e.month,r=e.year;this.calendar=Object.freeze(S({numberOfMonths:this.customNumberOfMonths,viewMode:this.viewMode,firstDayOfWeek:t,month:n,year:r}))},defaultSelectedDates:function(t){this.selectedDates=t.map(p.fromString)}},render:function(){var e={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};return t?this.$slots.default(e):this.$scopedSlots.default(e)}};export{P 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 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;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vue-demi"),e="single",n="range",r="single",a="double",i="custom";function s(t,e){return[e]}function o(t,e){return[t,e].slice(0).sort((function(t,e){return t.ms-e.ms}))}function u(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 h(t){return new(Function.prototype.bind.apply(Date,[null].concat(t.split("-"))))}function f(t,e){var n=e[0],r=e[1];return D(t,n)&&m(t,r)}function c(t,e){return d(e,t)}function l(t,e){return d(t,e)}function d(t,e){return h(t).valueOf()-h(e).valueOf()==864e5}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 t===e}function g(t,e){return new Date(t,e)}function M(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&&m(t,a)||r&&D(t,r)||function(t,e){return-1!==e.indexOf(t)}(t,n)}function O(t){return t<10?"0"+t:t}function p(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(O).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}p.fromString=function(t,e){void 0===e&&(e={firstDayOfWeek:1});var n=e.firstDayOfWeek,r=t.split("-");return new p(r[0],r[1]-1,r[2],{firstDayOfWeek:n})},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],s=r[1],o=e&&e.formatted,u=i&&i.formatted,h=s&&s.formatted;return!s&&o?f(a,[u,o])||f(a,[o,u]):n&&o?f(a,[u,o])||f(a,[o,h]):f(a,[u,h])},p.prototype.isSelected=function(t){return void 0===t&&(t=[]),function(t,e){return e.some((function(e){return v(e,t)}))}(this.formatted,t.map((function(t){return t.formatted})))};var w={};function S(t){for(var e=t.numberOfMonths,n=t.viewMode,r=t.month,a=t.year,s=t.firstDayOfWeek,o=[],u=r+(n===i?e:w[n]),h=r,f=a,c=r;h<u;){var l=g(f,c),d=l.getFullYear(),m=l.getMonth(),D=b(d,m,s),v=k(D[0],s),y=Y(D[D.length-1],s);o.push({dates:v.concat(D,y),month:m,year:d}),f=d,c=m+1,h++}return o}function k(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 p(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});y(n,o.month)||a.unshift(o),s--}return a}(t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}function b(t,e,n){void 0===n&&(n=1);for(var r=[],a=1;a<=31;a++)r.push(new p(t,e,a,{firstDayOfWeek:n}));return r.filter((function(t){return y(e,t.month)}))}function Y(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 p(e,i,s,{isOtherMonthDay:!0,firstDayOfWeek:r});a.push(o)}return a}(6-t.dayOfWeek,t.year,t.month,{firstDayOfWeek:e})}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],s=r[2],o=new Date(a,i-1,s),u=o.getFullYear(),h=o.getMonth(),f=n+1;return v(u,e)&&m(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 v(u,e)&&D(h,f)}(r,e,n)}w[r]=1,w[a]=2;var x={};x[r]=function(){var t=new Date,e=t.getFullYear(),n=t.getMonth();return[{year:e,month:n}]},x[a]=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}]},x[i]=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 N={};N[r]={prevPage:function(){},nextPage:function(){}},N[a]={prevPage:function(){},nextPage:function(){}};var W={};function P(t,e){return/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(t)||(t="object"==typeof navigator?navigator.language:"en"),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!==[r,a,i].indexOf(t)},default:r},customNumberOfMonths:{type:Number,default:0},mode:{type:String,validator:function(t){return-1!==[e,n].indexOf(t)},default:e},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}},emits:["onDateChange"],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,x[t](e)),this.viewNavigator=function(t){return N[t]}(this.viewMode),this.calendar=Object.freeze(S({numberOfMonths:this.customNumberOfMonths,month:this.currentMonth,viewMode:this.viewMode,year:this.currentYear,firstDayOfWeek:this.firstDayOfWeek}))},computed:{localeStrings:function(){return"string"==typeof this.locale?P(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!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){M(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,n=this.customNumberOfMonths,i=t[0],s=i.year,o=i.month,u=[];if(!this.shouldPreventMonthChange(s,o,-1)){var h=g(s,o-1),f=S({numberOfMonths:n,year:h.getFullYear(),month:h.getMonth(),viewMode:e,firstDayOfWeek:this.firstDayOfWeek});if(e===r)u=[{year:h.getFullYear(),month:h.getMonth()}];else if(e===a){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,n=this.customNumberOfMonths,i=[],s=t===r?e[0]:e[1],o=s.year,u=s.month;if(!this.shouldPreventMonthChange(o,u,1)){if(t===a){var h=e[0];o=h.year,u=h.month}var f=g(o,u+1),c=S({numberOfMonths:n,year:f.getFullYear(),month:f.getMonth(),viewMode:t,firstDayOfWeek:this.firstDayOfWeek});if(t===r)i=[{year:f.getFullYear(),month:f.getMonth()}];else if(t===a){var l=e[1],d=g(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&&F({currentMonth:e,currentYear:t,minDate:this.minDate,maxDate:this.maxDate,step:n})},setMonth:function(t){var e=t.month,n=t.year,i=this.viewMode,s=this.customNumberOfMonths,o=[];if(i===r&&(o=[{month:e,year:n}]),i===a){var u=g(n,e+1);o=[{month:e,year:n},{year:u.getFullYear(),month:u.getMonth()}]}this.calendar=S({numberOfMonths:s,viewMode:i,month:e,year:n,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 M(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 l(t.formatted,e)}))},isOneDayBefore:function(t){return this.selectedDates.map((function(t){return t.formatted})).some((function(e){return c(t.formatted,e)}))},isOneDayBeforeFirst:function(t){var e=this.selectedDates[0];return e&&c(t.formatted,e.formatted)},isOneDayAfterFirst:function(t){var e=this.selectedDates[0];return e&&l(t.formatted,e.formatted)},isOneDayBeforeLast:function(t){var e=this.selectedDates[1];return e&&c(t.formatted,e.formatted)},isOneDayAfterLast:function(t){var e=this.selectedDates[1];return e&&l(t.formatted,e.formatted)},isFirst:function(t){var e=this.selectedDates[0];return e&&v(t.formatted,e.formatted)},isLast:function(t){var e=this.selectedDates[1];return e&&v(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(t){this.dateChangeHangler=this.dateSelectStrategy||function(t){switch(t){case e:return s;case n:return u;default:throw new Error("unkown mode: "+t)}}(t)},immediate:!0},firstDayOfWeek:function(t){var e=this.viewState[0],n=e.month,r=e.year;this.calendar=Object.freeze(S({numberOfMonths:this.customNumberOfMonths,viewMode:this.viewMode,firstDayOfWeek:t,month:n,year:r}))},defaultSelectedDates:function(t){this.selectedDates=t.map(p.fromString)}},render:function(){var e={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};return t.isVue3?this.$slots.default(e):this.$scopedSlots.default(e)}};exports.RenderlessCalendar=B;

@@ -7,9 +7,14 @@ import { MONTH_INDEX_CORRECTION, DAYS_IN_WEEK } from '../utils/constants';

isWeekend,
isToday
isToday,
} from '../utils/renderless-date.service';
export default function CalendarDate(year, month, day, {
isOtherMonthDay,
firstDayOfWeek
} = { isOtherMonthDay: false, firstDayOfWeek: 1 }) {
export default function CalendarDate(
year,
month,
day,
{ isOtherMonthDay, firstDayOfWeek } = {
isOtherMonthDay: false,
firstDayOfWeek: 1,
}
) {
const date = new Date(year, month, day);

@@ -20,3 +25,4 @@

// + 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;
this.dayOfWeek =
(date.getDay() - firstDayOfWeek + DAYS_IN_WEEK) % DAYS_IN_WEEK;

@@ -29,3 +35,4 @@ this.year = date.getFullYear();

this.formatted = [this.year, this.actualMonthNumber, this.day]
.map(prependZero).join('-');
.map(prependZero)
.join('-');

@@ -37,5 +44,10 @@ this.isWeekend = isWeekend(date);

CalendarDate.fromString = function (date, { firstDayOfWeek } = { firstDayOfWeek: 1 }) {
CalendarDate.fromString = function (
date,
{ firstDayOfWeek } = { firstDayOfWeek: 1 }
) {
const [year, month, day] = date.split('-');
return new CalendarDate(year, month - MONTH_INDEX_CORRECTION, day, { firstDayOfWeek });
return new CalendarDate(year, month - MONTH_INDEX_CORRECTION, day, {
firstDayOfWeek,
});
};

@@ -46,3 +58,3 @@

captureThirdDate,
selectedDates
selectedDates,
}) {

@@ -56,3 +68,4 @@ if (selectedDates.length === 0) {

const formattedHoveredDate = currentHoveredDate && currentHoveredDate.formatted;
const formattedHoveredDate =
currentHoveredDate && currentHoveredDate.formatted;
const formattedLeftDate = left && left.formatted;

@@ -62,9 +75,13 @@ const formattedRightDate = right && right.formatted;

if (!right && formattedHoveredDate) {
return isBetween(formatted, [formattedLeftDate, formattedHoveredDate])
|| isBetween(formatted, [formattedHoveredDate, formattedLeftDate]);
return (
isBetween(formatted, [formattedLeftDate, formattedHoveredDate]) ||
isBetween(formatted, [formattedHoveredDate, formattedLeftDate])
);
}
if (captureThirdDate && formattedHoveredDate) {
return isBetween(formatted, [formattedLeftDate, formattedHoveredDate])
|| isBetween(formatted, [formattedHoveredDate, formattedRightDate]);
return (
isBetween(formatted, [formattedLeftDate, formattedHoveredDate]) ||
isBetween(formatted, [formattedHoveredDate, formattedRightDate])
);
}

@@ -75,5 +92,7 @@

CalendarDate.prototype.isSelected = function (selectedDates = []) {
return isSelected(this.formatted, selectedDates.map(_ => _.formatted));
return isSelected(
this.formatted,
selectedDates.map(_ => _.formatted)
);
};

@@ -28,5 +28,6 @@ export function rangeDateStrategy(dates, newDate) {

function sortDates(date, comparedDate) {
return [date, comparedDate].slice(0).sort((date1, date2) => date1.ms - date2.ms);
return [date, comparedDate]
.slice(0)
.sort((date1, date2) => date1.ms - date2.ms);
}
const months = [
{
short: 'Jan',
full: 'January'
full: 'January',
},
{
short: 'Feb',
full: 'February'
full: 'February',
},
{
short: 'Mar',
full: 'March'
full: 'March',
},
{
short: 'Apr',
full: 'April'
full: 'April',
},
{
short: 'May',
full: 'May'
full: 'May',
},
{
short: 'Jun',
full: 'June'
full: 'June',
},
{
short: 'Jul',
full: 'July'
full: 'July',
},
{
short: 'Aug',
full: 'August'
full: 'August',
},
{
short: 'Sep',
full: 'September'
full: 'September',
},
{
short: 'Oct',
full: 'October'
full: 'October',
},
{
short: 'Nov',
full: 'November'
full: 'November',
},
{
short: 'Dec',
full: 'December'
}
full: 'December',
},
];

@@ -55,28 +55,28 @@

short: 'Mon',
full: 'Monday'
full: 'Monday',
},
{
short: 'Tue',
full: 'Tuesday'
full: 'Tuesday',
},
{
short: 'Wed',
full: 'Wednesday'
full: 'Wednesday',
},
{
short: 'Thu',
full: 'Thursday'
full: 'Thursday',
},
{
short: 'Fri',
full: 'Friday'
full: 'Friday',
},
{
short: 'Sat',
full: 'Saturday'
full: 'Saturday',
},
{
short: 'Sun',
full: 'Sunday'
}
full: 'Sunday',
},
];

@@ -86,5 +86,5 @@

months,
days
days,
};
export default locale;
const months = [
{
short: 'Янв',
full: 'Январь'
full: 'Январь',
},
{
short: 'Фев',
full: 'Февраль'
full: 'Февраль',
},
{
short: 'Мар',
full: 'Март'
full: 'Март',
},
{
short: 'Апр',
full: 'Апрель'
full: 'Апрель',
},
{
short: 'Май',
full: 'Май'
full: 'Май',
},
{
short: 'Июн',
full: 'Июнь'
full: 'Июнь',
},
{
short: 'Июл',
full: 'Июль'
full: 'Июль',
},
{
short: 'Авг',
full: 'Август'
full: 'Август',
},
{
short: 'Сен',
full: 'Сентябрь'
full: 'Сентябрь',
},
{
short: 'Окт',
full: 'Октябрь'
full: 'Октябрь',
},
{
short: 'Ноя',
full: 'Ноябрь'
full: 'Ноябрь',
},
{
short: 'Дек',
full: 'Декабрь'
}
full: 'Декабрь',
},
];

@@ -55,28 +55,28 @@

short: 'Пн',
full: 'Понедельник'
full: 'Понедельник',
},
{
short: 'Вт',
full: 'Вторник'
full: 'Вторник',
},
{
short: 'Ср',
full: 'Среда'
full: 'Среда',
},
{
short: 'Чт',
full: 'Четверг'
full: 'Четверг',
},
{
short: 'Пт',
full: 'Пятница'
full: 'Пятница',
},
{
short: 'Сб',
full: 'Суббота'
full: 'Суббота',
},
{
short: 'Вс',
full: 'Воскресенье'
}
full: 'Воскресенье',
},
];

@@ -86,5 +86,5 @@

months,
days
days,
};
export default locale;

@@ -0,5 +1,8 @@

import { isVue3 } from 'vue-demi';
import {
MODE_RANGE, MODE_SINGLE,
MODE_RANGE,
MODE_SINGLE,
VIEW_MODE_DOUBLE,
VIEW_MODE_SINGLE, VIEW_MODE_CUSTOM
VIEW_MODE_SINGLE,
VIEW_MODE_CUSTOM,
} from './utils/constants';

@@ -11,3 +14,3 @@ import { getDateSelectStrategy } from './utils/get-date-select-strategy';

resetDate,
getMonthsList
getMonthsList,
} from './utils/renderless-calendar.service';

@@ -21,5 +24,8 @@ import CalendarDate from './classes/CalendarDate';

isPrevDate,
isRestricted
isRestricted,
} from './utils/renderless-date.service';
import { viewModeInitializer, getViewNavigator } from './utils/view-mode.service';
import {
viewModeInitializer,
getViewNavigator,
} from './utils/view-mode.service';
import { getCalendarStringsForLocale } from './utils/locale-strings';

@@ -40,9 +46,12 @@ /**

validator(v) {
return [VIEW_MODE_SINGLE, VIEW_MODE_DOUBLE, VIEW_MODE_CUSTOM].indexOf(v) !== -1;
return (
[VIEW_MODE_SINGLE, VIEW_MODE_DOUBLE, VIEW_MODE_CUSTOM].indexOf(v) !==
-1
);
},
default: VIEW_MODE_SINGLE
default: VIEW_MODE_SINGLE,
},
customNumberOfMonths: {
type: Number,
default: 0
default: 0,
},

@@ -54,50 +63,52 @@ mode: {

},
default: MODE_SINGLE
default: MODE_SINGLE,
},
locale: {
type: [String, Object],
default: ''
default: '',
},
minDate: {
type: String,
default: ''
default: '',
},
maxDate: {
type: String,
default: ''
default: '',
},
preventOutOfRange: {
default: true,
type: Boolean
type: Boolean,
},
captureThirdDate: {
type: Boolean,
default: false
default: false,
},
dateSelectStrategy: {
type: Function,
default: null
default: null,
},
defaultSelectedDates: {
type: Array,
default: () => []
default: () => [],
},
captureHover: {
type: Boolean,
default: true
default: true,
},
disabledDates: {
type: Array,
default: () => []
default: () => [],
},
markedDates: {
type: Array,
default: () => []
default: () => [],
},
firstDayOfWeek: {
type: Number,
default: 1
}
default: 1,
},
},
emits: ['onDateChange'],
data() {

@@ -111,3 +122,3 @@ return {

currentHoveredDate: null,
viewState: []
viewState: [],
};

@@ -122,11 +133,16 @@ },

this.viewState = viewModeInitializer(this.viewMode, this.customNumberOfMonths);
this.viewState = viewModeInitializer(
this.viewMode,
this.customNumberOfMonths
);
this.viewNavigator = getViewNavigator(this.viewMode);
this.calendar = Object.freeze(generateCalendarViewData({
numberOfMonths: this.customNumberOfMonths,
month: this.currentMonth,
viewMode: this.viewMode,
year: this.currentYear,
firstDayOfWeek: this.firstDayOfWeek
}));
this.calendar = Object.freeze(
generateCalendarViewData({
numberOfMonths: this.customNumberOfMonths,
month: this.currentMonth,
viewMode: this.viewMode,
year: this.currentYear,
firstDayOfWeek: this.firstDayOfWeek,
})
);
},

@@ -147,4 +163,7 @@

monthNames() {
return this.localeStrings.months
.map(({ short, full }, id) => ({ short, full, id }));
return this.localeStrings.months.map(({ short, full }, id) => ({
short,
full,
id,
}));
},

@@ -156,3 +175,3 @@ monthsList() {

monthNames: this.monthNames,
viewState: this.viewState
viewState: this.viewState,
});

@@ -168,3 +187,3 @@ },

currentYear: year,
step: -1
step: -1,
});

@@ -180,5 +199,5 @@ },

currentYear: year,
step: 1
step: 1,
});
}
},
},

@@ -188,7 +207,9 @@

onDateSelect(date) {
if (isRestricted(date.formatted, {
disabledDates: this.disabledDates,
maxDate: this.maxDate,
minDate: this.minDate
})) {
if (
isRestricted(date.formatted, {
disabledDates: this.disabledDates,
maxDate: this.maxDate,
minDate: this.minDate,
})
) {
return;

@@ -229,17 +250,22 @@ }

viewMode,
firstDayOfWeek: this.firstDayOfWeek
firstDayOfWeek: this.firstDayOfWeek,
});
if (viewMode === VIEW_MODE_SINGLE) {
newViewState = [{
year: prevMonthDate.getFullYear(),
month: prevMonthDate.getMonth()
}];
newViewState = [
{
year: prevMonthDate.getFullYear(),
month: prevMonthDate.getMonth(),
},
];
} else if (viewMode === VIEW_MODE_DOUBLE) {
const first = viewState[0];
newViewState = [{
year: prevMonthDate.getFullYear(),
month: prevMonthDate.getMonth()
}, first];
newViewState = [
{
year: prevMonthDate.getFullYear(),
month: prevMonthDate.getMonth(),
},
first,
];
}

@@ -249,3 +275,2 @@

this.viewState = newViewState;
},

@@ -255,5 +280,4 @@ nextPage() {

let newViewState = [];
let { year, month } = viewMode === VIEW_MODE_SINGLE
? viewState[0]
: viewState[1];
let { year, month } =
viewMode === VIEW_MODE_SINGLE ? viewState[0] : viewState[1];

@@ -277,10 +301,12 @@ if (this.shouldPreventMonthChange(year, month, 1)) {

viewMode,
firstDayOfWeek: this.firstDayOfWeek
firstDayOfWeek: this.firstDayOfWeek,
});
if (viewMode === VIEW_MODE_SINGLE) {
newViewState = [{
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth()
}];
newViewState = [
{
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth(),
},
];
} else if (viewMode === VIEW_MODE_DOUBLE) {

@@ -290,6 +316,9 @@ const second = viewState[1];

newViewState = [second, {
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth()
}];
newViewState = [
second,
{
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth(),
},
];
}

@@ -301,9 +330,12 @@

shouldPreventMonthChange(year, month, step) {
return this.preventOutOfRange && shouldPreventMonthChange({
currentMonth: month,
currentYear: year,
minDate: this.minDate,
maxDate: this.maxDate,
step
});
return (
this.preventOutOfRange &&
shouldPreventMonthChange({
currentMonth: month,
currentYear: year,
minDate: this.minDate,
maxDate: this.maxDate,
step,
})
);
},

@@ -317,9 +349,13 @@ setMonth(monthListItem) {

newViewState = [{ month, year }];
} if (viewMode === VIEW_MODE_DOUBLE) {
}
if (viewMode === VIEW_MODE_DOUBLE) {
const nextMonthDate = getMonthDateSafely(year, month + 1);
newViewState = [{ month, year }, {
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth()
}];
newViewState = [
{ month, year },
{
year: nextMonthDate.getFullYear(),
month: nextMonthDate.getMonth(),
},
];
}

@@ -332,3 +368,3 @@

year,
firstDayOfWeek: this.firstDayOfWeek
firstDayOfWeek: this.firstDayOfWeek,
});

@@ -338,7 +374,10 @@ this.viewState = newViewState;

isBetween(date) {
return this.captureHover && date.isBetween({
currentHoveredDate: this.currentHoveredDate,
captureThirdDate: this.captureThirdDate,
selectedDates: this.selectedDates
});
return (
this.captureHover &&
date.isBetween({
currentHoveredDate: this.currentHoveredDate,
captureThirdDate: this.captureThirdDate,
selectedDates: this.selectedDates,
})
);
},

@@ -352,3 +391,3 @@ isSelected(date) {

maxDate: this.maxDate,
minDate: this.minDate
minDate: this.minDate,
});

@@ -406,5 +445,5 @@ },

isLast: this.isLast(date),
isMarked: this.isMarked(date)
isMarked: this.isMarked(date),
};
}
},
},

@@ -415,23 +454,26 @@

handler(mode) {
this.dateChangeHangler = this.dateSelectStrategy || getDateSelectStrategy(mode);
this.dateChangeHangler =
this.dateSelectStrategy || getDateSelectStrategy(mode);
},
immediate: true
immediate: true,
},
firstDayOfWeek(newFirstDoW) {
const [{ month, year }] = this.viewState;
this.calendar = Object.freeze(generateCalendarViewData({
numberOfMonths: this.customNumberOfMonths,
viewMode: this.viewMode,
firstDayOfWeek: newFirstDoW,
month,
year
}));
this.calendar = Object.freeze(
generateCalendarViewData({
numberOfMonths: this.customNumberOfMonths,
viewMode: this.viewMode,
firstDayOfWeek: newFirstDoW,
month,
year,
})
);
},
defaultSelectedDates(dates) {
this.selectedDates = dates.map(CalendarDate.fromString);
}
},
},
render() {
return this.$scopedSlots.default({
const api = {
weekDayNames: this.weekDayNames,

@@ -458,5 +500,7 @@ monthNames: this.monthNames,

getModifiers: this.getModifiers
});
}
getModifiers: this.getModifiers,
};
return isVue3 ? this.$slots.default(api) : this.$scopedSlots.default(api);
},
};

@@ -1,21 +0,30 @@

import Vue from "vue";
import { CombinedVueInstance } from "vue/types/vue";
import Vue from 'vue';
import { CombinedVueInstance } from 'vue/types/vue';
export class CalendarDate {
ms: number
dayOfWeek: number
year: number
month: number
day: number
actualMonthNumber: number
formatted: string
isWeekend: boolean
isToday: boolean
isOtherMonthDay: boolean
ms: number;
dayOfWeek: number;
year: number;
month: number;
day: number;
actualMonthNumber: number;
formatted: string;
isWeekend: boolean;
isToday: boolean;
isOtherMonthDay: boolean;
constructor(year: number, month: number, day: number, options: { isOtherMonthDay: boolean, firstDayOfWeek: number })
constructor(
year: number,
month: number,
day: number,
options: { isOtherMonthDay: boolean; firstDayOfWeek: number }
);
fromString(date, options: { firstDayOfWeek: number }): string;
static isBetween(options: { currentHoveredDate, captureThirdDate, selectedDates }): boolean;
static isBetween(options: {
currentHoveredDate;
captureThirdDate;
selectedDates;
}): boolean;

@@ -28,91 +37,91 @@ static isSelected(isSelected: any): boolean;

type DigitNoZero = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
type Digit = '0' | DigitNoZero
type DayFirstDigit = '1' | '2' | '3'
type DayNb = `0${DigitNoZero}` | `1${Digit}` | `2${Digit}` | `3${'0' | '1'}`
type MonthNb = `0${Digit}` | `1${'0' | '1' | '2'}`
type YearNb = `${number}` // Year type is too complicated for Typescript to be described as four digits
export type DateFormat = `${YearNb}-${MonthNb}-${DayNb}`
type DigitNoZero = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
type Digit = '0' | DigitNoZero;
type DayFirstDigit = '1' | '2' | '3';
type DayNb = `0${DigitNoZero}` | `1${Digit}` | `2${Digit}` | `3${'0' | '1'}`;
type MonthNb = `0${Digit}` | `1${'0' | '1' | '2'}`;
type YearNb = `${number}`; // Year type is too complicated for Typescript to be described as four digits
export type DateFormat = `${YearNb}-${MonthNb}-${DayNb}`;
export interface MonthName {
short: string
full: string
id: number
short: string;
full: string;
id: number;
}
export interface Month extends MonthName {
isActive: boolean
month: number
year: number
isActive: boolean;
month: number;
year: number;
}
export type MonthYear = Pick<Month, 'month' | 'year'>
export type MonthYear = Pick<Month, 'month' | 'year'>;
export interface Calendar {
dates: Array<CalendarDate>,
month: number,
year: number
dates: Array<CalendarDate>;
month: number;
year: number;
}
export interface Modifiers<T> {
isBetween(date: T): boolean
isSelected(date: T): boolean
isDisabled(date: T): boolean
isOneDayAfter(date: T): boolean
isOneDayBefore(date: T): boolean
isOneDayBeforeFirst(date: T): boolean
isOneDayAfterFirst(date: T): boolean
isOneDayBeforeLast(date: T): boolean
isOneDayAfterLast(date: T): boolean
isFirst(date: T): boolean
isLast(date: T): boolean
isMarked(date: T): boolean
isBetween(date: T): boolean;
isSelected(date: T): boolean;
isDisabled(date: T): boolean;
isOneDayAfter(date: T): boolean;
isOneDayBefore(date: T): boolean;
isOneDayBeforeFirst(date: T): boolean;
isOneDayAfterFirst(date: T): boolean;
isOneDayBeforeLast(date: T): boolean;
isOneDayAfterLast(date: T): boolean;
isFirst(date: T): boolean;
isLast(date: T): boolean;
isMarked(date: T): boolean;
}
type Props = {
startDate: Date | string,
viewMode: VIEW_MODES
customNumberOfMonths: number
mode: MODES
locale: string | object
minDate: DateFormat
maxDate: DateFormat
preventOutOfRange: boolean
captureThirdDate: boolean
dateSelectStrategy: Function
defaultSelectedDates: Array<DateFormat>
captureHover: boolean
disabledDates: Array<DateFormat>
markedDates: Array<DateFormat>
firstDayOfWeek: number
}
startDate: Date | string;
viewMode: VIEW_MODES;
customNumberOfMonths: number;
mode: MODES;
locale: string | object;
minDate: DateFormat;
maxDate: DateFormat;
preventOutOfRange: boolean;
captureThirdDate: boolean;
dateSelectStrategy: Function;
defaultSelectedDates: Array<DateFormat>;
captureHover: boolean;
disabledDates: Array<DateFormat>;
markedDates: Array<DateFormat>;
firstDayOfWeek: number;
};
type Data = {
calendar: Array<Calendar>,
selectedDates: Array<CalendarDate>,
currentMonth: number | null,
currentYear: number | null,
currentHoveredDate: DateFormat | null,
viewState: Array<any>
}
calendar: Array<Calendar>;
selectedDates: Array<CalendarDate>;
currentMonth: number | null;
currentYear: number | null;
currentHoveredDate: DateFormat | null;
viewState: Array<any>;
};
type Computed = {
localeStrings: string
weekDayNames: string[]
monthNames: Month[]
monthsList: Month[]
canGoToPrevMonth: boolean
canGoToNextMonth: boolean
}
localeStrings: string;
weekDayNames: string[];
monthNames: Month[];
monthsList: Month[];
canGoToPrevMonth: boolean;
canGoToNextMonth: boolean;
};
type Methods = {
onDateSelect(date: CalendarDate): void
onDateMouseOver(date: CalendarDate): void
onDateMouseOut(): void
setDates(dates: Array<DateFormat>): void
resetDates(index: number): void
prevPage(): void
nextPage(): void
onDateSelect(date: CalendarDate): void;
onDateMouseOver(date: CalendarDate): void;
onDateMouseOut(): void;
setDates(dates: Array<DateFormat>): void;
resetDates(index: number): void;
prevPage(): void;
nextPage(): void;
/**
*
*
* @param year The year as number

@@ -122,5 +131,5 @@ * @param month The month index starting from 0

*/
shouldPreventMonthChange(year: number, month: number, step: number): boolean
shouldPreventMonthChange(year: number, month: number, step: number): boolean;
/** */
setMonth(monthListItem: MonthYear): void
setMonth(monthListItem: MonthYear): void;
/**

@@ -130,19 +139,25 @@ * Check if a date is between the current date selection

*/
isBetween(date: CalendarDate): boolean
isBetween(date: CalendarDate): boolean;
/** Return if the given date is currently selected */
isSelected(date: CalendarDate): boolean
isSelected(date: CalendarDate): boolean;
/** Return if the given date is currently disabled */
isDisabled(date: CalendarDate): boolean
isOneDayAfter(date: CalendarDate): boolean
isOneDayBefore(date: CalendarDate): boolean
isOneDayBeforeFirst(date: CalendarDate): boolean
isOneDayAfterFirst(date: CalendarDate): boolean
isOneDayBeforeLast(date: CalendarDate): boolean
isOneDayAfterLast(date: CalendarDate): boolean
isFirst(date: CalendarDate): boolean
isLast(date: CalendarDate): boolean
isMarked(date: CalendarDate): boolean
getModifiers(date: CalendarDate): Modifiers<CalendarDate>
}
isDisabled(date: CalendarDate): boolean;
isOneDayAfter(date: CalendarDate): boolean;
isOneDayBefore(date: CalendarDate): boolean;
isOneDayBeforeFirst(date: CalendarDate): boolean;
isOneDayAfterFirst(date: CalendarDate): boolean;
isOneDayBeforeLast(date: CalendarDate): boolean;
isOneDayAfterLast(date: CalendarDate): boolean;
isFirst(date: CalendarDate): boolean;
isLast(date: CalendarDate): boolean;
isMarked(date: CalendarDate): boolean;
getModifiers(date: CalendarDate): Modifiers<CalendarDate>;
};
export const RenderlessCalendar: CombinedVueInstance<Vue, Data, Methods, Computed, Props> & { name: string }
export const RenderlessCalendar: CombinedVueInstance<
Vue,
Data,
Methods,
Computed,
Props
> & { name: string };
export function prependZero(number) {
if (number < 10) return '0' + number;
if (number < 10) return `0${number}`;
return number;
}
import { MODE_RANGE, MODE_SINGLE } from './constants';
import { singleDateStrategy } from '../date-select-strategies/single-date-strategy';
import { onThirdClickResetStrategy } from '../date-select-strategies/on-third-click-reset-strategy';
import { rangeDateStrategy } from '../date-select-strategies/range-date-strategy';

@@ -6,0 +5,0 @@ export function getDateSelectStrategy(mode) {

@@ -16,4 +16,4 @@ import { DAYS_IN_WEEK } from './constants';

export function getCalendarStringsForLocale(locale, firstDayOfWeek) {
if (!(/^[a-z]{2,3}(-[A-Za-z]{2})?$/).test(locale)) {
locale = navigator.language;
if (!/^[a-z]{2,3}(-[A-Za-z]{2})?$/.test(locale)) {
locale = typeof navigator === 'object' ? navigator.language : 'en';
}

@@ -39,20 +39,24 @@ if (!CALENDAR_STRINGS.hasOwnProperty(locale)) {

const months = Array(12).fill().map((_, i) => {
const d = new Date(year, i);
return {
short: d.toLocaleString(locale, { month: 'short' }),
full: d.toLocaleString(locale, { month: 'long' })
};
});
const months = Array(12)
.fill()
.map((_, i) => {
const d = new Date(year, i);
return {
short: d.toLocaleString(locale, { month: 'short' }),
full: d.toLocaleString(locale, { month: 'long' }),
};
});
// 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);
return {
short: d.toLocaleString(locale, { weekday: 'short' }),
full: d.toLocaleString(locale, { weekday: 'long' })
};
});
const days = Array(7)
.fill()
.map((_, i) => {
const d = new Date(year, month, firstMondayDate + i);
return {
short: d.toLocaleString(locale, { weekday: 'short' }),
full: d.toLocaleString(locale, { weekday: 'long' }),
};
});
return { months, days };
}
import {
MAX_DAYS_IN_MONTH, MONTH_INDEX_CORRECTION,
MAX_DAYS_IN_MONTH,
MONTH_INDEX_CORRECTION,
VIEW_MODE_DOUBLE,
VIEW_MODE_SINGLE,
VIEW_MODE_CUSTOM,
ZERO_BASED_DAYS_IN_WEEK
ZERO_BASED_DAYS_IN_WEEK,
} from './constants';

@@ -13,3 +14,3 @@ import {

isLessThan,
isSameMonth
isSameMonth,
} from './renderless-date.service';

@@ -20,3 +21,3 @@ import CalendarDate from '../classes/CalendarDate';

[VIEW_MODE_SINGLE]: 1,
[VIEW_MODE_DOUBLE]: 2
[VIEW_MODE_DOUBLE]: 2,
};

@@ -29,7 +30,6 @@

year,
firstDayOfWeek
firstDayOfWeek,
}) {
const months = viewMode === VIEW_MODE_CUSTOM
? numberOfMonths
: monthsEnum[viewMode];
const months =
viewMode === VIEW_MODE_CUSTOM ? numberOfMonths : monthsEnum[viewMode];

@@ -48,4 +48,10 @@ const result = [];

const currentMonthDates = getCurrentMonthDates(year, month, firstDayOfWeek);
const prevMonthDates = getPrevMonthDates(currentMonthDates[0], firstDayOfWeek);
const nextMonthDates = getNextMonthDates(currentMonthDates[currentMonthDates.length - 1], firstDayOfWeek);
const prevMonthDates = getPrevMonthDates(
currentMonthDates[0],
firstDayOfWeek
);
const nextMonthDates = getNextMonthDates(
currentMonthDates[currentMonthDates.length - 1],
firstDayOfWeek
);

@@ -55,3 +61,3 @@ result.push({

month,
year
year,
});

@@ -67,5 +73,6 @@

export function getPrevMonthDates(date, firstDayOfWeek = 1) {
return _getMonthLastNDays(date.dayOfWeek, date.year, date.month, { firstDayOfWeek });
return _getMonthLastNDays(date.dayOfWeek, date.year, date.month, {
firstDayOfWeek,
});
}

@@ -85,3 +92,5 @@

const numberOfDays = ZERO_BASED_DAYS_IN_WEEK - date.dayOfWeek;
return _getMonthFirstNDays(numberOfDays, date.year, date.month, { firstDayOfWeek });
return _getMonthFirstNDays(numberOfDays, date.year, date.month, {
firstDayOfWeek,
});
}

@@ -96,3 +105,6 @@

while (dates.length < n) {
const date = new CalendarDate(year, prevMonthNumber, dayNumber, { isOtherMonthDay: true, firstDayOfWeek });
const date = new CalendarDate(year, prevMonthNumber, dayNumber, {
isOtherMonthDay: true,
firstDayOfWeek,
});

@@ -114,3 +126,6 @@ if (!isSameMonth(month, date.month)) {

for (let dayNumber = 1; dayNumber <= n; dayNumber++) {
const date = new CalendarDate(year, nextMonthNumber, dayNumber, { isOtherMonthDay: true, firstDayOfWeek });
const date = new CalendarDate(year, nextMonthNumber, dayNumber, {
isOtherMonthDay: true,
firstDayOfWeek,
});
dates.push(date);

@@ -123,5 +138,8 @@ }

export function shouldPreventMonthChange({
currentYear, currentMonth, minDate, maxDate, step
currentYear,
currentMonth,
minDate,
maxDate,
step,
}) {
return step === 1

@@ -139,3 +157,5 @@ ? breaksUpperLimit(maxDate, currentYear, currentMonth)

return isEqual(minDateYear, currentYear) && isGreaterThan(minDateMonth, prevMonth);
return (
isEqual(minDateYear, currentYear) && isGreaterThan(minDateMonth, prevMonth)
);
}

@@ -150,12 +170,11 @@

return isEqual(maxDateYear, currentYear) && isLessThan(maxDateMonth, nextMonth);
return (
isEqual(maxDateYear, currentYear) && isLessThan(maxDateMonth, nextMonth)
);
}
export function resetDate(dates, index) {
return Number.isNaN(index)
? []
: dates.filter((_, idx) => idx !== index);
return Number.isNaN(index) ? [] : dates.filter((_, idx) => idx !== index);
}
export function getMonthsList({

@@ -165,3 +184,3 @@ currentMonth,

monthNames,
viewState
viewState,
}) {

@@ -183,3 +202,3 @@ const startIndex = currentMonth;

month,
year
year,
});

@@ -186,0 +205,0 @@ }

import test from 'ava';
import * as renderlessCalendarService from './renderless-calendar.service';
test('shouldPreventMonthChange', t => {

@@ -11,3 +10,3 @@ let result = renderlessCalendarService.shouldPreventMonthChange({

minDate: '2019-02-01',
step: 1
step: 1,
});

@@ -22,3 +21,3 @@

minDate: '2019-07-01',
step: -1
step: -1,
});

@@ -33,3 +32,3 @@

minDate: '2019-02-01',
step: -1
step: -1,
});

@@ -36,0 +35,0 @@

@@ -12,3 +12,2 @@ import { MILLISECONDS_IN_DAY, SATURDAY, SUNDAY } from './constants';

export function isSelected(date, selectedDates) {

@@ -18,3 +17,2 @@ return selectedDates.some(selectedDate => isEqual(selectedDate, date));

export function isDisabled(date, disabledDates) {

@@ -24,12 +22,12 @@ return disabledDates.indexOf(date) !== -1;

export function isToday(date) {
const today = new Date();
return today.getDate() === date.getDate()
&& today.getMonth() === date.getMonth()
&& today.getFullYear() === date.getFullYear();
return (
today.getDate() === date.getDate() &&
today.getMonth() === date.getMonth() &&
today.getFullYear() === date.getFullYear()
);
}
export function isWeekend(date) {

@@ -79,10 +77,11 @@ const day = date.getDay();

export function isRestricted(date, {
disabledDates = [],
maxDate = '',
minDate = ''
}) {
return (minDate && isLessThan(date, minDate))
|| (maxDate && isGreaterThan(date, maxDate))
|| (isDisabled(date, disabledDates));
export function isRestricted(
date,
{ disabledDates = [], maxDate = '', minDate = '' }
) {
return (
(minDate && isLessThan(date, minDate)) ||
(maxDate && isGreaterThan(date, maxDate)) ||
isDisabled(date, disabledDates)
);
}

@@ -12,3 +12,2 @@ import test from 'ava';

test('isWeekend', t => {

@@ -27,3 +26,2 @@ let weekendsCounter = 0;

test('isLessThan', t => {

@@ -38,3 +36,2 @@ const date1 = '2019-05-04';

test('isGreaterThan', t => {

@@ -49,3 +46,2 @@ const date1 = '2019-05-04';

test('isDisabled', t => {

@@ -58,3 +54,2 @@ const disabledDates = ['2019-05-13', '2019-05-20', '2019-06-13'];

test('isSelected', t => {

@@ -67,3 +62,2 @@ const selectedDates = ['2019-04-23'];

test('isEqual', t => {

@@ -74,3 +68,2 @@ t.is(renderlessDateService.isEqual('2019-04-23', '2019-04-23'), true);

test('fromFormatted', t => {

@@ -83,3 +76,2 @@ const formatted = '2019-4-12';

test('isMarked', t => {

@@ -95,3 +87,2 @@ const markedDates = ['2019-04-10', '2019-04-12', '2019-05-21'];

test('getMonthDateSafely', t => {
const date = renderlessDateService.getMonthDateSafely(2019, 0);

@@ -121,6 +112,22 @@ const date2 = renderlessDateService.getMonthDateSafely(2019, -1);

const test1 = renderlessDateService.isRestricted('2019-06-01', { disabledDates, minDate, maxDate });
const test2 = renderlessDateService.isRestricted('2019-06-20', { disabledDates, minDate, maxDate });
const test3 = renderlessDateService.isRestricted('2019-05-20', { disabledDates, minDate, maxDate });
const test4 = renderlessDateService.isRestricted('2019-07-01', { disabledDates, minDate, maxDate });
const test1 = renderlessDateService.isRestricted('2019-06-01', {
disabledDates,
minDate,
maxDate,
});
const test2 = renderlessDateService.isRestricted('2019-06-20', {
disabledDates,
minDate,
maxDate,
});
const test3 = renderlessDateService.isRestricted('2019-05-20', {
disabledDates,
minDate,
maxDate,
});
const test4 = renderlessDateService.isRestricted('2019-07-01', {
disabledDates,
minDate,
maxDate,
});

@@ -139,7 +146,22 @@ t.is(test1, false);

const test1 = renderlessDateService.isRestricted('2019-06-01', { disabledDates, maxDate });
const test2 = renderlessDateService.isRestricted('2019-06-20', { disabledDates, maxDate });
const test3 = renderlessDateService.isRestricted('2019-05-20', { disabledDates, maxDate });
const test4 = renderlessDateService.isRestricted('2019-07-01', { disabledDates, minDate });
const test5 = renderlessDateService.isRestricted('2019-06-20', { disabledDates: emptyDisabledDates, maxDate });
const test1 = renderlessDateService.isRestricted('2019-06-01', {
disabledDates,
maxDate,
});
const test2 = renderlessDateService.isRestricted('2019-06-20', {
disabledDates,
maxDate,
});
const test3 = renderlessDateService.isRestricted('2019-05-20', {
disabledDates,
maxDate,
});
const test4 = renderlessDateService.isRestricted('2019-07-01', {
disabledDates,
minDate,
});
const test5 = renderlessDateService.isRestricted('2019-06-20', {
disabledDates: emptyDisabledDates,
maxDate,
});

@@ -146,0 +168,0 @@ t.is(test1, false);

@@ -1,2 +0,6 @@

import { VIEW_MODE_DOUBLE, VIEW_MODE_SINGLE, VIEW_MODE_CUSTOM } from './constants';
import {
VIEW_MODE_DOUBLE,
VIEW_MODE_SINGLE,
VIEW_MODE_CUSTOM,
} from './constants';
import { getMonthDateSafely } from './renderless-date.service';

@@ -7,3 +11,3 @@

[VIEW_MODE_DOUBLE]: initializeDoubleViewMode,
[VIEW_MODE_CUSTOM]: initializeCustomViewMode
[VIEW_MODE_CUSTOM]: initializeCustomViewMode,
};

@@ -15,3 +19,2 @@

function initializeSingleViewMode() {

@@ -25,3 +28,2 @@ const today = new Date();

function initializeDoubleViewMode() {

@@ -32,3 +34,6 @@ const today = new Date();

const nextMonthDate = getMonthDateSafely(today.getFullYear(), today.getMonth() + 1);
const nextMonthDate = getMonthDateSafely(
today.getFullYear(),
today.getMonth() + 1
);
const nextMonthYear = nextMonthDate.getFullYear();

@@ -39,3 +44,3 @@ const nextMonthNumber = nextMonthDate.getMonth();

{ year: currentYear, month: currentMonth },
{ year: nextMonthYear, month: nextMonthNumber }
{ year: nextMonthYear, month: nextMonthNumber },
];

@@ -55,3 +60,3 @@ }

year: date.getFullYear(),
month: date.getMonth()
month: date.getMonth(),
});

@@ -66,8 +71,8 @@ }

prevPage: () => {},
nextPage: () => {}
nextPage: () => {},
},
[VIEW_MODE_DOUBLE]: {
prevPage: () => {},
nextPage: () => {}
}
nextPage: () => {},
},
};

@@ -78,5 +83,1 @@

}
{
"name": "vue-renderless-calendar",
"version": "2.3.0",
"version": "2.4.0",
"main": "./dist/index.js",

@@ -25,16 +25,32 @@ "module": "./dist/index.js",

"scripts": {
"prepare": "husky install",
"build": "NODE_ENV=production rollup -c",
"build:example": "parcel build example/index.html --out-dir dist-example",
"watch": "rollup -c -w",
"dev": "rollup -c",
"dev:example": "parcel example/index.html --out-dir dist-example --open",
"test:watch": "ava --watch",
"test": "ava",
"prepare": "npm test && npm run build"
"lint": "eslint ./lib",
"lint:fix": "eslint ./lib --fix",
"format:check": "prettier --check .",
"format": "prettier --write .",
"prepublishOnly": "npm test && npm run build",
"build:examples": "TARGET=examples rollup -c"
},
"dependencies": {
"vue-demi": "^0.13.1"
},
"peerDependencies": {
"@vue/composition-api": "^1.0.0-rc.1",
"vue": "^2.0.0 || >=3.0.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
}
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@vue/component-compiler-utils": "^3.0.0",
"autoprefixer": "^9.6.0",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"ava": "^1.4.1",

@@ -46,7 +62,8 @@ "babel-eslint": "^10.0.1",

"eslint-config-chocotravel-aviata": "^1.0.7",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-vue": "^5.2.2",
"esm": "^3.2.25",
"node-sass": "^4.13.1",
"parcel-bundler": "^1.12.4",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "2.7.1",
"rollup": "^1.15.1",

@@ -57,25 +74,5 @@ "rollup-plugin-babel": "^4.3.2",

"rollup-plugin-terser": "^5.2.0",
"sass-loader": "^7.1.0",
"vue": "^2.6.10",
"vue-hot-reload-api": "^2.3.3",
"vue-template-compiler": "^2.6.10"
"sass": "^1.53.0",
"vue": "^3.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"chocotravel-aviata"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [

@@ -82,0 +79,0 @@ "> 1%",

# vue-renderless-calendar 📆
![default workflow](https://github.com/winexy/vue-renderless-calendar/actions/workflows/default.yml/badge.svg)
![npm version](https://badgen.net/npm/v/vue-renderless-calendar)
> Zero dependency Vue renderless calendar with scoped-slots API

@@ -18,49 +21,49 @@

| Prop | Required | Type | Default | Description
|----------------------|-------------|-----------------------|---------------------|----------------------------------
| viewMode | false | String | | 'single', 'double', 'infinite'
| mode | false | String | | 'single', 'range'
| locale | false | Object or String | navigator.language | Locale string (e.g. 'ru'), it will automatically generate locale object using `Date.prototype.toLocaleString`, otherwise you can provide this object manually
| minDate | false | String | '' | Minimal valid date (`YYYY-MM-DDD`)
| maxDate | false | String | '' | Maximal valid date (`YYYY-MM-DDD`)
| preventOutOfRange | false | Boolean | true | Prevent user go out of valid dates range
| dateSelectStrategy | false | Function | null | If you want custom behaviour for handling date select, you can implement this function
| defaultSelectedDates | false | Array | [] | Array of date strings with `YYYY-MM-DDD` format
| captureHover | false | Boolean | true | `captureHover` prop is used for computing dates which are between selected date and current hovered date
| captureThirdDate | false | Boolean | false | `captureThirdDate` prop is used for capturing dates between in case when 2 dates already selected and you have third element hovered
| disabledDates | false | Array<String> | [] | Array of `YYYY-MM-DDD` strings containing dates that can't be selected |
| 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 |
| Prop | Required | Type | Default | Description |
| -------------------- | -------- | ---------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| viewMode | false | String | | 'single', 'double', 'infinite' |
| mode | false | String | | 'single', 'range' |
| locale | false | Object or String | navigator.language | Locale string (e.g. 'ru'), it will automatically generate locale object using `Date.prototype.toLocaleString`, otherwise you can provide this object manually |
| minDate | false | String | '' | Minimal valid date (`YYYY-MM-DDD`) |
| maxDate | false | String | '' | Maximal valid date (`YYYY-MM-DDD`) |
| preventOutOfRange | false | Boolean | true | Prevent user go out of valid dates range |
| dateSelectStrategy | false | Function | null | If you want custom behaviour for handling date select, you can implement this function |
| defaultSelectedDates | false | Array | [] | Array of date strings with `YYYY-MM-DDD` format |
| captureHover | false | Boolean | true | `captureHover` prop is used for computing dates which are between selected date and current hovered date |
| captureThirdDate | false | Boolean | false | `captureThirdDate` prop is used for capturing dates between in case when 2 dates already selected and you have third element hovered |
| disabledDates | false | Array<String> | [] | Array of `YYYY-MM-DDD` strings containing dates that can't be selected |
| 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 |
### Scoped-slots properties
| Property | Type | Description |
|-------------------|-----------------------|---------------|
| weekDayNames | Array | List of week days with short and full titles from `locale` object |
| monthNames | Array | List of months with short and full titles from `locale` object |
| monthsList | Array | List of months which can be used for rendering months with possibility for changing current month view of calendar using `setMonth` method |
| calendar | Array | Array of months with `month`, `year` number and array of `dates` |
| selectedDates | Array\<CalendarDate\> | Array of current selected dates|
| currentMonth | Number | |
| currentYear | Number | |
| canGoToPrevMonth | Boolean | |
| canGoToNextMonth | Boolean | |
| Property | Type | Description |
| ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| weekDayNames | Array | List of week days with short and full titles from `locale` object |
| monthNames | Array | List of months with short and full titles from `locale` object |
| monthsList | Array | List of months which can be used for rendering months with possibility for changing current month view of calendar using `setMonth` method |
| calendar | Array | Array of months with `month`, `year` number and array of `dates` |
| selectedDates | Array\<CalendarDate\> | Array of current selected dates |
| currentMonth | Number | |
| currentYear | Number | |
| canGoToPrevMonth | Boolean | |
| canGoToNextMonth | Boolean | |
### Scoped-slots Methods
| Property | Arguments | Description |
|-------------------|---------------|-------------|
| prevPage | - | Go to previous view iteration |
| nextPage | - | Go to next view iteration |
| resetDates | - | Set `selectedDates` to [] |
| setMonth | monthListItem | Update views current active month |
| onDateMouseOut | - | Reset current hovered date |
| onDateMouseOver | CalendarDate | Set current hovered date |
| onDateSelect | CalendarDate | Append selected date to `selectedDates` array using "date select strategy" |
| getModifiers | CalendarDate | Returns |
| Property | Arguments | Description |
| --------------- | ------------- | -------------------------------------------------------------------------- |
| prevPage | - | Go to previous view iteration |
| nextPage | - | Go to next view iteration |
| resetDates | - | Set `selectedDates` to [] |
| setMonth | monthListItem | Update views current active month |
| onDateMouseOut | - | Reset current hovered date |
| onDateMouseOver | CalendarDate | Set current hovered date |
| onDateSelect | CalendarDate | Append selected date to `selectedDates` array using "date select strategy" |
| getModifiers | CalendarDate | Returns |
### Events
| Event name | Payload |
|--------------|-----------------------|
| ------------ | --------------------- |
| onDateChange | Array\<CalendarDate\> |

@@ -72,18 +75,17 @@

| Property | Type | Description
|----------------------|----------|---------------
| isSelected | Boolean |
| isBetween | Boolean |
| isDisabled | Boolean |
| isMarked | Boolean |
| isFirst | Boolean | is first selected date
| isLast | Boolean | is last selected date
| isOneDayAfter | Boolean | is one day after selected date
| isOneDayBefore | Boolean | is one date before selected date
| isOneDayBeforeFirst | Boolean |
| isOneDayAfterFirst | Boolean |
| isOneDayBeforeLast | Boolean |
| isOneDayAfterLast | Boolean |
| Property | Type | Description |
| ------------------- | ------- | -------------------------------- |
| isSelected | Boolean |
| isBetween | Boolean |
| isDisabled | Boolean |
| isMarked | Boolean |
| isFirst | Boolean | is first selected date |
| isLast | Boolean | is last selected date |
| isOneDayAfter | Boolean | is one day after selected date |
| isOneDayBefore | Boolean | is one date before selected date |
| isOneDayBeforeFirst | Boolean |
| isOneDayAfterFirst | Boolean |
| isOneDayBeforeLast | Boolean |
| isOneDayAfterLast | Boolean |
## CalendarDate

@@ -95,11 +97,11 @@

| Property | Type | Description |
|-------------------|---------|-------------|
| year | Number | |
| month | Number | 0-11 |
| day | Number | 1-31 |
| actualMonthNumber | Number | Number of month with index correction |
| formatted | String | YYYY-MM-DD |
| isWeekend | Boolean | |
| isToday | Boolean | |
| Property | Type | Description |
| ----------------- | ------- | ------------------------------------------------------------------------------------ |
| year | Number | |
| month | Number | 0-11 |
| day | Number | 1-31 |
| actualMonthNumber | Number | Number of month with index correction |
| formatted | String | YYYY-MM-DD |
| isWeekend | Boolean | |
| isToday | Boolean | |
| isOtherMonthDay | Boolean | This field can be used to find out that this is the date from previous or next month |

@@ -6,4 +6,7 @@ import { terser } from 'rollup-plugin-terser';

import path from 'path';
import pkg from './package.json';
const production = process.env.NODE_ENV === 'production';
const isProductionBuild = process.env.NODE_ENV === 'production';
const isBuildForExamples = process.env.TARGET === 'examples';
const { log } = console;

@@ -13,43 +16,56 @@ const localesList = fs.readdirSync(path.join(__dirname, 'lib', 'locale'));

function createOutputAssets({ dir }) {
return [
{
sourcemap: !isProductionBuild,
format: 'es',
dir,
entryFileNames: '[name].es.js',
},
{
sourcemap: !isProductionBuild,
format: 'cjs',
dir,
},
];
}
function createExampleOutputs() {
const examples = fs
.readdirSync(path.join(__dirname, 'examples'))
.filter(example => example !== 'README.md');
log('Create example outputs', examples);
return examples.flatMap(example => {
const exampleDir = path.join('examples', example, 'dist');
log('Example dir', exampleDir);
return createOutputAssets({ dir: exampleDir });
});
}
function createLocaleConfig(locale) {
return {
input: path.join('lib', 'locale', locale),
output: [
{
format: 'es',
dir: 'dist/locale',
entryFileNames: '[name].es.js'
},
{
format: 'cjs',
dir: 'dist/locale'
}
],
plugins: [
buble(),
production && terser()
]
output: isBuildForExamples
? createExampleOutputs()
: createOutputAssets({ dir: path.join('dist', 'locale') }),
plugins: [buble(), isProductionBuild && terser()],
};
}
export default [{
input: path.join('lib', 'index.js'),
output: [
{
sourcemap: !production,
format: 'es',
dir: 'dist',
entryFileNames: '[name].es.js'
},
{
sourcemap: !production,
format: 'cjs',
dir: 'dist'
}
],
plugins: [
buble(),
!production && sourcemaps(),
production && terser()
]
}, ...locales];
export default [
{
input: path.join('lib', 'index.js'),
external: Object.keys(pkg.dependencies),
output: isBuildForExamples
? createExampleOutputs()
: createOutputAssets({ dir: 'dist' }),
plugins: [
buble(),
!isProductionBuild && sourcemaps(),
isProductionBuild && terser(),
],
},
...locales,
];
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc