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 5.0.0 to 5.1.0

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

@@ -14,4 +14,5 @@ import { MouseEvent } from 'react';

'aria-disabled'?: boolean;
'aria-selected'?: boolean;
onClick?(evt: MouseEvent<HTMLElement>): void;
}
//# sourceMappingURL=prop-getters.d.ts.map
import { MouseEvent } from 'react';
import type { DPPropGetter, DPPropsGetterConfig } from '../types';
export declare const createPropGetter: (isDisabled: boolean, action: (evt: MouseEvent<HTMLElement>) => void, props?: DPPropsGetterConfig) => DPPropGetter;
export declare const createPropGetter: (isDisabled: boolean, action: (evt: MouseEvent<HTMLElement>) => void, props?: DPPropsGetterConfig, selected?: boolean) => DPPropGetter;
//# sourceMappingURL=create-prop-getter.d.ts.map
{
"name": "@rehookify/datepicker",
"version": "5.0.0",
"version": "5.1.0",
"description": "The ultimate tool to create a date, range and time picker in your React applications.",

@@ -73,3 +73,3 @@ "main": "dist/index.cjs.js",

"@playwright/test": "^1.28.1",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",

@@ -76,0 +76,0 @@ "@rollup/plugin-terser": "^0.4.0",

@@ -475,2 +475,3 @@ # @rehookify/datepicker

'aria-disabled'?: boolean;
'aria-selected'?: boolean;
onClick?(evt: MouseEvent<HTMLElement>): void;

@@ -477,0 +478,0 @@ }

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

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