react-select-datepicker 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{__rest as e,__assign as a}from"../_virtual/_tslib.js";import t,{useState as n,useMemo as r,useRef as o,useEffect as l,useCallback as i}from"react";import{classPrefix as c}from"../utils/helpers.js";import{getCachedYearsObject as s,getCachedMonthsObject as u,getCachedDaysObject as d}from"../utils/performance.js";import{normalizeToLocalMidnight as m,isValidDate as f,createSmartDate as v}from"../utils/dateUtils.js";import{isValidOrder as h,isDate as p,validateDateRange as b,isDateInRange as g}from"../utils/validation.js";import{useFocusManagement as y,useKeyboardNavigation as D}from"../hooks/useKeyboardNavigation.js";import{OptionsRenderer as L}from"./OptionsRenderer.js";import{SelectDatepickerContext as E}from"./SelectDatepickerContext.js";import{SelectDatepickerField as k}from"./SelectDatepickerField.js";import"./SelectDatepicker.css.js";var w=function(w){var N=w.id,C=w.className,S=w.minDate,j=w.maxDate,R=w.selectedDate,_=w.onDateChange,x=w.value,P=w.onChange,O=w.disabled,B=void 0!==O&&O,F=w.hasError,K=void 0!==F&&F,M=w.monthRef,Y=w.yearRef,I=w.dayRef,A=w.labels,U=void 0===A?{}:A,V=w.order,q=void 0===V?"month/day/year":V,z=w.reverseYears,G=w.hideLabels,H=e(w,["id","className","minDate","maxDate","selectedDate","onDateChange","value","onChange","disabled","hasError","monthRef","yearRef","dayRef","labels","order","reverseYears","hideLabels"]),J=n(-1),Q=J[0],T=J[1],W=n(-1),X=W[0],Z=W[1],$=n(-1),ee=$[0],ae=$[1],te=r(function(){return q&&h(q)?q:"month/day/year"},[q]),ne=r(function(){return te.split("/")},[te]),re=o("datepicker-".concat(Math.random().toString(36).substr(2,9))),oe=N||re.current,le=r(function(){var e={};return ne.forEach(function(a){e[a]="".concat(c,"_select-").concat(a,"-").concat(oe)}),e},[ne,oe]),ie=y(ne.map(function(e){return le[e]})),ce=D({onArrowKey:function(e){"right"===e||"down"===e?ie.focusNext():"left"!==e&&"up"!==e||ie.focusPrevious()},enabled:!B}).addKeyboardNavigation;l(function(){var e=[];return ne.forEach(function(a){var t=document.getElementById(le[a]);if(t){var n=ce(t);n&&e.push(n)}}),function(){e.forEach(function(e){return e()})}},[ne,le,ce]);var se=r(function(){return["".concat(c,"_react-select-datepicker"),C].join(" ")},[C]),ue=r(function(){return void 0!==x?x:R},[x,R]),de=r(function(){return null!=P?P:_},[P,_]);l(function(){if("production"!==process.env.NODE_ENV&&(q&&!h(q)&&console.warn('[SelectDatepicker] Invalid order "'.concat(q,'". Falling back to "month/day/year".')),P&&_&&console.warn("[SelectDatepicker] Both onChange and onDateChange provided. onChange will be used."),void 0!==x&&void 0!==R&&console.warn("[SelectDatepicker] Both value and selectedDate provided. value will be used."),de||console.warn("[SelectDatepicker] Missing onChange/onDateChange handler."),S&&!p(S)&&console.warn("[SelectDatepicker] minDate is not a valid Date instance."),j&&!p(j)&&console.warn("[SelectDatepicker] maxDate is not a valid Date instance."),S&&j&&p(S)&&p(j)&&!b(S,j)&&console.warn("[SelectDatepicker] minDate is after maxDate. Range constraints ignored."),null==R||p(R)||console.warn("[SelectDatepicker] selectedDate is not a valid Date instance."),null==U?void 0:U.months)){var e=U.months,a=Array.from({length:12},function(e,a){return a+1}).filter(function(a){return void 0===e[a]});if(a.length>0){var t=a.join(", ");console.warn("[SelectDatepicker] labels.months is missing entries for months: ".concat(t,"."))}}},[q,S,j,R,U,P,_,x,de]);var me=r(function(){return p(S)?m(S):void 0},[S]),fe=r(function(){return p(j)?m(j):void 0},[j]),ve=r(function(){return b(me,fe)},[me,fe]),he=ve?me:void 0,pe=ve?fe:void 0,be=r(function(){return t.createElement(L,{options:s(he,pe,z)})},[pe,he,z]),ge=r(function(){return t.createElement(L,{options:u(he,pe,Q,U.months)})},[pe,he,U.months,Q]),ye=r(function(){return t.createElement(L,{options:d(he,pe,X,Q)})},[pe,he,X,Q]),De=i(function(e){var a=Number(e.target.value);T(a),u(he,pe,a,U.months).some(function(e){return e.value===X})||Z(-1)},[X,he,pe,U.months]),Le=i(function(e){var a=Number(e.target.value);Z(a)},[]),Ee=i(function(e){ae(Number(e.target.value))},[]),ke=r(function(){return{baseId:oe,labels:U,hideLabels:G,disabled:B,hasError:K,day:ee,month:X,year:Q,dayOptions:ye,monthOptions:ge,yearOptions:be,dayRef:I,monthRef:M,yearRef:Y,onDayChange:Ee,onMonthChange:Le,onYearChange:De}},[oe,U,G,B,K,ee,X,Q,ye,ge,be,I,M,Y,Ee,Le,De]);l(function(){null!=ue&&p(ue)&&f(ue)?(ae(Number(ue.getDate())),Z(Number(ue.getMonth()+1)),T(Number(ue.getFullYear()))):(ae(-1),Z(-1),T(-1))},[ue]),l(function(){if(-1!==Q&&-1!==X&&-1!==ee){var e=v(Q,X,ee);g(e,he,pe)?null==de||de(e):null==de||de(null)}else null==de||de(null)},[ee,X,Q,de,he,pe]);var we=r(function(){var e,a,t;if(!K)return null;if(-1===ee&&-1===X&&-1===Q)return"Please select a date";var n=[];return-1===ee&&n.push((null===(e=U.dayLabel)||void 0===e?void 0:e.toLowerCase())||"day"),-1===X&&n.push((null===(a=U.monthLabel)||void 0===a?void 0:a.toLowerCase())||"month"),-1===Q&&n.push((null===(t=U.yearLabel)||void 0===t?void 0:t.toLowerCase())||"year"),1===n.length?"Please select a ".concat(n[0]):2===n.length?"Please select a ".concat(n[0]," and ").concat(n[1]):"Please select all date fields"},[K,ee,X,Q,U.dayLabel,U.monthLabel,U.yearLabel]),Ne="".concat(N||oe,"-legend"),Ce=Boolean(U.groupLabel||!G),Se=U.groupLabel?U.groupLabel:U.yearLabel&&U.monthLabel&&U.dayLabel?"Select ".concat(U.monthLabel,", ").concat(U.dayLabel,", and ").concat(U.yearLabel):"Select date";return t.createElement("div",a({},H,{className:se,id:N,role:"group","aria-labelledby":Ce?Ne:void 0,"aria-describedby":we?"".concat(N||oe,"-error"):void 0,"aria-invalid":K}),Ce&&t.createElement("label",{id:Ne,className:"".concat(c,"_legend")},Se),t.createElement(E.Provider,{value:ke},t.createElement("div",{className:"".concat(c,"_select-row")},ne.map(function(e,a){var n=e;return t.createElement(t.Fragment,{key:"".concat(e,"-").concat(a)},t.createElement(k,{fieldKey:n}))}))),we&&t.createElement("div",{id:"".concat(N||oe,"-error"),className:"".concat(c,"_error-message"),role:"alert","aria-live":"polite"},we))};export{w as SelectDatepicker};
1
+ import{__rest as e,__assign as t}from"../_virtual/_tslib.js";import n,{useState as a,useRef as r,useMemo as o,useEffect as l,useCallback as i}from"react";import{classPrefix as c}from"../utils/helpers.js";import{getCachedYearsObject as s,getCachedMonthsObject as u,getCachedDaysObject as d}from"../utils/performance.js";import{normalizeToLocalMidnight as m,isValidDate as f,createSmartDate as v}from"../utils/dateUtils.js";import{isValidOrder as h,isDate as p,validateDateRange as g,isDateInRange as b}from"../utils/validation.js";import{useFocusManagement as y,useKeyboardNavigation as D}from"../hooks/useKeyboardNavigation.js";import{OptionsRenderer as L}from"./OptionsRenderer.js";import{SelectDatepickerContext as E}from"./SelectDatepickerContext.js";import{SelectDatepickerField as k}from"./SelectDatepickerField.js";import"./SelectDatepicker.css.js";var w=function(w){var N=w.id,C=w.className,S=w.minDate,j=w.maxDate,R=w.selectedDate,_=w.onDateChange,x=w.value,P=w.onChange,F=w.disabled,M=void 0!==F&&F,O=w.hasError,Y=void 0!==O&&O,B=w.monthRef,K=w.yearRef,I=w.dayRef,T=w.labels,A=void 0===T?{}:T,U=w.order,V=void 0===U?"month/day/year":U,q=w.reverseYears,z=w.hideLabels,G=e(w,["id","className","minDate","maxDate","selectedDate","onDateChange","value","onChange","disabled","hasError","monthRef","yearRef","dayRef","labels","order","reverseYears","hideLabels"]),H=a(-1),J=H[0],Q=H[1],W=a(-1),X=W[0],Z=W[1],$=a(-1),ee=$[0],te=$[1],ne=r(!1),ae=r(void 0),re=o(function(){return V&&h(V)?V:"month/day/year"},[V]),oe=o(function(){return re.split("/")},[re]),le=r("datepicker-".concat(Math.random().toString(36).substr(2,9))),ie=N||le.current,ce=o(function(){var e={};return oe.forEach(function(t){e[t]="".concat(c,"_select-").concat(t,"-").concat(ie)}),e},[oe,ie]),se=y(oe.map(function(e){return ce[e]})),ue=D({onArrowKey:function(e){"right"===e||"down"===e?se.focusNext():"left"!==e&&"up"!==e||se.focusPrevious()},enabled:!M}).addKeyboardNavigation;l(function(){var e=[];return oe.forEach(function(t){var n=document.getElementById(ce[t]);if(n){var a=ue(n);a&&e.push(a)}}),function(){e.forEach(function(e){return e()})}},[oe,ce,ue]);var de=o(function(){return["".concat(c,"_react-select-datepicker"),C].join(" ")},[C]),me=o(function(){return void 0!==x?x:R},[x,R]),fe=o(function(){return null!=P?P:_},[P,_]);l(function(){if("production"!==process.env.NODE_ENV&&(V&&!h(V)&&console.warn('[SelectDatepicker] Invalid order "'.concat(V,'". Falling back to "month/day/year".')),P&&_&&console.warn("[SelectDatepicker] Both onChange and onDateChange provided. onChange will be used."),void 0!==x&&void 0!==R&&console.warn("[SelectDatepicker] Both value and selectedDate provided. value will be used."),fe||console.warn("[SelectDatepicker] Missing onChange/onDateChange handler."),S&&!p(S)&&console.warn("[SelectDatepicker] minDate is not a valid Date instance."),j&&!p(j)&&console.warn("[SelectDatepicker] maxDate is not a valid Date instance."),S&&j&&p(S)&&p(j)&&!g(S,j)&&console.warn("[SelectDatepicker] minDate is after maxDate. Range constraints ignored."),null==R||p(R)||console.warn("[SelectDatepicker] selectedDate is not a valid Date instance."),null==A?void 0:A.months)){var e=A.months,t=Array.from({length:12},function(e,t){return t+1}).filter(function(t){return void 0===e[t]});if(t.length>0){var n=t.join(", ");console.warn("[SelectDatepicker] labels.months is missing entries for months: ".concat(n,"."))}}},[V,S,j,R,A,P,_,x,fe]);var ve=o(function(){return p(S)?m(S):void 0},[S]),he=o(function(){return p(j)?m(j):void 0},[j]),pe=o(function(){return g(ve,he)},[ve,he]),ge=pe?ve:void 0,be=pe?he:void 0,ye=o(function(){return n.createElement(L,{options:s(ge,be,q)})},[be,ge,q]),De=o(function(){return n.createElement(L,{options:u(ge,be,J,A.months)})},[be,ge,A.months,J]),Le=o(function(){return n.createElement(L,{options:d(ge,be,X,J)})},[be,ge,X,J]),Ee=i(function(e){var t=Number(e.target.value);Q(t),u(ge,be,t,A.months).some(function(e){return e.value===X})||Z(-1)},[X,ge,be,A.months]),ke=i(function(e){var t=Number(e.target.value);Z(t)},[]),we=i(function(e){te(Number(e.target.value))},[]),Ne=o(function(){return{baseId:ie,labels:A,hideLabels:z,disabled:M,hasError:Y,day:ee,month:X,year:J,dayOptions:Le,monthOptions:De,yearOptions:ye,dayRef:I,monthRef:B,yearRef:K,onDayChange:we,onMonthChange:ke,onYearChange:Ee}},[ie,A,z,M,Y,ee,X,J,Le,De,ye,I,B,K,we,ke,Ee]);l(function(){var e=me&&p(me)&&f(me)?me.getTime():null;ae.current!==e&&(ae.current=e,null!==e&&me?(ne.current=!0,te(Number(me.getDate())),Z(Number(me.getMonth()+1)),Q(Number(me.getFullYear()))):(ne.current=!0,te(-1),Z(-1),Q(-1)))},[me]),l(function(){if(ne.current){var e=me&&p(me)&&f(me)?me.getFullYear()===J&&me.getMonth()+1===X&&me.getDate()===ee:-1===ee&&-1===X&&-1===J;if(ne.current=!1,e)return}if(-1!==J&&-1!==X&&-1!==ee){var t=v(J,X,ee),n=me&&p(me)&&f(me)?me.getTime():null;if(b(t,ge,be))n!==t.getTime()&&(null==fe||fe(t));else null!==n&&(null==fe||fe(null))}},[ee,X,J,fe,ge,be,me]);var Ce=o(function(){var e,t,n;if(!Y)return null;if(-1===ee&&-1===X&&-1===J)return"Please select a date";var a=[];return-1===ee&&a.push((null===(e=A.dayLabel)||void 0===e?void 0:e.toLowerCase())||"day"),-1===X&&a.push((null===(t=A.monthLabel)||void 0===t?void 0:t.toLowerCase())||"month"),-1===J&&a.push((null===(n=A.yearLabel)||void 0===n?void 0:n.toLowerCase())||"year"),0===a.length?null:1===a.length?"Please select a ".concat(a[0]):2===a.length?"Please select a ".concat(a[0]," and ").concat(a[1]):"Please select all date fields"},[Y,ee,X,J,A.dayLabel,A.monthLabel,A.yearLabel]),Se="".concat(N||ie,"-legend"),je=Boolean(A.groupLabel||!z),Re=A.groupLabel?A.groupLabel:A.yearLabel&&A.monthLabel&&A.dayLabel?"Select ".concat(A.monthLabel,", ").concat(A.dayLabel,", and ").concat(A.yearLabel):"Select date";return n.createElement("div",t({},G,{className:de,id:N,role:"group","aria-labelledby":je?Se:void 0,"aria-describedby":Ce?"".concat(N||ie,"-error"):void 0,"aria-invalid":Y}),je&&n.createElement("label",{id:Se,className:"".concat(c,"_legend")},Re),n.createElement(E.Provider,{value:Ne},n.createElement("div",{className:"".concat(c,"_select-row")},oe.map(function(e,t){var a=e;return n.createElement(n.Fragment,{key:"".concat(e,"-").concat(t)},n.createElement(k,{fieldKey:a}))}))),Ce&&n.createElement("div",{id:"".concat(N||ie,"-error"),className:"".concat(c,"_error-message"),role:"alert","aria-live":"polite"},Ce))};export{w as SelectDatepicker};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-select-datepicker",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "A simple and reusable dropdown datepicker component for React",
5
5
  "author": "JMcAmmond",
6
6
  "license": "MIT",