@rehookify/datepicker
Advanced tools
Comparing version 6.5.0 to 6.5.1
@@ -1,2 +0,2 @@ | ||
import { ReactNode } from 'react'; | ||
import { FC } from 'react'; | ||
import { DatePickerProviderProps } from './types'; | ||
@@ -7,3 +7,3 @@ export declare var useDatePickerContext: () => { | ||
}; | ||
export declare function DatePickerProvider({ children, config, }: DatePickerProviderProps): ReactNode; | ||
export declare var DatePickerProvider: FC<DatePickerProviderProps>; | ||
//# sourceMappingURL=date-picker-provider.d.ts.map |
@@ -1,5 +0,5 @@ | ||
import { ReactNode } from 'react'; | ||
import { FC } from 'react'; | ||
import type { DatePickerProviderProps, DPState } from './types'; | ||
export declare var useDatePickerStateContext: () => DPState; | ||
export declare function DatePickerStateProvider({ children, config, }: DatePickerProviderProps): ReactNode; | ||
export declare var DatePickerStateProvider: FC<DatePickerProviderProps>; | ||
//# sourceMappingURL=date-picker-state-provider.d.ts.map |
@@ -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(),n=e=>t(a(e).Y,a(e).M,a(e).D),o=e=>t(a(e).Y,a(e).M+1,0).getDate(),r=(e,s,n)=>{const{Y:r,M:c,D:l}=a(e),d="date"===n?l+s:"month"===n&&l>o(t(r,c+s,1))?o(t(r,c+s,1)):l;return t(r+("year"===n?s:0),c+("month"===n?s:0),d)},c=(e,t)=>+e-+t,l=(e,t,a)=>e.toLocaleDateString(t,a),d=(e,{locale:t,monthName:a})=>l(e,t,{month:a}),i=(e,a,s,n)=>n&&null!=n.h&&null!=n.m?t(e,a,s,n.h,n.m):void 0,u=(e,{locale:t,hour:a,minute:s,second:n,hour12:o})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:n,hour12:o}),f=e=>`${e<10?0:""}${e}`,m=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${f(e%12||12)}:${f(t)} ${a}`})(a,s):`${f(a)}:${f(s)}`},D=(e,t)=>e.concat(t).sort(c),g=(e,t,a)=>{let[s,n]=[e,t];return e&&t&&([s,n]=[e,t].sort(a)),[s,n]},x=(e,{day:t,date:s}={})=>((e,t)=>!!t&&t.includes(e))(e.getDay(),t)||((e,t=[])=>{const{M:s,D:n}=a(e);return t.some((e=>{const{M:t,D:o}=a(e);return s===t&&n===o}))})(e,s);function p(e,t){return(s(e)+7-t)%7}const h=(e,t)=>+e==+t,y=(e,t)=>e<t,C=(e,t)=>e>t,b=(e,t,a)=>C(t,e)&&y(t,a)||y(t,e)&&C(t,a),k=(e,t)=>!!e&&C(t,e),Y=(e,t)=>!!e&&y(t,e),M=(e,t)=>e.some((e=>h(n(e),n(t)))),v=(e,t)=>!!t&&e<a(t).M,P=(e,t)=>!!t&&e<a(t).Y,E=(e,t)=>!!t&&e>a(t).M,T=(e,t)=>!!t&&e>a(t).Y;var $={mode:"static",offsets:[0],startDay:0},w={mode:"decade",numberOfYears:12,step:10},O={mode:"single",toggle:!1,selectSameDate:!1},G={interval:30,useLocales:!1},S={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 A(e){return"range"===e}const B="range-start",_="range-end",I="will-be-range-start",F="will-be-range-end",L=(e,t,a,s)=>{if(!A(s)||0===a.length)return"";const[o,r]=a;return o&&r?h(e,n(o))?h(n(o),n(r))?`${B} ${_}`:B:h(e,n(r))?_:b(n(o),e,n(r))?"in-range":"":!r&&t?b(n(o),e,t)?"will-be-in-range":y(t,n(o))?h(e,t)?I:h(e,n(o))?F:"":h(e,n(o))?I:h(e,t)?F:"":""},N=(e,s,r,{rangeEnd:c},i)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:y}=i,{locale:C,day:b,year:v}=D,{M:P,Y:E}=a(s),{start:T,length:$}=function(e,a,{mode:s,startDay:n}){const r=t(a,e,1),c=o(r),l=p(r,n);return{start:l,length:"static"===s?42:l+c+6-p(t(a,e,c),n)}}(P,E,g),w=Array($).fill(0).map(((s,o)=>{const d=t(E,P,o+1-T);return{$date:d,active:h(e,d),day:l(d,C,{day:b}),now:h(n(t()),d),range:L(d,c,r,u),disabled:Y(f,d)||k(m,d)||x(d,y),selected:M(r,d),inCurrentMonth:a(d).M===P}}));return{year:l(s,C,{year:v}),month:d(s,D),days:w}};function R({days:e},{locale:{locale:t,weekday:a}}){return[0,1,2,3,4,5,6].map((s=>l(e[s].$date,t,{weekday:a})))}const q=t=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((n=>N(s,r(s,n,"month"),e,t,a))))(t);return e.useMemo((()=>({calendars:a,weekDays:R(a[0],t.config)})),[a,t.config])},H=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),U=e=>(t,a)=>e(a),j=e=>(...t)=>{e()},z=(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 J="SET_FOCUS_DATE",K="SET_OFFSET_DATE",Q="SET_RANGE_END",V="SET_YEAR";function W(e,t){switch(t.type){case J:return{...e,focusDate:t.date};case K:return{...e,offsetDate:t.date};case Q:return{...e,rangeEnd:t.date};case V:return{...e,offsetYear:t.year};default:return e}}function X(e,t){e({type:J,date:t})}function Z(e,t){e({type:Q,date:t})}function ee(e,t){e({type:V,year:t})}const te=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||function(e,t){e({type:K,date:t})}(e,s),t&&t(s)},ae=(e,{days:t,months:a,years:s})=>{let n=e;return t&&0!==t&&(n=r(n,t,"date")),a&&0!==a&&(n=r(n,a,"month")),s&&0!==s&&(n=r(n,s,"year")),n},se=t=>{const{config:{dates:a}}=t,{minDate:s,maxDate:n}=a,o=e.useCallback(((e,{disabled:a,onClick:s,...o}={})=>{const r=ae(t.offsetDate,e),c=!!a||k(n,r);return z(c,(e=>H(s,U(te(t)))(e,r)),o)}),[n,t]),r=e.useCallback((({days:e=0,months:a=0,years:n=0},{disabled:o,onClick:r,...c}={})=>{const l={days:-e,months:-a,years:-n},d=ae(t.offsetDate,l),i=!!o||Y(s,d);return z(i,(e=>H(r,U(te(t)))(e,d)),c)}),[s,t]);return{addOffset:o,setOffset:e.useCallback(((e,{disabled:a,onClick:o,...r}={})=>{const c=!!a||Y(s,e)||k(n,e);return z(c,(a=>H(o,U(te(t)))(a,e)),r)}),[t,n,s]),subtractOffset:r}},ne=e=>"exact"===e,oe=(e,{mode:t,numberOfYears:a})=>ne(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),re=e=>{const{selectedDates:s,offsetDate:o,focusDate:r,dates:{minDate:c,maxDate:l},years:d}=e,i=o||(s.length>0?s[s.length-1]:((e,t,a)=>k(t,a)?t:Y(e,a)?e:a)(c,l,n(t())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:oe(a(i).Y,d)}},ce=t=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:o,calendar:r={},dates:l={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...x}=l,{offsets:p=[],...h}=r,{minTime:y,maxTime:C,...b}=i,[k,Y]=g(m,D,c),[v,P]=g(y,C,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:o,focusDate:a&&M(e,a)?a:void 0,calendar:{...$,...h,offsets:$.offsets.concat(p)},years:{...w,...f},dates:{...O,...x,minDate:k&&n(k),maxDate:Y&&n(Y)},locale:{...S,...d},time:{...G,minTime:v,maxTime:P,...b},exclude:u}}(t),[s,o]=e.useReducer(W,re(a));return{dispatch:o,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},le=({selectedDates:t,config:{locale:a}})=>e.useMemo((()=>({selectedDates:t,formattedDates:t.map((e=>((e,{locale:t,options:a})=>l(e,t,a))(e,a)))})),[t,a]),de=({config:t,selectedDates:a,dispatch:s})=>{const{onDatesChange:o,dates:{mode:r,toggle:c,selectSameDate:l}}=t;return{dayButton:e.useCallback((({$date:e,selected:d,disabled:i,active:u},{onClick:f,disabled:m,...g}={})=>z(i||!!m,(i=>{(!d||c||(a.forEach((t=>{h(n(t),e)&&X(s,t)})),A(r)&&l))&&(A(r)&&1===a.length&&Z(s,null),H(f,U((e=>{const r=((e,t,{mode:a,toggle:s,limit:o})=>s&&M(e,t)?e.filter((e=>!h(n(e),t))):"multiple"===a?!o||e.length<o?D(e,t):e:A(a)?2===e.length?[t]:D(e,t):[t])(a,e,t.dates);X(s,M(r,e)?e:void 0),o(r)})))(i,e))}),{...g,...A(r)&&1===a.length&&{onMouseEnter(){Z(s,e)}},tabIndex:u?0:-1},d)),[r,c,t.dates,o,a,s,l])}};function ie(e,s,n,{minDate:o,maxDate:r}){const{M:c,Y:l}=a(e),{Y:i,M:u}=a(t());return Array(12).fill(0).map(((e,f)=>{const m=t(l,f,1);return{$date:m,month:d(m,n),selected:s.some((e=>{const{M:t,Y:s}=a(e);return s===l&&t===f})),active:c===f,now:f===u&&l===i,disabled:v(f,o)||P(l,o)||E(f,r)||T(l,r)}}))}const ue=({selectedDates:t,offsetDate:a,config:{locale:s,dates:n}})=>e.useMemo((()=>({months:ie(a,t,s,n)})),[n,s,a,t]),fe=t=>({monthButton:e.useCallback((({$date:e,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>z(!!r||a,(a=>H(o,U(te(t)))(a,e)),{...c,tabIndex:n?0:-1},s)),[t])}),me=(e,{time:s,locale:n})=>{const o=t(),{interval:r,minTime:c,maxTime:l,useLocales:d}=s,{Y:f,M:D,D:g}=a(e||o),x=1440/r,p=i(f,D,g,c),y=i(f,D,g,l);return Array(x).fill(0).map(((a,s)=>{const c=t(f,D,g,0,s*r);return{$date:c,disabled:!e||Y(p,c)||k(y,c),now:h(c,o),selected:!!e&&h(e,c),time:d?u(c,n):m(c,n)}}))},De=({state:{focusDate:t},config:a})=>e.useMemo((()=>({time:me(t,a)})),[t,a]),ge=({selectedDates:t,state:{focusDate:a},config:{onDatesChange:s},dispatch:n})=>({timeButton:e.useCallback((({$date:e,selected:o,disabled:r,now:c},{onClick:l,disabled:d,...i}={})=>z(r||!!d,(r=>{o||H(l,U((e=>{const o=t.map((t=>h(a,t)?e:t));X(n,e),s(o)})))(r,e)}),{...i,tabIndex:o||c?0:-1},o)),[t,s,n,a])}),xe=(e,s,n,{numberOfYears:o},{minDate:r,maxDate:c})=>{const{Y:l,M:d,D:i}=a(s),{Y:u}=a(t());return Array(o).fill(0).map(((s,o)=>{const f=e+o;return{$date:t(f,d,i),active:l===f,disabled:P(f,r)||T(f,c),now:f===u,selected:n.some((e=>a(e).Y===f)),year:f}}))},pe=({selectedDates:t,state:{offsetDate:a,offsetYear:s},config:{years:n,dates:o}})=>e.useMemo((()=>({years:xe(s,a,t,n,o)})),[a,s,t,n,o]),he=s=>{const{state:{offsetYear:n,offsetDate:o},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(o);return{yearButton:e.useCallback((({$date:e,disabled:t,selected:a,active:n},{onClick:o,disabled:r,...c}={})=>z(!!r||t,(t=>H(o,U(te(s)))(t,e)),{...c,tabIndex:n?0:-1},a)),[s]),nextYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const o=t(n+f-1,g,D),r=!!a||k(i,o)||ne(m)&&!!i&&h(i,o);return z(r,(t=>H(e,j((()=>ee(l,n+u))))(t)),s)}),[i,l,n,u,D,g,f,m]),previousYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const o=!!a||Y(d,t(n,g,D));return z(o,(t=>H(e,j((()=>ee(l,n-u))))(t)),s)}),[d,l,n,u,g,D])}},ye=e=>{const t=ce(e);return{data:{...q(t),...le(t),...ue(t),...De(t),...pe(t)},propGetters:{...de(t),...fe(t),...ge(t),...he(t),...se(t)}}};var Ce=e.createContext({});var be=e.createContext({}),ke=()=>e.useContext(be);exports.DatePickerProvider=function({children:t,config:a}){return e.createElement(Ce.Provider,{value:ye(a)},t)},exports.DatePickerStateProvider=function({children:t,config:a}){return e.createElement(be.Provider,{value:ce(a)},t)},exports.useCalendars=q,exports.useContextCalendars=()=>q(ke()),exports.useContextDatePickerOffsetPropGetters=()=>se(ke()),exports.useContextDays=()=>le(ke()),exports.useContextDaysPropGetters=()=>de(ke()),exports.useContextMonths=()=>ue(ke()),exports.useContextMonthsPropGetters=()=>fe(ke()),exports.useContextTime=()=>De(ke()),exports.useContextTimePropGetters=()=>ge(ke()),exports.useContextYears=()=>pe(ke()),exports.useContextYearsPropGetters=()=>he(ke()),exports.useDatePicker=ye,exports.useDatePickerContext=()=>e.useContext(Ce),exports.useDatePickerOffsetPropGetters=se,exports.useDatePickerState=ce,exports.useDatePickerStateContext=ke,exports.useDays=le,exports.useDaysPropGetters=de,exports.useMonths=ue,exports.useMonthsPropGetters=fe,exports.useTime=De,exports.useTimePropGetter=ge,exports.useYears=pe,exports.useYearsPropGetters=he; | ||
"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)=>+e-+t,l=(e,t,a)=>e.toLocaleDateString(t,a),d=(e,{locale:t,monthName:a})=>l(e,t,{month:a}),i=(e,a,s,o)=>o&&null!=o.h&&null!=o.m?t(e,a,s,o.h,o.m):void 0,u=(e,{locale:t,hour:a,minute:s,second:o,hour12:n})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:o,hour12:n}),f=e=>`${e<10?0:""}${e}`,m=(e,{hour12:t})=>{const a=e.getHours(),s=e.getMinutes();return t?((e,t)=>{const a=e>=12?"pm":"am";return`${f(e%12||12)}:${f(t)} ${a}`})(a,s):`${f(a)}:${f(s)}`},D=(e,t)=>e.concat(t).sort(c),g=(e,t,a)=>{let[s,o]=[e,t];return e&&t&&([s,o]=[e,t].sort(a)),[s,o]},x=(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 p(e,t){return(s(e)+7-t)%7}const h=(e,t)=>+e==+t,y=(e,t)=>e<t,C=(e,t)=>e>t,b=(e,t,a)=>C(t,e)&&y(t,a)||y(t,e)&&C(t,a),k=(e,t)=>!!e&&C(t,e),Y=(e,t)=>!!e&&y(t,e),M=(e,t)=>e.some((e=>h(o(e),o(t)))),v=(e,t)=>!!t&&e<a(t).M,P=(e,t)=>!!t&&e<a(t).Y,E=(e,t)=>!!t&&e>a(t).M,T=(e,t)=>!!t&&e>a(t).Y;var $={mode:"static",offsets:[0],startDay:0},w={mode:"decade",numberOfYears:12,step:10},O={mode:"single",toggle:!1,selectSameDate:!1},G={interval:30,useLocales:!1},S={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 A(e){return"range"===e}const B="range-start",_="range-end",I="will-be-range-start",F="will-be-range-end",L=(e,t,a,s)=>{if(!A(s)||0===a.length)return"";const[n,r]=a;return n&&r?h(e,o(n))?h(o(n),o(r))?`${B} ${_}`:B:h(e,o(r))?_:b(o(n),e,o(r))?"in-range":"":!r&&t?b(o(n),e,t)?"will-be-in-range":y(t,o(n))?h(e,t)?I:h(e,o(n))?F:"":h(e,o(n))?I:h(e,t)?F:"":""},N=(e,s,r,{rangeEnd:c},i)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:y}=i,{locale:C,day:b,year:v}=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=p(r,o);return{start:l,length:"static"===s?42:l+c+6-p(t(a,e,c),o)}}(P,E,g),w=Array($).fill(0).map(((s,n)=>{const d=t(E,P,n+1-T);return{$date:d,active:h(e,d),day:l(d,C,{day:b}),now:h(o(t()),d),range:L(d,c,r,u),disabled:Y(f,d)||k(m,d)||x(d,y),selected:M(r,d),inCurrentMonth:a(d).M===P}}));return{year:l(s,C,{year:v}),month:d(s,D),days:w}};var R=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>l(e[s].$date,t,{weekday:a})));const q=t=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((o=>N(s,r(s,o,"month"),e,t,a))))(t);return e.useMemo((()=>({calendars:a,weekDays:R(a[0],t.config)})),[a,t.config])},H=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),U=e=>(t,a)=>e(a),j=e=>(...t)=>{e()},z=(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 J="SET_FOCUS_DATE",K="SET_OFFSET_DATE",Q="SET_RANGE_END",V="SET_YEAR",W=(e,t)=>{switch(t.type){case J:return{...e,focusDate:t.date};case K:return{...e,offsetDate:t.date};case Q:return{...e,rangeEnd:t.date};case V:return{...e,offsetYear:t.year};default:return e}},X=(e,t)=>{e({type:J,date:t})},Z=(e,t)=>{e({type:Q,date:t})},ee=(e,t)=>{e({type:V,year:t})};const te=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||((e,t)=>{e({type:K,date:t})})(e,s),t&&t(s)},ae=(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},se=t=>{const{config:{dates:a}}=t,{minDate:s,maxDate:o}=a,n=e.useCallback(((e,{disabled:a,onClick:s,...n}={})=>{const r=ae(t.offsetDate,e),c=!!a||k(o,r);return z(c,(e=>H(s,U(te(t)))(e,r)),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=ae(t.offsetDate,l),i=!!n||Y(s,d);return z(i,(e=>H(r,U(te(t)))(e,d)),c)}),[s,t]);return{addOffset:n,setOffset:e.useCallback(((e,{disabled:a,onClick:n,...r}={})=>{const c=!!a||Y(s,e)||k(o,e);return z(c,(a=>H(n,U(te(t)))(a,e)),r)}),[t,o,s]),subtractOffset:r}},oe=e=>"exact"===e,ne=(e,{mode:t,numberOfYears:a})=>oe(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),re=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:Y(e,a)?e:a)(c,l,o(t())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:ne(a(i).Y,d)}},ce=t=>{const a=function({selectedDates:e=[],onDatesChange:t,focusDate:a,offsetDate:s,onOffsetChange:n,calendar:r={},dates:l={},locale:d,time:i={},exclude:u={},years:f}){const{minDate:m,maxDate:D,...x}=l,{offsets:p=[],...h}=r,{minTime:y,maxTime:C,...b}=i,[k,Y]=g(m,D,c),[v,P]=g(y,C,((e,t)=>e.h-t.h));return{selectedDates:e,onDatesChange:t,offsetDate:s,onOffsetChange:n,focusDate:a&&M(e,a)?a:void 0,calendar:{...$,...h,offsets:$.offsets.concat(p)},years:{...w,...f},dates:{...O,...x,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...S,...d},time:{...G,minTime:v,maxTime:P,...b},exclude:u}}(t),[s,n]=e.useReducer(W,re(a));return{dispatch:n,selectedDates:a.selectedDates,offsetDate:a.offsetDate||s.offsetDate,state:s,config:a}},le=({selectedDates:t,config:{locale:a}})=>e.useMemo((()=>({selectedDates:t,formattedDates:t.map((e=>((e,{locale:t,options:a})=>l(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,...g}={})=>z(i||!!m,(i=>{(!d||c||(a.forEach((t=>{h(o(t),e)&&X(s,t)})),A(r)&&l))&&(A(r)&&1===a.length&&Z(s,null),H(f,U((e=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&M(e,t)?e.filter((e=>!h(o(e),t))):"multiple"===a?!n||e.length<n?D(e,t):e:A(a)?2===e.length?[t]:D(e,t):[t])(a,e,t.dates);X(s,M(r,e)?e:void 0),n(r)})))(i,e))}),{...g,...A(r)&&1===a.length&&{onMouseEnter(){Z(s,e)}},tabIndex:u?0:-1},d)),[r,c,t.dates,n,a,s,l])}};var ie=(e,s,o,{minDate:n,maxDate:r})=>{const{M:c,Y:l}=a(e),{Y:i,M:u}=a(t());return Array(12).fill(0).map(((e,f)=>{const m=t(l,f,1);return{$date:m,month:d(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===i,disabled:v(f,n)||P(l,n)||E(f,r)||T(l,r)}}))};const ue=({selectedDates:t,offsetDate:a,config:{locale:s,dates:o}})=>e.useMemo((()=>({months:ie(a,t,s,o)})),[o,s,a,t]),fe=t=>({monthButton:e.useCallback((({$date:e,disabled:a,selected:s,active:o},{onClick:n,disabled:r,...c}={})=>z(!!r||a,(a=>H(n,U(te(t)))(a,e)),{...c,tabIndex:o?0:-1},s)),[t])});var me=(e,{time:s,locale:o})=>{const n=t(),{interval:r,minTime:c,maxTime:l,useLocales:d}=s,{Y:f,M:D,D:g}=a(e||n),x=1440/r,p=i(f,D,g,c),y=i(f,D,g,l);return Array(x).fill(0).map(((a,s)=>{const c=t(f,D,g,0,s*r);return{$date:c,disabled:!e||Y(p,c)||k(y,c),now:h(c,n),selected:!!e&&h(e,c),time:d?u(c,o):m(c,o)}}))};const De=({state:{focusDate:t},config:a})=>e.useMemo((()=>({time:me(t,a)})),[t,a]),ge=({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}={})=>z(r||!!d,(r=>{n||H(l,U((e=>{const n=t.map((t=>h(a,t)?e:t));X(o,e),s(n)})))(r,e)}),{...i,tabIndex:n||c?0:-1},n)),[t,s,o,a])}),xe=(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:P(f,r)||T(f,c),now:f===u,selected:o.some((e=>a(e).Y===f)),year:f}}))},pe=({selectedDates:t,state:{offsetDate:a,offsetYear:s},config:{years:o,dates:n}})=>e.useMemo((()=>({years:xe(s,a,t,o,n)})),[a,s,t,o,n]),he=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}={})=>z(!!r||t,(t=>H(n,U(te(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)||oe(m)&&!!i&&h(i,n);return z(r,(t=>H(e,j((()=>ee(l,o+u))))(t)),s)}),[i,l,o,u,D,g,f,m]),previousYearsButton:e.useCallback((({onClick:e,disabled:a,...s}={})=>{const n=!!a||Y(d,t(o,g,D));return z(n,(t=>H(e,j((()=>ee(l,o-u))))(t)),s)}),[d,l,o,u,g,D])}},ye=e=>{const t=ce(e);return{data:{...q(t),...le(t),...ue(t),...De(t),...pe(t)},propGetters:{...de(t),...fe(t),...ge(t),...he(t),...se(t)}}};var Ce=e.createContext({}),be=e.createContext({}),ke=()=>e.useContext(be);exports.DatePickerProvider=({children:t,config:a})=>e.createElement(Ce.Provider,{value:ye(a)},t),exports.DatePickerStateProvider=({children:t,config:a})=>e.createElement(be.Provider,{value:ce(a)},t),exports.useCalendars=q,exports.useContextCalendars=()=>q(ke()),exports.useContextDatePickerOffsetPropGetters=()=>se(ke()),exports.useContextDays=()=>le(ke()),exports.useContextDaysPropGetters=()=>de(ke()),exports.useContextMonths=()=>ue(ke()),exports.useContextMonthsPropGetters=()=>fe(ke()),exports.useContextTime=()=>De(ke()),exports.useContextTimePropGetters=()=>ge(ke()),exports.useContextYears=()=>pe(ke()),exports.useContextYearsPropGetters=()=>he(ke()),exports.useDatePicker=ye,exports.useDatePickerContext=()=>e.useContext(Ce),exports.useDatePickerOffsetPropGetters=se,exports.useDatePickerState=ce,exports.useDatePickerStateContext=ke,exports.useDays=le,exports.useDaysPropGetters=de,exports.useMonths=ue,exports.useMonthsPropGetters=fe,exports.useTime=De,exports.useTimePropGetter=ge,exports.useYears=pe,exports.useYearsPropGetters=he; | ||
//# 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:l}=s(e),d="date"===n?l+t:"month"===n&&l>r(a(o,c+t,1))?r(a(o,c+t,1)):l;return a(o+("year"===n?t:0),c+("month"===n?t:0),d)},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,t,s,n)=>n&&null!=n.h&&null!=n.m?a(e,t,s,n.h,n.m):void 0,f=(e,{locale:t,hour:a,minute:s,second:n,hour12:o})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:n,hour12:o}),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),h=(e,t,a)=>{let[s,n]=[e,t];return e&&t&&([s,n]=[e,t].sort(a)),[s,n]},y=(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 C(e,t){return(n(e)+7-t)%7}const b=(e,t)=>+e==+t,p=(e,t)=>e<t,x=(e,t)=>e>t,k=(e,t,a)=>x(t,e)&&p(t,a)||p(t,e)&&x(t,a),Y=(e,t)=>!!e&&x(t,e),M=(e,t)=>!!e&&p(t,e),v=(e,t)=>e.some((e=>b(o(e),o(t)))),P=(e,t)=>!!t&&e<s(t).M,T=(e,t)=>!!t&&e<s(t).Y,E=(e,t)=>!!t&&e>s(t).M,$=(e,t)=>!!t&&e>s(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",R="will-be-range-start",F="will-be-range-end",L=(e,t,a,s)=>{if(!B(s)||0===a.length)return"";const[n,r]=a;return n&&r?b(e,o(n))?b(o(n),o(r))?`${_} ${I}`:_:b(e,o(r))?I:k(o(n),e,o(r))?"in-range":"":!r&&t?k(o(n),e,t)?"will-be-in-range":p(t,o(n))?b(e,t)?R:b(e,o(n))?F:"":b(e,o(n))?R:b(e,t)?F:"":""},N=(e,t,n,{rangeEnd:c},l)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:h}=l,{locale:p,day:x,year:k}=D,{M:P,Y:T}=s(t),{start:E,length:$}=function(e,t,{mode:s,startDay:n}){const o=a(t,e,1),c=r(o),l=C(o,n);return{start:l,length:"static"===s?42:l+c+6-C(a(t,e,c),n)}}(P,T,g),w=Array($).fill(0).map(((t,r)=>{const l=a(T,P,r+1-E);return{$date:l,active:b(e,l),day:d(l,p,{day:x}),now:b(o(a()),l),range:L(l,c,n,u),disabled:M(f,l)||Y(m,l)||y(l,h),selected:v(n,l),inCurrentMonth:s(l).M===P}}));return{year:d(t,p,{year:k}),month:i(t,D),days:w}};function j({days:e},{locale:{locale:t,weekday:a}}){return[0,1,2,3,4,5,6].map((s=>d(e[s].$date,t,{weekday:a})))}const q=e=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((n=>N(s,c(s,n,"month"),e,t,a))))(e);return t.useMemo((()=>({calendars:a,weekDays:j(a[0],e.config)})),[a,e.config])},H=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),U=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";function 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}}function Z(e,t){e({type:K,date:t})}function ee(e,t){e({type:V,date:t})}function te(e,t){e({type:W,year:t})}const ae=({dispatch:e,config:{onOffsetChange:t,offsetDate:a}})=>s=>{t||a||function(e,t){e({type:Q,date:t})}(e,s),t&&t(s)},se=(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},ne=e=>{const{config:{dates:a}}=e,{minDate:s,maxDate:n}=a,o=t.useCallback(((t,{disabled:a,onClick:s,...o}={})=>{const r=se(e.offsetDate,t),c=!!a||Y(n,r);return J(c,(t=>H(s,U(ae(e)))(t,r)),o)}),[n,e]),r=t.useCallback((({days:t=0,months:a=0,years:n=0},{disabled:o,onClick:r,...c}={})=>{const l={days:-t,months:-a,years:-n},d=se(e.offsetDate,l),i=!!o||M(s,d);return J(i,(t=>H(r,U(ae(e)))(t,d)),c)}),[s,e]);return{addOffset:o,setOffset:t.useCallback(((t,{disabled:a,onClick:o,...r}={})=>{const c=!!a||M(s,t)||Y(n,t);return J(c,(a=>H(o,U(ae(e)))(a,t)),r)}),[e,n,s]),subtractOffset:r}},oe=e=>"exact"===e,re=(e,{mode:t,numberOfYears:a})=>oe(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),ce=e=>{const{selectedDates:t,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:l},years:d}=e,i=n||(t.length>0?t[t.length-1]:((e,t,a)=>Y(t,a)?t:M(e,a)?e:a)(c,l,o(a())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:re(s(i).Y,d)}},le=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:y=[],...C}=r,{minTime:b,maxTime:p,...x}=i,[k,Y]=h(m,D,l),[M,P]=h(b,p,((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,...C,offsets:w.offsets.concat(y)},years:{...O,...f},dates:{...G,...g,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...A,...d},time:{...S,minTime:M,maxTime:P,...x},exclude:u}}(e),[s,n]=t.useReducer(X,ce(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})=>d(e,t,a))(e,a)))})),[e,a]),ie=({config:e,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:l}}=e;return{dayButton:t.useCallback((({$date:t,selected:d,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>J(i||!!m,(i=>{(!d||c||(a.forEach((e=>{b(o(e),t)&&Z(s,e)})),B(r)&&l))&&(B(r)&&1===a.length&&ee(s,null),H(f,U((t=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&v(e,t)?e.filter((e=>!b(o(e),t))):"multiple"===a?!n||e.length<n?g(e,t):e:B(a)?2===e.length?[t]:g(e,t):[t])(a,t,e.dates);Z(s,v(r,t)?t:void 0),n(r)})))(i,t))}),{...D,...B(r)&&1===a.length&&{onMouseEnter(){ee(s,t)}},tabIndex:u?0:-1},d)),[r,c,e.dates,n,a,s,l])}};function ue(e,t,n,{minDate:o,maxDate:r}){const{M:c,Y:l}=s(e),{Y:d,M:u}=s(a());return Array(12).fill(0).map(((e,f)=>{const m=a(l,f,1);return{$date:m,month:i(m,n),selected:t.some((e=>{const{M:t,Y:a}=s(e);return a===l&&t===f})),active:c===f,now:f===u&&l===d,disabled:P(f,o)||T(l,o)||E(f,r)||$(l,r)}}))}const fe=({selectedDates:e,offsetDate:a,config:{locale:s,dates:n}})=>t.useMemo((()=>({months:ue(a,e,s,n)})),[n,s,a,e]),me=e=>({monthButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>J(!!r||a,(a=>H(o,U(ae(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e])}),De=(e,{time:t,locale:n})=>{const o=a(),{interval:r,minTime:c,maxTime:l,useLocales:d}=t,{Y:i,M:m,D:g}=s(e||o),h=1440/r,y=u(i,m,g,c),C=u(i,m,g,l);return Array(h).fill(0).map(((t,s)=>{const c=a(i,m,g,0,s*r);return{$date:c,disabled:!e||M(y,c)||Y(C,c),now:b(c,o),selected:!!e&&b(e,c),time:d?f(c,n):D(c,n)}}))},ge=({state:{focusDate:e},config:a})=>t.useMemo((()=>({time:De(e,a)})),[e,a]),he=({selectedDates:e,state:{focusDate:a},config:{onDatesChange:s},dispatch:n})=>({timeButton:t.useCallback((({$date:t,selected:o,disabled:r,now:c},{onClick:l,disabled:d,...i}={})=>J(r||!!d,(r=>{o||H(l,U((t=>{const o=e.map((e=>b(a,e)?t:e));Z(n,t),s(o)})))(r,t)}),{...i,tabIndex:o||c?0:-1},o)),[e,s,n,a])}),ye=(e,t,n,{numberOfYears:o},{minDate:r,maxDate:c})=>{const{Y:l,M:d,D:i}=s(t),{Y:u}=s(a());return Array(o).fill(0).map(((t,o)=>{const f=e+o;return{$date:a(f,d,i),active:l===f,disabled:T(f,r)||$(f,c),now:f===u,selected:n.some((e=>s(e).Y===f)),year:f}}))},Ce=({selectedDates:e,state:{offsetDate:a,offsetYear:s},config:{years:n,dates:o}})=>t.useMemo((()=>({years:ye(s,a,e,n,o)})),[a,s,e,n,o]),be=e=>{const{state:{offsetYear:n,offsetDate:o},config:{dates:r,years:c},dispatch:l}=e,{minDate:d,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}={})=>J(!!r||a,(a=>H(o,U(ae(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||Y(i,o)||oe(m)&&!!i&&b(i,o);return J(r,(t=>H(e,z((()=>te(l,n+u))))(t)),s)}),[i,l,n,u,D,g,f,m]),previousYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=!!t||M(d,a(n,g,D));return J(o,(t=>H(e,z((()=>te(l,n-u))))(t)),s)}),[d,l,n,u,g,D])}},pe=e=>{const t=le(e);return{data:{...q(t),...de(t),...fe(t),...ge(t),...Ce(t)},propGetters:{...ie(t),...me(t),...he(t),...be(t),...ne(t)}}};var xe=t.createContext({});var ke=t.createContext({}),Ye=()=>t.useContext(ke);e.DatePickerProvider=function({children:e,config:a}){return t.createElement(xe.Provider,{value:pe(a)},e)},e.DatePickerStateProvider=function({children:e,config:a}){return t.createElement(ke.Provider,{value:le(a)},e)},e.useCalendars=q,e.useContextCalendars=()=>q(Ye()),e.useContextDatePickerOffsetPropGetters=()=>ne(Ye()),e.useContextDays=()=>de(Ye()),e.useContextDaysPropGetters=()=>ie(Ye()),e.useContextMonths=()=>fe(Ye()),e.useContextMonthsPropGetters=()=>me(Ye()),e.useContextTime=()=>ge(Ye()),e.useContextTimePropGetters=()=>he(Ye()),e.useContextYears=()=>Ce(Ye()),e.useContextYearsPropGetters=()=>be(Ye()),e.useDatePicker=pe,e.useDatePickerContext=()=>t.useContext(xe),e.useDatePickerOffsetPropGetters=ne,e.useDatePickerState=le,e.useDatePickerStateContext=Ye,e.useDays=de,e.useDaysPropGetters=ie,e.useMonths=fe,e.useMonthsPropGetters=me,e.useTime=ge,e.useTimePropGetter=he,e.useYears=Ce,e.useYearsPropGetters=be})); | ||
!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:l}=s(e),d="date"===n?l+t:"month"===n&&l>r(a(o,c+t,1))?r(a(o,c+t,1)):l;return a(o+("year"===n?t:0),c+("month"===n?t:0),d)},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,t,s,n)=>n&&null!=n.h&&null!=n.m?a(e,t,s,n.h,n.m):void 0,f=(e,{locale:t,hour:a,minute:s,second:n,hour12:o})=>e.toLocaleTimeString(t,{hour:a,minute:s,second:n,hour12:o}),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),h=(e,t,a)=>{let[s,n]=[e,t];return e&&t&&([s,n]=[e,t].sort(a)),[s,n]},y=(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 C(e,t){return(n(e)+7-t)%7}const b=(e,t)=>+e==+t,p=(e,t)=>e<t,x=(e,t)=>e>t,k=(e,t,a)=>x(t,e)&&p(t,a)||p(t,e)&&x(t,a),Y=(e,t)=>!!e&&x(t,e),M=(e,t)=>!!e&&p(t,e),v=(e,t)=>e.some((e=>b(o(e),o(t)))),P=(e,t)=>!!t&&e<s(t).M,T=(e,t)=>!!t&&e<s(t).Y,E=(e,t)=>!!t&&e>s(t).M,$=(e,t)=>!!t&&e>s(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",R="will-be-range-start",F="will-be-range-end",L=(e,t,a,s)=>{if(!B(s)||0===a.length)return"";const[n,r]=a;return n&&r?b(e,o(n))?b(o(n),o(r))?`${_} ${I}`:_:b(e,o(r))?I:k(o(n),e,o(r))?"in-range":"":!r&&t?k(o(n),e,t)?"will-be-in-range":p(t,o(n))?b(e,t)?R:b(e,o(n))?F:"":b(e,o(n))?R:b(e,t)?F:"":""},N=(e,t,n,{rangeEnd:c},l)=>{const{dates:{mode:u,minDate:f,maxDate:m},locale:D,calendar:g,exclude:h}=l,{locale:p,day:x,year:k}=D,{M:P,Y:T}=s(t),{start:E,length:$}=function(e,t,{mode:s,startDay:n}){const o=a(t,e,1),c=r(o),l=C(o,n);return{start:l,length:"static"===s?42:l+c+6-C(a(t,e,c),n)}}(P,T,g),w=Array($).fill(0).map(((t,r)=>{const l=a(T,P,r+1-E);return{$date:l,active:b(e,l),day:d(l,p,{day:x}),now:b(o(a()),l),range:L(l,c,n,u),disabled:M(f,l)||Y(m,l)||y(l,h),selected:v(n,l),inCurrentMonth:s(l).M===P}}));return{year:d(t,p,{year:k}),month:i(t,D),days:w}};var j=({days:e},{locale:{locale:t,weekday:a}})=>[0,1,2,3,4,5,6].map((s=>d(e[s].$date,t,{weekday:a})));const q=e=>{const a=(({selectedDates:e,state:t,config:a,offsetDate:s})=>a.calendar.offsets.map((n=>N(s,c(s,n,"month"),e,t,a))))(e);return t.useMemo((()=>({calendars:a,weekDays:j(a[0],e.config)})),[a,e.config])},H=(...e)=>(...t)=>e.forEach((e=>null==e?void 0:e(...t))),U=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 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},ne=e=>{const{config:{dates:a}}=e,{minDate:s,maxDate:n}=a,o=t.useCallback(((t,{disabled:a,onClick:s,...o}={})=>{const r=se(e.offsetDate,t),c=!!a||Y(n,r);return J(c,(t=>H(s,U(ae(e)))(t,r)),o)}),[n,e]),r=t.useCallback((({days:t=0,months:a=0,years:n=0},{disabled:o,onClick:r,...c}={})=>{const l={days:-t,months:-a,years:-n},d=se(e.offsetDate,l),i=!!o||M(s,d);return J(i,(t=>H(r,U(ae(e)))(t,d)),c)}),[s,e]);return{addOffset:o,setOffset:t.useCallback(((t,{disabled:a,onClick:o,...r}={})=>{const c=!!a||M(s,t)||Y(n,t);return J(c,(a=>H(o,U(ae(e)))(a,t)),r)}),[e,n,s]),subtractOffset:r}},oe=e=>"exact"===e,re=(e,{mode:t,numberOfYears:a})=>oe(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),ce=e=>{const{selectedDates:t,offsetDate:n,focusDate:r,dates:{minDate:c,maxDate:l},years:d}=e,i=n||(t.length>0?t[t.length-1]:((e,t,a)=>Y(t,a)?t:M(e,a)?e:a)(c,l,o(a())));return{focusDate:r,rangeEnd:null,offsetDate:i,offsetYear:re(s(i).Y,d)}},le=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:y=[],...C}=r,{minTime:b,maxTime:p,...x}=i,[k,Y]=h(m,D,l),[M,P]=h(b,p,((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,...C,offsets:w.offsets.concat(y)},years:{...O,...f},dates:{...G,...g,minDate:k&&o(k),maxDate:Y&&o(Y)},locale:{...A,...d},time:{...S,minTime:M,maxTime:P,...x},exclude:u}}(e),[s,n]=t.useReducer(X,ce(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})=>d(e,t,a))(e,a)))})),[e,a]),ie=({config:e,selectedDates:a,dispatch:s})=>{const{onDatesChange:n,dates:{mode:r,toggle:c,selectSameDate:l}}=e;return{dayButton:t.useCallback((({$date:t,selected:d,disabled:i,active:u},{onClick:f,disabled:m,...D}={})=>J(i||!!m,(i=>{(!d||c||(a.forEach((e=>{b(o(e),t)&&Z(s,e)})),B(r)&&l))&&(B(r)&&1===a.length&&ee(s,null),H(f,U((t=>{const r=((e,t,{mode:a,toggle:s,limit:n})=>s&&v(e,t)?e.filter((e=>!b(o(e),t))):"multiple"===a?!n||e.length<n?g(e,t):e:B(a)?2===e.length?[t]:g(e,t):[t])(a,t,e.dates);Z(s,v(r,t)?t:void 0),n(r)})))(i,t))}),{...D,...B(r)&&1===a.length&&{onMouseEnter(){ee(s,t)}},tabIndex:u?0:-1},d)),[r,c,e.dates,n,a,s,l])}};var ue=(e,t,n,{minDate:o,maxDate:r})=>{const{M:c,Y:l}=s(e),{Y:d,M:u}=s(a());return Array(12).fill(0).map(((e,f)=>{const m=a(l,f,1);return{$date:m,month:i(m,n),selected:t.some((e=>{const{M:t,Y:a}=s(e);return a===l&&t===f})),active:c===f,now:f===u&&l===d,disabled:P(f,o)||T(l,o)||E(f,r)||$(l,r)}}))};const fe=({selectedDates:e,offsetDate:a,config:{locale:s,dates:n}})=>t.useMemo((()=>({months:ue(a,e,s,n)})),[n,s,a,e]),me=e=>({monthButton:t.useCallback((({$date:t,disabled:a,selected:s,active:n},{onClick:o,disabled:r,...c}={})=>J(!!r||a,(a=>H(o,U(ae(e)))(a,t)),{...c,tabIndex:n?0:-1},s)),[e])});var De=(e,{time:t,locale:n})=>{const o=a(),{interval:r,minTime:c,maxTime:l,useLocales:d}=t,{Y:i,M:m,D:g}=s(e||o),h=1440/r,y=u(i,m,g,c),C=u(i,m,g,l);return Array(h).fill(0).map(((t,s)=>{const c=a(i,m,g,0,s*r);return{$date:c,disabled:!e||M(y,c)||Y(C,c),now:b(c,o),selected:!!e&&b(e,c),time:d?f(c,n):D(c,n)}}))};const ge=({state:{focusDate:e},config:a})=>t.useMemo((()=>({time:De(e,a)})),[e,a]),he=({selectedDates:e,state:{focusDate:a},config:{onDatesChange:s},dispatch:n})=>({timeButton:t.useCallback((({$date:t,selected:o,disabled:r,now:c},{onClick:l,disabled:d,...i}={})=>J(r||!!d,(r=>{o||H(l,U((t=>{const o=e.map((e=>b(a,e)?t:e));Z(n,t),s(o)})))(r,t)}),{...i,tabIndex:o||c?0:-1},o)),[e,s,n,a])}),ye=(e,t,n,{numberOfYears:o},{minDate:r,maxDate:c})=>{const{Y:l,M:d,D:i}=s(t),{Y:u}=s(a());return Array(o).fill(0).map(((t,o)=>{const f=e+o;return{$date:a(f,d,i),active:l===f,disabled:T(f,r)||$(f,c),now:f===u,selected:n.some((e=>s(e).Y===f)),year:f}}))},Ce=({selectedDates:e,state:{offsetDate:a,offsetYear:s},config:{years:n,dates:o}})=>t.useMemo((()=>({years:ye(s,a,e,n,o)})),[a,s,e,n,o]),be=e=>{const{state:{offsetYear:n,offsetDate:o},config:{dates:r,years:c},dispatch:l}=e,{minDate:d,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}={})=>J(!!r||a,(a=>H(o,U(ae(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||Y(i,o)||oe(m)&&!!i&&b(i,o);return J(r,(t=>H(e,z((()=>te(l,n+u))))(t)),s)}),[i,l,n,u,D,g,f,m]),previousYearsButton:t.useCallback((({onClick:e,disabled:t,...s}={})=>{const o=!!t||M(d,a(n,g,D));return J(o,(t=>H(e,z((()=>te(l,n-u))))(t)),s)}),[d,l,n,u,g,D])}},pe=e=>{const t=le(e);return{data:{...q(t),...de(t),...fe(t),...ge(t),...Ce(t)},propGetters:{...ie(t),...me(t),...he(t),...be(t),...ne(t)}}};var xe=t.createContext({}),ke=t.createContext({}),Ye=()=>t.useContext(ke);e.DatePickerProvider=({children:e,config:a})=>t.createElement(xe.Provider,{value:pe(a)},e),e.DatePickerStateProvider=({children:e,config:a})=>t.createElement(ke.Provider,{value:le(a)},e),e.useCalendars=q,e.useContextCalendars=()=>q(Ye()),e.useContextDatePickerOffsetPropGetters=()=>ne(Ye()),e.useContextDays=()=>de(Ye()),e.useContextDaysPropGetters=()=>ie(Ye()),e.useContextMonths=()=>fe(Ye()),e.useContextMonthsPropGetters=()=>me(Ye()),e.useContextTime=()=>ge(Ye()),e.useContextTimePropGetters=()=>he(Ye()),e.useContextYears=()=>Ce(Ye()),e.useContextYearsPropGetters=()=>be(Ye()),e.useDatePicker=pe,e.useDatePickerContext=()=>t.useContext(xe),e.useDatePickerOffsetPropGetters=ne,e.useDatePickerState=le,e.useDatePickerStateContext=Ye,e.useDays=de,e.useDaysPropGetters=ie,e.useMonths=fe,e.useMonthsPropGetters=me,e.useTime=ge,e.useTimePropGetter=he,e.useYears=Ce,e.useYearsPropGetters=be})); | ||
//# sourceMappingURL=index.umd.js.map |
import { Dispatch } from 'react'; | ||
import type { DPReducerAction, DPReducerState, DPSetFocusDate, DPSetOffsetDate, DPSetRangeEndAction, DPSetYearAction } from './types'; | ||
export declare function stateReducer(state: DPReducerState, action: DPReducerAction): DPReducerState; | ||
export declare function setFocus(dispatch: Dispatch<DPSetFocusDate>, date: DPReducerState['focusDate']): void; | ||
export declare function setOffset(dispatch: Dispatch<DPSetOffsetDate>, date: Date): void; | ||
export declare function setRangeEnd(dispatch: Dispatch<DPSetRangeEndAction>, date: DPReducerState['rangeEnd']): void; | ||
export declare function setYear(dispatch: Dispatch<DPSetYearAction>, year: number): void; | ||
export declare var stateReducer: (state: DPReducerState, action: DPReducerAction) => DPReducerState; | ||
export declare var setFocus: (dispatch: Dispatch<DPSetFocusDate>, date: DPReducerState['focusDate']) => void; | ||
export declare var setOffset: (dispatch: Dispatch<DPSetOffsetDate>, date: Date) => void; | ||
export declare var setRangeEnd: (dispatch: Dispatch<DPSetRangeEndAction>, date: DPReducerState['rangeEnd']) => void; | ||
export declare var setYear: (dispatch: Dispatch<DPSetYearAction>, year: number) => void; | ||
//# sourceMappingURL=state-reducer.d.ts.map |
import type { DPDatesConfig, DPLocaleConfig, DPMonth } from '../types'; | ||
export declare function createMonths(offsetDate: Date, selectedDates: Date[], locale: DPLocaleConfig, { minDate, maxDate }: DPDatesConfig): DPMonth[]; | ||
export declare var createMonths: (offsetDate: Date, selectedDates: Date[], locale: DPLocaleConfig, { minDate, maxDate }: DPDatesConfig) => DPMonth[]; | ||
//# sourceMappingURL=create-months.d.ts.map |
import type { DPConfig, DPTime } from '../types'; | ||
export declare const createTime: (d: Date | undefined, { time, locale }: DPConfig) => DPTime[]; | ||
export declare var createTime: (d: Date | undefined, { time, locale }: DPConfig) => DPTime[]; | ||
//# sourceMappingURL=create-time.d.ts.map |
import type { DPCalendar, DPConfig } from '../types'; | ||
export declare function createWeekdays({ days }: DPCalendar, { locale: { locale, weekday } }: DPConfig): string[]; | ||
export declare var createWeekdays: ({ days }: DPCalendar, { locale: { locale, weekday } }: DPConfig) => string[]; | ||
//# sourceMappingURL=create-weekdays.d.ts.map |
{ | ||
"name": "@rehookify/datepicker", | ||
"version": "6.5.0", | ||
"version": "6.5.1", | ||
"description": "The ultimate tool to create a date, range and time picker in your React applications.", | ||
@@ -63,4 +63,4 @@ "main": "dist/index.cjs.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.23.3", | ||
"@babel/preset-env": "^7.23.3", | ||
"@babel/core": "^7.23.9", | ||
"@babel/preset-env": "^7.23.9", | ||
"@babel/preset-typescript": "^7.23.3", | ||
@@ -70,11 +70,11 @@ "@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@testing-library/react": "^14.1.2", | ||
"@types/react": "^18.2.39", | ||
"jsdom": "^23.0.0", | ||
"@testing-library/react": "^14.2.1", | ||
"@types/react": "^18.2.55", | ||
"jsdom": "^24.0.0", | ||
"react": "^18.2.0", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.6.0", | ||
"rollup": "^4.10.0", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"rollup-plugin-typescript2": "^0.36.0", | ||
"vitest": "^0.34.6" | ||
"vitest": "^1.2.2" | ||
}, | ||
@@ -81,0 +81,0 @@ "peerDependencies": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
280414
96
1141