react-select-datepicker 3.0.0 → 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
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=function(){function e(e){void 0===e&&(e=50),this.cache=new Map,this.maxSize=e}return e.prototype.get=function(e){var t=this.cache.get(e);return void 0!==t&&(this.cache.delete(e),this.cache.set(e,t)),t},e.prototype.set=function(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.maxSize){var n=this.cache.keys().next().value;void 0!==n&&this.cache.delete(n)}this.cache.set(e,t)},e.prototype.clear=function(){this.cache.clear()},e}(),t=new e,n=new e,r=new e,a=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.map(function(e){return String(e||"undefined")}).join("|")},l=function(e,t,n){for(var r=Math.floor((t-e)/n)+1,a=new Array(r),l=0;l<r;l++)a[l]=e+l*n;return a},i=function(e,n,r){var i=a((null==e?void 0:e.getFullYear())||"undefined",(null==n?void 0:n.getFullYear())||(new Date).getFullYear(),r||!1),u=t.get(i);if(u)return u;var o=n?n.getFullYear():(new Date).getFullYear(),c=e?e.getFullYear():1900,h=l(o,c,-1);r&&(h=h.reverse()),u=new Array(h.length);for(var v=0;v<h.length;v++)u[v]={value:h[v],label:"".concat(h[v])};return t.set(i,u),u},u=function(e,t,r,i){void 0===r&&(r=-1),void 0===i&&(i={1:"January",2:"February",3:"March",4:"April",5:"May",6:"June",7:"July",8:"August",9:"September",10:"October",11:"November",12:"December"});var u=a((null==e?void 0:e.getFullYear())||"undefined",(null==t?void 0:t.getFullYear())||"undefined",r,
|
|
1
|
+
var e=function(){function e(e){void 0===e&&(e=50),this.cache=new Map,this.maxSize=e}return e.prototype.get=function(e){var t=this.cache.get(e);return void 0!==t&&(this.cache.delete(e),this.cache.set(e,t)),t},e.prototype.set=function(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.maxSize){var n=this.cache.keys().next().value;void 0!==n&&this.cache.delete(n)}this.cache.set(e,t)},e.prototype.clear=function(){this.cache.clear()},e}(),t=new e,n=new e,r=new e,a=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.map(function(e){return String(e||"undefined")}).join("|")},l=function(e,t,n){for(var r=Math.floor((t-e)/n)+1,a=new Array(r),l=0;l<r;l++)a[l]=e+l*n;return a},i=function(e,n,r){var i=a((null==e?void 0:e.getFullYear())||"undefined",(null==n?void 0:n.getFullYear())||(new Date).getFullYear(),r||!1),u=t.get(i);if(u)return u;var o=n?n.getFullYear():(new Date).getFullYear(),c=e?e.getFullYear():1900,h=l(o,c,-1);r&&(h=h.reverse()),u=new Array(h.length);for(var v=0;v<h.length;v++)u[v]={value:h[v],label:"".concat(h[v])};return t.set(i,u),u},u=function(e,t,r,i){void 0===r&&(r=-1),void 0===i&&(i={1:"January",2:"February",3:"March",4:"April",5:"May",6:"June",7:"July",8:"August",9:"September",10:"October",11:"November",12:"December"});var u=Object.keys(i).sort(function(e,t){return Number(e)-Number(t)}).map(function(e){return"".concat(e,":").concat(i[e])}).join(","),o=a((null==e?void 0:e.getFullYear())||"undefined",(null==t?void 0:t.getFullYear())||"undefined",r,u),c=n.get(o);if(c)return c;var h=l(1,12,1);if(t&&-1!==r&&r===t.getFullYear()){var v=t.getMonth()+1;h=h.slice(0,v)}if(e&&-1!==r&&r===e.getFullYear()){var g=e.getMonth()+1;h=h.slice(g-1,h.length)}c=new Array(h.length);for(var f=0;f<h.length;f++){var d=h[f];c[f]={value:d,label:i[d]||"Month ".concat(d)}}return n.set(o,c),c},o=function(e,t,n,i){void 0===n&&(n=-1),void 0===i&&(i=-1);var u=a((null==e?void 0:e.getFullYear())||"undefined",(null==e?void 0:e.getMonth())||"undefined",(null==t?void 0:t.getFullYear())||"undefined",(null==t?void 0:t.getMonth())||"undefined",n,i),o=r.get(u);if(o)return o;var c=[];if(-1===n)c=l(1,31,1);else{var h=new Date(-1===i?1900:i,n,0).getDate();c=l(1,h,1)}if(t&&i===t.getFullYear()&&n===t.getMonth()+1){var v=t.getDate();c=c.slice(0,v)}if(e&&i===e.getFullYear()&&n===e.getMonth()+1){var g=e.getDate();c=c.slice(g-1,c.length)}o=new Array(c.length);for(var f=0;f<c.length;f++)o[f]={value:c[f],label:"".concat(c[f])};return r.set(u,o),o};export{a as createCacheKey,l as createRange,o as getCachedDaysObject,u as getCachedMonthsObject,i as getCachedYearsObject};
|