Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rehookify/datepicker

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rehookify/datepicker - npm Package Compare versions

Comparing version 6.6.0 to 6.6.1

2

dist/index.cjs.js

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

"use strict";var e=require("react");const t=(e,t,...a)=>e&&null!=t?new Date(e,t,...a):new Date,a=e=>({D:e.getDate(),M:e.getMonth(),Y:e.getFullYear()}),s=e=>e.getDay(),o=e=>t(a(e).Y,a(e).M,a(e).D),n=e=>t(a(e).Y,a(e).M+1,0).getDate(),r=(e,s,o)=>{const{Y:r,M:c,D:l}=a(e),d="date"===o?l+s:"month"===o&&l>n(t(r,c+s,1))?n(t(r,c+s,1)):l;return t(r+("year"===o?s:0),c+("month"===o?s:0),d)},c=(e,t,a)=>r(e,0-t,a),l=(e,t)=>+e-+t,d=(e,t,a)=>e.toLocaleDateString(t,a),i=(e,{locale:t,monthName:a})=>d(e,t,{month:a}),u=(e,a,s,o)=>o&&null!=o.h&&null!=o.m?t(e,a,s,o.h,o.m):void 0,f=(e,{locale:t,hour:a,minute:s,second:o,hour12:n})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:o,hour12:n}),m=e=>`${e<10?0:""}${e}`,D=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${m(e%12||12)}:${m(t)} ${a}`})(a,s):`${m(a)}:${m(s)}`},g=(e,t)=>e.concat(t).sort(l),x=(e,t,a)=>{let[s,o]=[e,t];return e&&t&&([s,o]=[e,t].sort(a)),[s,o]},p=(e,{day:t,date:s}={})=>((e,t)=>!!t&&t.includes(e))(e.getDay(),t)||((e,t=[])=>{const{M:s,D:o}=a(e);return t.some((e=>{const{M:t,D:n}=a(e);return s===t&&o===n}))})(e,s);function h(e,t){return(s(e)+7-t)%7}const y=(e,t)=>+e==+t,C=(e,t)=>e<t,b=(e,t)=>e>t,k=(e,t,a)=>b(t,e)&&C(t,a)||C(t,e)&&b(t,a),Y=(e,t)=>!!e&&b(t,e),M=(e,t)=>!!e&&C(t,e),v=(e,t)=>e.some((e=>y(o(e),o(t)))),P=(e,t)=>!!t&&e<a(t).M,E=(e,t)=>!!t&&e<a(t).Y,T=(e,t)=>!!t&&e>a(t).M,$=(e,t)=>!!t&&e>a(t).Y;var w={mode:"static",offsets:[0],startDay:0},O={mode:"decade",numberOfYears:12,step:10},G={mode:"single",toggle:!1,selectSameDate:!1},S={interval:30,useLocales:!1},A={locale:"en-GB",day:"2-digit",year:"numeric",weekday:"short",monthName:"long",hour:"2-digit",minute:"2-digit",hour12:void 0,second:void 0};function B(e){return"range"===e}const _="range-start",I="range-end",F="will-be-range-start",L="will-be-range-end",N=(e,t,a,s)=>{if(!B(s)||0===a.length)return"";const[n,r]=a;return n&&r?y(e,o(n))?y(o(n),o(r))?`${_} ${I}`:_:y(e,o(r))?I:k(o(n),e,o(r))?"in-range":"":!r&&t?k(o(n),e,t)?"will-be-in-range":C(t,o(n))?y(e,t)?F:y(e,o(n))?L:"":y(e,o(n))?F:y(e,t)?L:"":""},R=(e,s,r,{rangeEnd:c},l)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:x}=l,{locale:C,day:b,year:k}=D,{M:P,Y:E}=a(s),{start:T,length:$}=function(e,a,{mode:s,startDay:o}){const r=t(a,e,1),c=n(r),l=h(r,o);return{start:l,length:"static"===s?42:l+c+6-h(t(a,e,c),o)}}(P,E,g),w=Array($).fill(0).map(((s,n)=>{const l=t(E,P,n+1-T);return{$date:l,active:y(e,l),day:d(l,C,{day:b}),now:y(o(t()),l),range:N(l,c,r,u),disabled:M(f,l)||Y(m,l)||p(l,x),selected:v(r,l),inCurrentMonth:a(l).M===P}}));return{year:d(s,C,{year:k}),month:i(s,D),days:w}};var q=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>d(e[s].$date,t,{weekday:a})));const H=t=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((o=>R(s,r(s,o,"month"),e,t,a))))(t);return e.useMemo((()=>({calendars:a,weekDays:q(a[0],t.config)})),[a,t.config])},U=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),j=e=>(t,a)=>e(a),z=e=>(...t)=>{e()},J=(e,t,a={},s=!1)=>({role:"button",tabIndex:0,...e?{disabled:!0,"aria-disabled":!0}:{onClick(e){t(e)}},...s?{"aria-selected":!0}:{},...a});var K="SET_FOCUS_DATE",Q="SET_OFFSET_DATE",V="SET_RANGE_END",W="SET_YEAR",X=(e,t)=>{switch(t.type){case K:return{...e,focusDate:t.date};case Q:return{...e,offsetDate:t.date};case V:return{...e,rangeEnd:t.date};case W:return{...e,offsetYear:t.year};default:return e}},Z=(e,t)=>{e({type:K,date:t})},ee=(e,t)=>{e({type:V,date:t})},te=(e,t)=>{e({type:W,year:t})};const ae=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||((e,t)=>{e({type:Q,date:t})})(e,s),t&&t(s)},se=(e,{days:t,months:a,years:s})=>{let o=e;return t&&0!==t&&(o=r(o,t,"date")),a&&0!==a&&(o=r(o,a,"month")),s&&0!==s&&(o=r(o,s,"year")),o},oe=(e,{days:t=0,months:a=0,years:s=0},o)=>o?y(e,o)?e:0!==t?ne(e,o,t,"date"):0!==a?ne(e,o,a,"month"):0!==s?ne(e,o,s,"year"):e:e,ne=(e,t,a,s)=>{const o=r(e,a,s);if(a>0){return Y(t,o)?c(t,a,s):e}return M(t,o)?c(t,a,s):e},re=t=>{const{config:{dates:a}}=t,{minDate:s,maxDate:o}=a,n=e.useCallback(((e,{disabled:a,onClick:s,...n}={})=>{const r=oe(t.offsetDate,e,o),c=se(r,e),l=!!a||Y(o,c);return J(l,(e=>U(s,j(ae(t)))(e,c)),n)}),[o,t]),r=e.useCallback((({days:e=0,months:a=0,years:o=0},{disabled:n,onClick:r,...c}={})=>{const l={days:-e,months:-a,years:-o},d=oe(t.offsetDate,l,s),i=se(d,l),u=!!n||M(s,i);return J(u,(e=>U(r,j(ae(t)))(e,i)),c)}),[s,t]);return{addOffset:n,setOffset:e.useCallback(((e,{disabled:a,onClick:n,...r}={})=>{const c=!!a||M(s,e)||Y(o,e);return J(c,(a=>U(n,j(ae(t)))(a,e)),r)}),[t,o,s]),subtractOffset:r}},ce=e=>"exact"===e,le=(e,{mode:t,numberOfYears:a})=>ce(t)?((e,t)=>e-t+1)(e,a):"decade"===t?(e=>e-e%10-1)(e):((e,t)=>e-(t/2-(t%2==0?1:0)))(e,a),de=e=>{const{selectedDates:s,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:l},years:d}=e,i=n||(s.length>0?s[s.length-1]:((e,t,a)=>Y(t,a)?t:M(e,a)?e:a)(c,l,o(t())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:le(a(i).Y,d)}},ie=t=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:n,calendar:r={},dates:c={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...g}=c,{offsets:p=[],...h}=r,{minTime:y,maxTime:C,...b}=i,[k,Y]=x(m,D,l),[M,P]=x(y,C,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:n,focusDate:a&&v(e,a)?a:void 0,calendar:{...w,...h,offsets:w.offsets.concat(p)},years:{...O,...f},dates:{...G,...g,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...A,...d},time:{...S,minTime:M,maxTime:P,...b},exclude:u}}(t),[s,n]=e.useReducer(X,de(a));return{dispatch:n,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},ue=({selectedDates:t,config:{locale:a}})=>e.useMemo((()=>({selectedDates:t,formattedDates:t.map((e=>((e,{locale:t,options:a})=>d(e,t,a))(e,a)))})),[t,a]),fe=({config:t,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:l}}=t;return{dayButton:e.useCallback((({$date:e,selected:d,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>J(i||!!m,(i=>{(!d||c||(a.forEach((t=>{y(o(t),e)&&Z(s,t)})),B(r)&&l))&&(B(r)&&1===a.length&&ee(s,null),U(f,j((e=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&v(e,t)?e.filter((e=>!y(o(e),t))):"multiple"===a?!n||e.length<n?g(e,t):e:B(a)?2===e.length?[t]:g(e,t):[t])(a,e,t.dates);Z(s,v(r,e)?e:void 0),n(r)})))(i,e))}),{...D,...B(r)&&1===a.length&&{onMouseEnter(){ee(s,e)}},tabIndex:u?0:-1},d)),[r,c,t.dates,n,a,s,l])}};var me=(e,s,o,{minDate:n,maxDate:r})=>{const{M:c,Y:l}=a(e),{Y:d,M:u}=a(t());return Array(12).fill(0).map(((e,f)=>{const m=t(l,f,1);return{$date:m,month:i(m,o),selected:s.some((e=>{const{M:t,Y:s}=a(e);return s===l&&t===f})),active:c===f,now:f===u&&l===d,disabled:P(f,n)||E(l,n)||T(f,r)||$(l,r)}}))};const De=({selectedDates:t,offsetDate:a,config:{locale:s,dates:o}})=>e.useMemo((()=>({months:me(a,t,s,o)})),[o,s,a,t]),ge=t=>({monthButton:e.useCallback((({$date:e,disabled:a,selected:s,active:o},{onClick:n,disabled:r,...c}={})=>J(!!r||a,(a=>U(n,j(ae(t)))(a,e)),{...c,tabIndex:o?0:-1},s)),[t])});var xe=(e,{time:s,locale:o})=>{const n=t(),{interval:r,minTime:c,maxTime:l,useLocales:d}=s,{Y:i,M:m,D:g}=a(e||n),x=1440/r,p=u(i,m,g,c),h=u(i,m,g,l);return Array(x).fill(0).map(((a,s)=>{const c=t(i,m,g,0,s*r);return{$date:c,disabled:!e||M(p,c)||Y(h,c),now:y(c,n),selected:!!e&&y(e,c),time:d?f(c,o):D(c,o)}}))};const pe=({state:{focusDate:t},config:a})=>e.useMemo((()=>({time:xe(t,a)})),[t,a]),he=({selectedDates:t,state:{focusDate:a},config:{onDatesChange:s},dispatch:o})=>({timeButton:e.useCallback((({$date:e,selected:n,disabled:r,now:c},{onClick:l,disabled:d,...i}={})=>J(r||!!d,(r=>{n||U(l,j((e=>{const n=t.map((t=>y(a,t)?e:t));Z(o,e),s(n)})))(r,e)}),{...i,tabIndex:n||c?0:-1},n)),[t,s,o,a])}),ye=(e,s,o,{numberOfYears:n},{minDate:r,maxDate:c})=>{const{Y:l,M:d,D:i}=a(s),{Y:u}=a(t());return Array(n).fill(0).map(((s,n)=>{const f=e+n;return{$date:t(f,d,i),active:l===f,disabled:E(f,r)||$(f,c),now:f===u,selected:o.some((e=>a(e).Y===f)),year:f}}))},Ce=({selectedDates:t,state:{offsetDate:a,offsetYear:s},config:{years:o,dates:n}})=>e.useMemo((()=>({years:ye(s,a,t,o,n)})),[a,s,t,o,n]),be=s=>{const{state:{offsetYear:o,offsetDate:n},config:{dates:r,years:c},dispatch:l}=s,{minDate:d,maxDate:i}=r,{step:u,numberOfYears:f,mode:m}=c,{D:D,M:g}=a(n);return{yearButton:e.useCallback((({$date:e,disabled:t,selected:a,active:o},{onClick:n,disabled:r,...c}={})=>J(!!r||t,(t=>U(n,j(ae(s)))(t,e)),{...c,tabIndex:o?0:-1},a)),[s]),nextYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const n=t(o+f-1,g,D),r=!!a||Y(i,n)||ce(m)&&!!i&&y(i,n);return J(r,(t=>U(e,z((()=>te(l,o+u))))(t)),s)}),[i,l,o,u,D,g,f,m]),previousYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const n=!!a||M(d,t(o,g,D));return J(n,(t=>U(e,z((()=>te(l,o-u))))(t)),s)}),[d,l,o,u,g,D])}},ke=e=>{const t=ie(e);return{data:{...H(t),...ue(t),...De(t),...pe(t),...Ce(t)},propGetters:{...fe(t),...ge(t),...he(t),...be(t),...re(t)}}};var Ye=e.createContext({}),Me=e.createContext({}),ve=()=>e.useContext(Me);exports.DatePickerProvider=({children:t,config:a})=>e.createElement(Ye.Provider,{value:ke(a)},t),exports.DatePickerStateProvider=({children:t,config:a})=>e.createElement(Me.Provider,{value:ie(a)},t),exports.useCalendars=H,exports.useContextCalendars=()=>H(ve()),exports.useContextDatePickerOffsetPropGetters=()=>re(ve()),exports.useContextDays=()=>ue(ve()),exports.useContextDaysPropGetters=()=>fe(ve()),exports.useContextMonths=()=>De(ve()),exports.useContextMonthsPropGetters=()=>ge(ve()),exports.useContextTime=()=>pe(ve()),exports.useContextTimePropGetters=()=>he(ve()),exports.useContextYears=()=>Ce(ve()),exports.useContextYearsPropGetters=()=>be(ve()),exports.useDatePicker=ke,exports.useDatePickerContext=()=>e.useContext(Ye),exports.useDatePickerOffsetPropGetters=re,exports.useDatePickerState=ie,exports.useDatePickerStateContext=ve,exports.useDays=ue,exports.useDaysPropGetters=fe,exports.useMonths=De,exports.useMonthsPropGetters=ge,exports.useTime=pe,exports.useTimePropGetter=he,exports.useYears=Ce,exports.useYearsPropGetters=be;
"use strict";var e=require("react");const t=(e,t,...a)=>e&&null!=t?new Date(e,t,...a):new Date,a=e=>({D:e.getDate(),M:e.getMonth(),Y:e.getFullYear()}),s=e=>e.getDay(),o=e=>t(a(e).Y,a(e).M,a(e).D),n=e=>t(a(e).Y,a(e).M+1,0).getDate(),r=(e,s,o)=>{const{Y:r,M:c,D:l}=a(e),d="date"===o?l+s:"month"===o&&l>n(t(r,c+s,1))?n(t(r,c+s,1)):l;return t(r+("year"===o?s:0),c+("month"===o?s:0),d)},c=(e,t,a)=>r(e,0-t,a),l=(e,t)=>+e-+t,d=(e,t,a)=>e.toLocaleDateString(t,a),i=(e,{locale:t,monthName:a})=>d(e,t,{month:a}),u=(e,a,s,o)=>o&&null!=o.h&&null!=o.m?t(e,a,s,o.h,o.m):void 0,f=(e,{locale:t,hour:a,minute:s,second:o,hour12:n})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:o,hour12:n}),m=e=>`${e<10?0:""}${e}`,D=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${m(e%12||12)}:${m(t)} ${a}`})(a,s):`${m(a)}:${m(s)}`},g=(e,t)=>e.concat(t).sort(l),x=(e,t,a)=>{let[s,o]=[e,t];return e&&t&&([s,o]=[e,t].sort(a)),[s,o]},p=(e,{day:t,date:s}={})=>((e,t)=>!!t&&t.includes(e))(e.getDay(),t)||((e,t=[])=>{const{M:s,D:o}=a(e);return t.some((e=>{const{M:t,D:n}=a(e);return s===t&&o===n}))})(e,s);function h(e,t){return(s(e)+7-t)%7}const y=(e,t)=>+e==+t,C=(e,t)=>e<t,b=(e,t)=>e>t,Y=(e,t,a)=>b(t,e)&&C(t,a)||C(t,e)&&b(t,a),k=(e,t)=>!!e&&b(t,e),M=(e,t)=>!!e&&C(t,e),v=(e,t)=>e.some((e=>y(o(e),o(t)))),P=(e,t)=>!!t&&e<a(t).M,E=(e,t)=>!!t&&e<a(t).Y,T=(e,t)=>!!t&&e>a(t).M,$=(e,t)=>!!t&&e>a(t).Y,w=(e,t)=>!!t&&e>=a(t).Y,O=(e,t)=>!!t&&e<=a(t).Y;var G={mode:"static",offsets:[0],startDay:0},S={mode:"decade",numberOfYears:12,step:10},A={mode:"single",toggle:!1,selectSameDate:!1},B={interval:30,useLocales:!1},_={locale:"en-GB",day:"2-digit",year:"numeric",weekday:"short",monthName:"long",hour:"2-digit",minute:"2-digit",hour12:void 0,second:void 0};function I(e){return"range"===e}const F="range-start",L="range-end",N="will-be-range-start",R="will-be-range-end",q=(e,t,a,s)=>{if(!I(s)||0===a.length)return"";const[n,r]=a;return n&&r?y(e,o(n))?y(o(n),o(r))?`${F} ${L}`:F:y(e,o(r))?L:Y(o(n),e,o(r))?"in-range":"":!r&&t?Y(o(n),e,t)?"will-be-in-range":C(t,o(n))?y(e,t)?N:y(e,o(n))?R:"":y(e,o(n))?N:y(e,t)?R:"":""},H=(e,s,r,{rangeEnd:c},l)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:x}=l,{locale:C,day:b,year:Y}=D,{M:P,Y:E}=a(s),{start:T,length:$}=function(e,a,{mode:s,startDay:o}){const r=t(a,e,1),c=n(r),l=h(r,o);return{start:l,length:"static"===s?42:l+c+6-h(t(a,e,c),o)}}(P,E,g),w=Array($).fill(0).map(((s,n)=>{const l=t(E,P,n+1-T);return{$date:l,active:y(e,l),day:d(l,C,{day:b}),now:y(o(t()),l),range:q(l,c,r,u),disabled:M(f,l)||k(m,l)||p(l,x),selected:v(r,l),inCurrentMonth:a(l).M===P}}));return{year:d(s,C,{year:Y}),month:i(s,D),days:w}};var U=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>d(e[s].$date,t,{weekday:a})));const j=t=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((o=>H(s,r(s,o,"month"),e,t,a))))(t);return e.useMemo((()=>({calendars:a,weekDays:U(a[0],t.config)})),[a,t.config])},z=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),J=e=>(t,a)=>e(a),K=e=>(...t)=>{e()},Q=(e,t,a={},s=!1)=>({role:"button",tabIndex:0,...e?{disabled:!0,"aria-disabled":!0}:{onClick(e){t(e)}},...s?{"aria-selected":!0}:{},...a});var V="SET_FOCUS_DATE",W="SET_OFFSET_DATE",X="SET_RANGE_END",Z="SET_YEAR",ee=(e,t)=>{switch(t.type){case V:return{...e,focusDate:t.date};case W:return{...e,offsetDate:t.date};case X:return{...e,rangeEnd:t.date};case Z:return{...e,offsetYear:t.year};default:return e}},te=(e,t)=>{e({type:V,date:t})},ae=(e,t)=>{e({type:X,date:t})},se=(e,t)=>{e({type:Z,year:t})};const oe=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||((e,t)=>{e({type:W,date:t})})(e,s),t&&t(s)},ne=(e,{days:t,months:a,years:s})=>{let o=e;return t&&0!==t&&(o=r(o,t,"date")),a&&0!==a&&(o=r(o,a,"month")),s&&0!==s&&(o=r(o,s,"year")),o},re=(e,{days:t=0,months:a=0,years:s=0},o)=>o?y(e,o)?e:0!==t?ce(e,o,t,"date"):0!==a?ce(e,o,a,"month"):0!==s?ce(e,o,s,"year"):e:e,ce=(e,t,a,s)=>{const o=r(e,a,s);if(a>0){return k(t,o)?c(t,a,s):e}return M(t,o)?c(t,a,s):e},le=t=>{const{config:{dates:a}}=t,{minDate:s,maxDate:o}=a,n=e.useCallback(((e,{disabled:a,onClick:s,...n}={})=>{const r=re(t.offsetDate,e,o),c=ne(r,e),l=!!a||k(o,c);return Q(l,(e=>z(s,J(oe(t)))(e,c)),n)}),[o,t]),r=e.useCallback((({days:e=0,months:a=0,years:o=0},{disabled:n,onClick:r,...c}={})=>{const l={days:-e,months:-a,years:-o},d=re(t.offsetDate,l,s),i=ne(d,l),u=!!n||M(s,i);return Q(u,(e=>z(r,J(oe(t)))(e,i)),c)}),[s,t]);return{addOffset:n,setOffset:e.useCallback(((e,{disabled:a,onClick:n,...r}={})=>{const c=!!a||M(s,e)||k(o,e);return Q(c,(a=>z(n,J(oe(t)))(a,e)),r)}),[t,o,s]),subtractOffset:r}},de=e=>"exact"===e,ie=(e,{mode:t,numberOfYears:a})=>de(t)?((e,t)=>e-t+1)(e,a):"decade"===t?(e=>e-e%10-1)(e):((e,t)=>e-(t/2-(t%2==0?1:0)))(e,a),ue=e=>{const{selectedDates:s,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:l},years:d}=e,i=n||(s.length>0?s[s.length-1]:((e,t,a)=>k(t,a)?t:M(e,a)?e:a)(c,l,o(t())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:ie(a(i).Y,d)}},fe=t=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:n,calendar:r={},dates:c={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...g}=c,{offsets:p=[],...h}=r,{minTime:y,maxTime:C,...b}=i,[Y,k]=x(m,D,l),[M,P]=x(y,C,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:n,focusDate:a&&v(e,a)?a:void 0,calendar:{...G,...h,offsets:G.offsets.concat(p)},years:{...S,...f},dates:{...A,...g,minDate:Y&&o(Y),maxDate:k&&o(k)},locale:{..._,...d},time:{...B,minTime:M,maxTime:P,...b},exclude:u}}(t),[s,n]=e.useReducer(ee,ue(a));return{dispatch:n,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},me=({selectedDates:t,config:{locale:a}})=>e.useMemo((()=>({selectedDates:t,formattedDates:t.map((e=>((e,{locale:t,options:a})=>d(e,t,a))(e,a)))})),[t,a]),De=({config:t,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:l}}=t;return{dayButton:e.useCallback((({$date:e,selected:d,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>Q(i||!!m,(i=>{(!d||c||(a.forEach((t=>{y(o(t),e)&&te(s,t)})),I(r)&&l))&&(I(r)&&1===a.length&&ae(s,null),z(f,J((e=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&v(e,t)?e.filter((e=>!y(o(e),t))):"multiple"===a?!n||e.length<n?g(e,t):e:I(a)?2===e.length?[t]:g(e,t):[t])(a,e,t.dates);te(s,v(r,e)?e:void 0),n(r)})))(i,e))}),{...D,...I(r)&&1===a.length&&{onMouseEnter(){ae(s,e)}},tabIndex:u?0:-1},d)),[r,c,t.dates,n,a,s,l])}};var ge=(e,s,o,{minDate:n,maxDate:r})=>{const{M:c,Y:l}=a(e),{Y:d,M:u}=a(t());return Array(12).fill(0).map(((e,f)=>{const m=t(l,f,1);return{$date:m,month:i(m,o),selected:s.some((e=>{const{M:t,Y:s}=a(e);return s===l&&t===f})),active:c===f,now:f===u&&l===d,disabled:P(f,n)&&O(l,n)||T(f,r)&&w(l,r)}}))};const xe=({selectedDates:t,offsetDate:a,config:{locale:s,dates:o}})=>e.useMemo((()=>({months:ge(a,t,s,o)})),[o,s,a,t]),pe=t=>({monthButton:e.useCallback((({$date:e,disabled:a,selected:s,active:o},{onClick:n,disabled:r,...c}={})=>Q(!!r||a,(a=>z(n,J(oe(t)))(a,e)),{...c,tabIndex:o?0:-1},s)),[t])});var he=(e,{time:s,locale:o})=>{const n=t(),{interval:r,minTime:c,maxTime:l,useLocales:d}=s,{Y:i,M:m,D:g}=a(e||n),x=1440/r,p=u(i,m,g,c),h=u(i,m,g,l);return Array(x).fill(0).map(((a,s)=>{const c=t(i,m,g,0,s*r);return{$date:c,disabled:!e||M(p,c)||k(h,c),now:y(c,n),selected:!!e&&y(e,c),time:d?f(c,o):D(c,o)}}))};const ye=({state:{focusDate:t},config:a})=>e.useMemo((()=>({time:he(t,a)})),[t,a]),Ce=({selectedDates:t,state:{focusDate:a},config:{onDatesChange:s},dispatch:o})=>({timeButton:e.useCallback((({$date:e,selected:n,disabled:r,now:c},{onClick:l,disabled:d,...i}={})=>Q(r||!!d,(r=>{n||z(l,J((e=>{const n=t.map((t=>y(a,t)?e:t));te(o,e),s(n)})))(r,e)}),{...i,tabIndex:n||c?0:-1},n)),[t,s,o,a])}),be=(e,s,o,{numberOfYears:n},{minDate:r,maxDate:c})=>{const{Y:l,M:d,D:i}=a(s),{Y:u}=a(t());return Array(n).fill(0).map(((s,n)=>{const f=e+n;return{$date:t(f,d,i),active:l===f,disabled:E(f,r)||$(f,c),now:f===u,selected:o.some((e=>a(e).Y===f)),year:f}}))},Ye=({selectedDates:t,state:{offsetDate:a,offsetYear:s},config:{years:o,dates:n}})=>e.useMemo((()=>({years:be(s,a,t,o,n)})),[a,s,t,o,n]),ke=s=>{const{state:{offsetYear:o,offsetDate:n},config:{dates:r,years:c},dispatch:l}=s,{minDate:d,maxDate:i}=r,{step:u,numberOfYears:f,mode:m}=c,{D:D,M:g}=a(n);return{yearButton:e.useCallback((({$date:e,disabled:t,selected:a,active:o},{onClick:n,disabled:r,...c}={})=>Q(!!r||t,(t=>z(n,J(oe(s)))(t,e)),{...c,tabIndex:o?0:-1},a)),[s]),nextYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const n=t(o+f-1,g,D),r=!!a||k(i,n)||de(m)&&!!i&&y(i,n);return Q(r,(t=>z(e,K((()=>se(l,o+u))))(t)),s)}),[i,l,o,u,D,g,f,m]),previousYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const n=!!a||M(d,t(o,g,D));return Q(n,(t=>z(e,K((()=>se(l,o-u))))(t)),s)}),[d,l,o,u,g,D])}},Me=e=>{const t=fe(e);return{data:{...j(t),...me(t),...xe(t),...ye(t),...Ye(t)},propGetters:{...De(t),...pe(t),...Ce(t),...ke(t),...le(t)}}};var ve=e.createContext({}),Pe=e.createContext({}),Ee=()=>e.useContext(Pe);exports.DatePickerProvider=({children:t,config:a})=>e.createElement(ve.Provider,{value:Me(a)},t),exports.DatePickerStateProvider=({children:t,config:a})=>e.createElement(Pe.Provider,{value:fe(a)},t),exports.useCalendars=j,exports.useContextCalendars=()=>j(Ee()),exports.useContextDatePickerOffsetPropGetters=()=>le(Ee()),exports.useContextDays=()=>me(Ee()),exports.useContextDaysPropGetters=()=>De(Ee()),exports.useContextMonths=()=>xe(Ee()),exports.useContextMonthsPropGetters=()=>pe(Ee()),exports.useContextTime=()=>ye(Ee()),exports.useContextTimePropGetters=()=>Ce(Ee()),exports.useContextYears=()=>Ye(Ee()),exports.useContextYearsPropGetters=()=>ke(Ee()),exports.useDatePicker=Me,exports.useDatePickerContext=()=>e.useContext(ve),exports.useDatePickerOffsetPropGetters=le,exports.useDatePickerState=fe,exports.useDatePickerStateContext=Ee,exports.useDays=me,exports.useDaysPropGetters=De,exports.useMonths=xe,exports.useMonthsPropGetters=pe,exports.useTime=ye,exports.useTimePropGetter=Ce,exports.useYears=Ye,exports.useYearsPropGetters=ke;
//# sourceMappingURL=index.cjs.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RehookifyDatepicker={},e.React)}(this,(function(e,t){"use strict";const a=(e,t,...a)=>e&&null!=t?new Date(e,t,...a):new Date,s=e=>({D:e.getDate(),M:e.getMonth(),Y:e.getFullYear()}),n=e=>e.getDay(),o=e=>a(s(e).Y,s(e).M,s(e).D),r=e=>a(s(e).Y,s(e).M+1,0).getDate(),c=(e,t,n)=>{const{Y:o,M:c,D:d}=s(e),l="date"===n?d+t:"month"===n&&d>r(a(o,c+t,1))?r(a(o,c+t,1)):d;return a(o+("year"===n?t:0),c+("month"===n?t:0),l)},d=(e,t,a)=>c(e,0-t,a),l=(e,t)=>+e-+t,i=(e,t,a)=>e.toLocaleDateString(t,a),u=(e,{locale:t,monthName:a})=>i(e,t,{month:a}),f=(e,t,s,n)=>n&&null!=n.h&&null!=n.m?a(e,t,s,n.h,n.m):void 0,m=(e,{locale:t,hour:a,minute:s,second:n,hour12:o})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:n,hour12:o}),D=e=>`${e<10?0:""}${e}`,g=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${D(e%12||12)}:${D(t)} ${a}`})(a,s):`${D(a)}:${D(s)}`},h=(e,t)=>e.concat(t).sort(l),y=(e,t,a)=>{let[s,n]=[e,t];return e&&t&&([s,n]=[e,t].sort(a)),[s,n]},C=(e,{day:t,date:a}={})=>((e,t)=>!!t&&t.includes(e))(e.getDay(),t)||((e,t=[])=>{const{M:a,D:n}=s(e);return t.some((e=>{const{M:t,D:o}=s(e);return a===t&&n===o}))})(e,a);function b(e,t){return(n(e)+7-t)%7}const p=(e,t)=>+e==+t,x=(e,t)=>e<t,k=(e,t)=>e>t,Y=(e,t,a)=>k(t,e)&&x(t,a)||x(t,e)&&k(t,a),M=(e,t)=>!!e&&k(t,e),v=(e,t)=>!!e&&x(t,e),P=(e,t)=>e.some((e=>p(o(e),o(t)))),T=(e,t)=>!!t&&e<s(t).M,E=(e,t)=>!!t&&e<s(t).Y,$=(e,t)=>!!t&&e>s(t).M,w=(e,t)=>!!t&&e>s(t).Y;var O={mode:"static",offsets:[0],startDay:0},G={mode:"decade",numberOfYears:12,step:10},S={mode:"single",toggle:!1,selectSameDate:!1},A={interval:30,useLocales:!1},B={locale:"en-GB",day:"2-digit",year:"numeric",weekday:"short",monthName:"long",hour:"2-digit",minute:"2-digit",hour12:void 0,second:void 0};function _(e){return"range"===e}const I="range-start",R="range-end",F="will-be-range-start",L="will-be-range-end",N=(e,t,a,s)=>{if(!_(s)||0===a.length)return"";const[n,r]=a;return n&&r?p(e,o(n))?p(o(n),o(r))?`${I} ${R}`:I:p(e,o(r))?R:Y(o(n),e,o(r))?"in-range":"":!r&&t?Y(o(n),e,t)?"will-be-in-range":x(t,o(n))?p(e,t)?F:p(e,o(n))?L:"":p(e,o(n))?F:p(e,t)?L:"":""},j=(e,t,n,{rangeEnd:c},d)=>{const{dates:{mode:l,minDate:f,maxDate:m},locale:D,calendar:g,exclude:h}=d,{locale:y,day:x,year:k}=D,{M:Y,Y:T}=s(t),{start:E,length:$}=function(e,t,{mode:s,startDay:n}){const o=a(t,e,1),c=r(o),d=b(o,n);return{start:d,length:"static"===s?42:d+c+6-b(a(t,e,c),n)}}(Y,T,g),w=Array($).fill(0).map(((t,r)=>{const d=a(T,Y,r+1-E);return{$date:d,active:p(e,d),day:i(d,y,{day:x}),now:p(o(a()),d),range:N(d,c,n,l),disabled:v(f,d)||M(m,d)||C(d,h),selected:P(n,d),inCurrentMonth:s(d).M===Y}}));return{year:i(t,y,{year:k}),month:u(t,D),days:w}};var q=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>i(e[s].$date,t,{weekday:a})));const H=e=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((n=>j(s,c(s,n,"month"),e,t,a))))(e);return t.useMemo((()=>({calendars:a,weekDays:q(a[0],e.config)})),[a,e.config])},U=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),z=e=>(t,a)=>e(a),J=e=>(...t)=>{e()},K=(e,t,a={},s=!1)=>({role:"button",tabIndex:0,...e?{disabled:!0,"aria-disabled":!0}:{onClick(e){t(e)}},...s?{"aria-selected":!0}:{},...a});var Q="SET_FOCUS_DATE",V="SET_OFFSET_DATE",W="SET_RANGE_END",X="SET_YEAR",Z=(e,t)=>{switch(t.type){case Q:return{...e,focusDate:t.date};case V:return{...e,offsetDate:t.date};case W:return{...e,rangeEnd:t.date};case X:return{...e,offsetYear:t.year};default:return e}},ee=(e,t)=>{e({type:Q,date:t})},te=(e,t)=>{e({type:W,date:t})},ae=(e,t)=>{e({type:X,year:t})};const se=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||((e,t)=>{e({type:V,date:t})})(e,s),t&&t(s)},ne=(e,{days:t,months:a,years:s})=>{let n=e;return t&&0!==t&&(n=c(n,t,"date")),a&&0!==a&&(n=c(n,a,"month")),s&&0!==s&&(n=c(n,s,"year")),n},oe=(e,{days:t=0,months:a=0,years:s=0},n)=>n?p(e,n)?e:0!==t?re(e,n,t,"date"):0!==a?re(e,n,a,"month"):0!==s?re(e,n,s,"year"):e:e,re=(e,t,a,s)=>{const n=c(e,a,s);if(a>0){return M(t,n)?d(t,a,s):e}return v(t,n)?d(t,a,s):e},ce=e=>{const{config:{dates:a}}=e,{minDate:s,maxDate:n}=a,o=t.useCallback(((t,{disabled:a,onClick:s,...o}={})=>{const r=oe(e.offsetDate,t,n),c=ne(r,t),d=!!a||M(n,c);return K(d,(t=>U(s,z(se(e)))(t,c)),o)}),[n,e]),r=t.useCallback((({days:t=0,months:a=0,years:n=0},{disabled:o,onClick:r,...c}={})=>{const d={days:-t,months:-a,years:-n},l=oe(e.offsetDate,d,s),i=ne(l,d),u=!!o||v(s,i);return K(u,(t=>U(r,z(se(e)))(t,i)),c)}),[s,e]);return{addOffset:o,setOffset:t.useCallback(((t,{disabled:a,onClick:o,...r}={})=>{const c=!!a||v(s,t)||M(n,t);return K(c,(a=>U(o,z(se(e)))(a,t)),r)}),[e,n,s]),subtractOffset:r}},de=e=>"exact"===e,le=(e,{mode:t,numberOfYears:a})=>de(t)?((e,t)=>e-t+1)(e,a):"decade"===t?(e=>e-e%10-1)(e):((e,t)=>e-(t/2-(t%2==0?1:0)))(e,a),ie=e=>{const{selectedDates:t,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:d},years:l}=e,i=n||(t.length>0?t[t.length-1]:((e,t,a)=>M(t,a)?t:v(e,a)?e:a)(c,d,o(a())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:le(s(i).Y,l)}},ue=e=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:n,calendar:r={},dates:c={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...g}=c,{offsets:h=[],...C}=r,{minTime:b,maxTime:p,...x}=i,[k,Y]=y(m,D,l),[M,v]=y(b,p,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:n,focusDate:a&&P(e,a)?a:void 0,calendar:{...O,...C,offsets:O.offsets.concat(h)},years:{...G,...f},dates:{...S,...g,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...B,...d},time:{...A,minTime:M,maxTime:v,...x},exclude:u}}(e),[s,n]=t.useReducer(Z,ie(a));return{dispatch:n,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},fe=({selectedDates:e,config:{locale:a}})=>t.useMemo((()=>({selectedDates:e,formattedDates:e.map((e=>((e,{locale:t,options:a})=>i(e,t,a))(e,a)))})),[e,a]),me=({config:e,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:d}}=e;return{dayButton:t.useCallback((({$date:t,selected:l,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>K(i||!!m,(i=>{(!l||c||(a.forEach((e=>{p(o(e),t)&&ee(s,e)})),_(r)&&d))&&(_(r)&&1===a.length&&te(s,null),U(f,z((t=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&P(e,t)?e.filter((e=>!p(o(e),t))):"multiple"===a?!n||e.length<n?h(e,t):e:_(a)?2===e.length?[t]:h(e,t):[t])(a,t,e.dates);ee(s,P(r,t)?t:void 0),n(r)})))(i,t))}),{...D,..._(r)&&1===a.length&&{onMouseEnter(){te(s,t)}},tabIndex:u?0:-1},l)),[r,c,e.dates,n,a,s,d])}};var De=(e,t,n,{minDate:o,maxDate:r})=>{const{M:c,Y:d}=s(e),{Y:l,M:i}=s(a());return Array(12).fill(0).map(((e,f)=>{const m=a(d,f,1);return{$date:m,month:u(m,n),selected:t.some((e=>{const{M:t,Y:a}=s(e);return a===d&&t===f})),active:c===f,now:f===i&&d===l,disabled:T(f,o)||E(d,o)||$(f,r)||w(d,r)}}))};const ge=({selectedDates:e,offsetDate:a,config:{locale:s,dates:n}})=>t.useMemo((()=>({months:De(a,e,s,n)})),[n,s,a,e]),he=e=>({monthButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>K(!!r||a,(a=>U(o,z(se(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e])});var ye=(e,{time:t,locale:n})=>{const o=a(),{interval:r,minTime:c,maxTime:d,useLocales:l}=t,{Y:i,M:u,D:D}=s(e||o),h=1440/r,y=f(i,u,D,c),C=f(i,u,D,d);return Array(h).fill(0).map(((t,s)=>{const c=a(i,u,D,0,s*r);return{$date:c,disabled:!e||v(y,c)||M(C,c),now:p(c,o),selected:!!e&&p(e,c),time:l?m(c,n):g(c,n)}}))};const Ce=({state:{focusDate:e},config:a})=>t.useMemo((()=>({time:ye(e,a)})),[e,a]),be=({selectedDates:e,state:{focusDate:a},config:{onDatesChange:s},dispatch:n})=>({timeButton:t.useCallback((({$date:t,selected:o,disabled:r,now:c},{onClick:d,disabled:l,...i}={})=>K(r||!!l,(r=>{o||U(d,z((t=>{const o=e.map((e=>p(a,e)?t:e));ee(n,t),s(o)})))(r,t)}),{...i,tabIndex:o||c?0:-1},o)),[e,s,n,a])}),pe=(e,t,n,{numberOfYears:o},{minDate:r,maxDate:c})=>{const{Y:d,M:l,D:i}=s(t),{Y:u}=s(a());return Array(o).fill(0).map(((t,o)=>{const f=e+o;return{$date:a(f,l,i),active:d===f,disabled:E(f,r)||w(f,c),now:f===u,selected:n.some((e=>s(e).Y===f)),year:f}}))},xe=({selectedDates:e,state:{offsetDate:a,offsetYear:s},config:{years:n,dates:o}})=>t.useMemo((()=>({years:pe(s,a,e,n,o)})),[a,s,e,n,o]),ke=e=>{const{state:{offsetYear:n,offsetDate:o},config:{dates:r,years:c},dispatch:d}=e,{minDate:l,maxDate:i}=r,{step:u,numberOfYears:f,mode:m}=c,{D:D,M:g}=s(o);return{yearButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>K(!!r||a,(a=>U(o,z(se(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e]),nextYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=a(n+f-1,g,D),r=!!t||M(i,o)||de(m)&&!!i&&p(i,o);return K(r,(t=>U(e,J((()=>ae(d,n+u))))(t)),s)}),[i,d,n,u,D,g,f,m]),previousYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=!!t||v(l,a(n,g,D));return K(o,(t=>U(e,J((()=>ae(d,n-u))))(t)),s)}),[l,d,n,u,g,D])}},Ye=e=>{const t=ue(e);return{data:{...H(t),...fe(t),...ge(t),...Ce(t),...xe(t)},propGetters:{...me(t),...he(t),...be(t),...ke(t),...ce(t)}}};var Me=t.createContext({}),ve=t.createContext({}),Pe=()=>t.useContext(ve);e.DatePickerProvider=({children:e,config:a})=>t.createElement(Me.Provider,{value:Ye(a)},e),e.DatePickerStateProvider=({children:e,config:a})=>t.createElement(ve.Provider,{value:ue(a)},e),e.useCalendars=H,e.useContextCalendars=()=>H(Pe()),e.useContextDatePickerOffsetPropGetters=()=>ce(Pe()),e.useContextDays=()=>fe(Pe()),e.useContextDaysPropGetters=()=>me(Pe()),e.useContextMonths=()=>ge(Pe()),e.useContextMonthsPropGetters=()=>he(Pe()),e.useContextTime=()=>Ce(Pe()),e.useContextTimePropGetters=()=>be(Pe()),e.useContextYears=()=>xe(Pe()),e.useContextYearsPropGetters=()=>ke(Pe()),e.useDatePicker=Ye,e.useDatePickerContext=()=>t.useContext(Me),e.useDatePickerOffsetPropGetters=ce,e.useDatePickerState=ue,e.useDatePickerStateContext=Pe,e.useDays=fe,e.useDaysPropGetters=me,e.useMonths=ge,e.useMonthsPropGetters=he,e.useTime=Ce,e.useTimePropGetter=be,e.useYears=xe,e.useYearsPropGetters=ke}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RehookifyDatepicker={},e.React)}(this,(function(e,t){"use strict";const a=(e,t,...a)=>e&&null!=t?new Date(e,t,...a):new Date,s=e=>({D:e.getDate(),M:e.getMonth(),Y:e.getFullYear()}),n=e=>e.getDay(),o=e=>a(s(e).Y,s(e).M,s(e).D),r=e=>a(s(e).Y,s(e).M+1,0).getDate(),c=(e,t,n)=>{const{Y:o,M:c,D:d}=s(e),l="date"===n?d+t:"month"===n&&d>r(a(o,c+t,1))?r(a(o,c+t,1)):d;return a(o+("year"===n?t:0),c+("month"===n?t:0),l)},d=(e,t,a)=>c(e,0-t,a),l=(e,t)=>+e-+t,i=(e,t,a)=>e.toLocaleDateString(t,a),u=(e,{locale:t,monthName:a})=>i(e,t,{month:a}),f=(e,t,s,n)=>n&&null!=n.h&&null!=n.m?a(e,t,s,n.h,n.m):void 0,m=(e,{locale:t,hour:a,minute:s,second:n,hour12:o})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:n,hour12:o}),D=e=>`${e<10?0:""}${e}`,g=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${D(e%12||12)}:${D(t)} ${a}`})(a,s):`${D(a)}:${D(s)}`},h=(e,t)=>e.concat(t).sort(l),y=(e,t,a)=>{let[s,n]=[e,t];return e&&t&&([s,n]=[e,t].sort(a)),[s,n]},C=(e,{day:t,date:a}={})=>((e,t)=>!!t&&t.includes(e))(e.getDay(),t)||((e,t=[])=>{const{M:a,D:n}=s(e);return t.some((e=>{const{M:t,D:o}=s(e);return a===t&&n===o}))})(e,a);function b(e,t){return(n(e)+7-t)%7}const p=(e,t)=>+e==+t,x=(e,t)=>e<t,k=(e,t)=>e>t,Y=(e,t,a)=>k(t,e)&&x(t,a)||x(t,e)&&k(t,a),M=(e,t)=>!!e&&k(t,e),v=(e,t)=>!!e&&x(t,e),P=(e,t)=>e.some((e=>p(o(e),o(t)))),T=(e,t)=>!!t&&e<s(t).M,E=(e,t)=>!!t&&e<s(t).Y,$=(e,t)=>!!t&&e>s(t).M,w=(e,t)=>!!t&&e>s(t).Y,O=(e,t)=>!!t&&e>=s(t).Y,G=(e,t)=>!!t&&e<=s(t).Y;var S={mode:"static",offsets:[0],startDay:0},A={mode:"decade",numberOfYears:12,step:10},B={mode:"single",toggle:!1,selectSameDate:!1},_={interval:30,useLocales:!1},I={locale:"en-GB",day:"2-digit",year:"numeric",weekday:"short",monthName:"long",hour:"2-digit",minute:"2-digit",hour12:void 0,second:void 0};function R(e){return"range"===e}const F="range-start",L="range-end",N="will-be-range-start",j="will-be-range-end",q=(e,t,a,s)=>{if(!R(s)||0===a.length)return"";const[n,r]=a;return n&&r?p(e,o(n))?p(o(n),o(r))?`${F} ${L}`:F:p(e,o(r))?L:Y(o(n),e,o(r))?"in-range":"":!r&&t?Y(o(n),e,t)?"will-be-in-range":x(t,o(n))?p(e,t)?N:p(e,o(n))?j:"":p(e,o(n))?N:p(e,t)?j:"":""},H=(e,t,n,{rangeEnd:c},d)=>{const{dates:{mode:l,minDate:f,maxDate:m},locale:D,calendar:g,exclude:h}=d,{locale:y,day:x,year:k}=D,{M:Y,Y:T}=s(t),{start:E,length:$}=function(e,t,{mode:s,startDay:n}){const o=a(t,e,1),c=r(o),d=b(o,n);return{start:d,length:"static"===s?42:d+c+6-b(a(t,e,c),n)}}(Y,T,g),w=Array($).fill(0).map(((t,r)=>{const d=a(T,Y,r+1-E);return{$date:d,active:p(e,d),day:i(d,y,{day:x}),now:p(o(a()),d),range:q(d,c,n,l),disabled:v(f,d)||M(m,d)||C(d,h),selected:P(n,d),inCurrentMonth:s(d).M===Y}}));return{year:i(t,y,{year:k}),month:u(t,D),days:w}};var U=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>i(e[s].$date,t,{weekday:a})));const z=e=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((n=>H(s,c(s,n,"month"),e,t,a))))(e);return t.useMemo((()=>({calendars:a,weekDays:U(a[0],e.config)})),[a,e.config])},J=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),K=e=>(t,a)=>e(a),Q=e=>(...t)=>{e()},V=(e,t,a={},s=!1)=>({role:"button",tabIndex:0,...e?{disabled:!0,"aria-disabled":!0}:{onClick(e){t(e)}},...s?{"aria-selected":!0}:{},...a});var W="SET_FOCUS_DATE",X="SET_OFFSET_DATE",Z="SET_RANGE_END",ee="SET_YEAR",te=(e,t)=>{switch(t.type){case W:return{...e,focusDate:t.date};case X:return{...e,offsetDate:t.date};case Z:return{...e,rangeEnd:t.date};case ee:return{...e,offsetYear:t.year};default:return e}},ae=(e,t)=>{e({type:W,date:t})},se=(e,t)=>{e({type:Z,date:t})},ne=(e,t)=>{e({type:ee,year:t})};const oe=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||((e,t)=>{e({type:X,date:t})})(e,s),t&&t(s)},re=(e,{days:t,months:a,years:s})=>{let n=e;return t&&0!==t&&(n=c(n,t,"date")),a&&0!==a&&(n=c(n,a,"month")),s&&0!==s&&(n=c(n,s,"year")),n},ce=(e,{days:t=0,months:a=0,years:s=0},n)=>n?p(e,n)?e:0!==t?de(e,n,t,"date"):0!==a?de(e,n,a,"month"):0!==s?de(e,n,s,"year"):e:e,de=(e,t,a,s)=>{const n=c(e,a,s);if(a>0){return M(t,n)?d(t,a,s):e}return v(t,n)?d(t,a,s):e},le=e=>{const{config:{dates:a}}=e,{minDate:s,maxDate:n}=a,o=t.useCallback(((t,{disabled:a,onClick:s,...o}={})=>{const r=ce(e.offsetDate,t,n),c=re(r,t),d=!!a||M(n,c);return V(d,(t=>J(s,K(oe(e)))(t,c)),o)}),[n,e]),r=t.useCallback((({days:t=0,months:a=0,years:n=0},{disabled:o,onClick:r,...c}={})=>{const d={days:-t,months:-a,years:-n},l=ce(e.offsetDate,d,s),i=re(l,d),u=!!o||v(s,i);return V(u,(t=>J(r,K(oe(e)))(t,i)),c)}),[s,e]);return{addOffset:o,setOffset:t.useCallback(((t,{disabled:a,onClick:o,...r}={})=>{const c=!!a||v(s,t)||M(n,t);return V(c,(a=>J(o,K(oe(e)))(a,t)),r)}),[e,n,s]),subtractOffset:r}},ie=e=>"exact"===e,ue=(e,{mode:t,numberOfYears:a})=>ie(t)?((e,t)=>e-t+1)(e,a):"decade"===t?(e=>e-e%10-1)(e):((e,t)=>e-(t/2-(t%2==0?1:0)))(e,a),fe=e=>{const{selectedDates:t,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:d},years:l}=e,i=n||(t.length>0?t[t.length-1]:((e,t,a)=>M(t,a)?t:v(e,a)?e:a)(c,d,o(a())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:ue(s(i).Y,l)}},me=e=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:n,calendar:r={},dates:c={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...g}=c,{offsets:h=[],...C}=r,{minTime:b,maxTime:p,...x}=i,[k,Y]=y(m,D,l),[M,v]=y(b,p,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:n,focusDate:a&&P(e,a)?a:void 0,calendar:{...S,...C,offsets:S.offsets.concat(h)},years:{...A,...f},dates:{...B,...g,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...I,...d},time:{..._,minTime:M,maxTime:v,...x},exclude:u}}(e),[s,n]=t.useReducer(te,fe(a));return{dispatch:n,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},De=({selectedDates:e,config:{locale:a}})=>t.useMemo((()=>({selectedDates:e,formattedDates:e.map((e=>((e,{locale:t,options:a})=>i(e,t,a))(e,a)))})),[e,a]),ge=({config:e,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:d}}=e;return{dayButton:t.useCallback((({$date:t,selected:l,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>V(i||!!m,(i=>{(!l||c||(a.forEach((e=>{p(o(e),t)&&ae(s,e)})),R(r)&&d))&&(R(r)&&1===a.length&&se(s,null),J(f,K((t=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&P(e,t)?e.filter((e=>!p(o(e),t))):"multiple"===a?!n||e.length<n?h(e,t):e:R(a)?2===e.length?[t]:h(e,t):[t])(a,t,e.dates);ae(s,P(r,t)?t:void 0),n(r)})))(i,t))}),{...D,...R(r)&&1===a.length&&{onMouseEnter(){se(s,t)}},tabIndex:u?0:-1},l)),[r,c,e.dates,n,a,s,d])}};var he=(e,t,n,{minDate:o,maxDate:r})=>{const{M:c,Y:d}=s(e),{Y:l,M:i}=s(a());return Array(12).fill(0).map(((e,f)=>{const m=a(d,f,1);return{$date:m,month:u(m,n),selected:t.some((e=>{const{M:t,Y:a}=s(e);return a===d&&t===f})),active:c===f,now:f===i&&d===l,disabled:T(f,o)&&G(d,o)||$(f,r)&&O(d,r)}}))};const ye=({selectedDates:e,offsetDate:a,config:{locale:s,dates:n}})=>t.useMemo((()=>({months:he(a,e,s,n)})),[n,s,a,e]),Ce=e=>({monthButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>V(!!r||a,(a=>J(o,K(oe(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e])});var be=(e,{time:t,locale:n})=>{const o=a(),{interval:r,minTime:c,maxTime:d,useLocales:l}=t,{Y:i,M:u,D:D}=s(e||o),h=1440/r,y=f(i,u,D,c),C=f(i,u,D,d);return Array(h).fill(0).map(((t,s)=>{const c=a(i,u,D,0,s*r);return{$date:c,disabled:!e||v(y,c)||M(C,c),now:p(c,o),selected:!!e&&p(e,c),time:l?m(c,n):g(c,n)}}))};const pe=({state:{focusDate:e},config:a})=>t.useMemo((()=>({time:be(e,a)})),[e,a]),xe=({selectedDates:e,state:{focusDate:a},config:{onDatesChange:s},dispatch:n})=>({timeButton:t.useCallback((({$date:t,selected:o,disabled:r,now:c},{onClick:d,disabled:l,...i}={})=>V(r||!!l,(r=>{o||J(d,K((t=>{const o=e.map((e=>p(a,e)?t:e));ae(n,t),s(o)})))(r,t)}),{...i,tabIndex:o||c?0:-1},o)),[e,s,n,a])}),ke=(e,t,n,{numberOfYears:o},{minDate:r,maxDate:c})=>{const{Y:d,M:l,D:i}=s(t),{Y:u}=s(a());return Array(o).fill(0).map(((t,o)=>{const f=e+o;return{$date:a(f,l,i),active:d===f,disabled:E(f,r)||w(f,c),now:f===u,selected:n.some((e=>s(e).Y===f)),year:f}}))},Ye=({selectedDates:e,state:{offsetDate:a,offsetYear:s},config:{years:n,dates:o}})=>t.useMemo((()=>({years:ke(s,a,e,n,o)})),[a,s,e,n,o]),Me=e=>{const{state:{offsetYear:n,offsetDate:o},config:{dates:r,years:c},dispatch:d}=e,{minDate:l,maxDate:i}=r,{step:u,numberOfYears:f,mode:m}=c,{D:D,M:g}=s(o);return{yearButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>V(!!r||a,(a=>J(o,K(oe(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e]),nextYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=a(n+f-1,g,D),r=!!t||M(i,o)||ie(m)&&!!i&&p(i,o);return V(r,(t=>J(e,Q((()=>ne(d,n+u))))(t)),s)}),[i,d,n,u,D,g,f,m]),previousYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=!!t||v(l,a(n,g,D));return V(o,(t=>J(e,Q((()=>ne(d,n-u))))(t)),s)}),[l,d,n,u,g,D])}},ve=e=>{const t=me(e);return{data:{...z(t),...De(t),...ye(t),...pe(t),...Ye(t)},propGetters:{...ge(t),...Ce(t),...xe(t),...Me(t),...le(t)}}};var Pe=t.createContext({}),Te=t.createContext({}),Ee=()=>t.useContext(Te);e.DatePickerProvider=({children:e,config:a})=>t.createElement(Pe.Provider,{value:ve(a)},e),e.DatePickerStateProvider=({children:e,config:a})=>t.createElement(Te.Provider,{value:me(a)},e),e.useCalendars=z,e.useContextCalendars=()=>z(Ee()),e.useContextDatePickerOffsetPropGetters=()=>le(Ee()),e.useContextDays=()=>De(Ee()),e.useContextDaysPropGetters=()=>ge(Ee()),e.useContextMonths=()=>ye(Ee()),e.useContextMonthsPropGetters=()=>Ce(Ee()),e.useContextTime=()=>pe(Ee()),e.useContextTimePropGetters=()=>xe(Ee()),e.useContextYears=()=>Ye(Ee()),e.useContextYearsPropGetters=()=>Me(Ee()),e.useDatePicker=ve,e.useDatePickerContext=()=>t.useContext(Pe),e.useDatePickerOffsetPropGetters=le,e.useDatePickerState=me,e.useDatePickerStateContext=Ee,e.useDays=De,e.useDaysPropGetters=ge,e.useMonths=ye,e.useMonthsPropGetters=Ce,e.useTime=pe,e.useTimePropGetter=xe,e.useYears=Ye,e.useYearsPropGetters=Me}));
//# sourceMappingURL=index.umd.js.map

@@ -12,2 +12,4 @@ export declare const isSame: (d1: Date, d2: Date) => boolean;

export declare const isAfterMaxYear: (year: number, maxDate?: Date) => boolean;
export declare const isSameOrAfterMaxYear: (year: number, maxDate?: Date) => boolean;
export declare const isSameOrBeforeMinYear: (year: number, minDate?: Date) => boolean;
//# sourceMappingURL=predicates.d.ts.map
{
"name": "@rehookify/datepicker",
"version": "6.6.0",
"version": "6.6.1",
"description": "The ultimate tool to create a date, range and time picker in your React applications.",

@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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