diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 0000000..099993c --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1 @@ +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),o=require("antd"),n=require("react"),r=function(){return r=Object.assign||function(e){for(var o,n=1,r=arguments.length;n2)throw new Error('Invalid value "'.concat(e,' for "').concat(o.type,'"'));var t=l[0],i=l[1];r="*"===t?d(o.min,o.max):function(e,o,n){var r=e.split("-");if(1===r.length){var l=m(r[0]);if(isNaN(l))throw new Error('Invalid value "'.concat(o,'" for ').concat(n.type));return[l]}if(2===r.length){var t=m(r[0]),i=m(r[1]);if(isNaN(t)||isNaN(i))throw new Error('Invalid value "'.concat(o,'" for ').concat(n.type));if(i0)return"year";if(e[2].length>0)return"month";if(e[4].length>0)return"week";if(e[1].length>0)return"day";if(e[0].length>0)return"hour";return"minute"}(C);x(M),f(C[0]),y(C[1]),h(C[2]),w(C[3]),b(C[4])}catch(e){k=!0}}k&&(l.current=e,o(!0),p(n,u))}function y(e,o,n,r,l,t,i,u){if("reboot"===e)return"@reboot";var d=function(e,o,n){return e.map((function(e,r){var l,t=a[r],i=b(e,t),u=null==n?void 0:n[t.type];return h(i,t,null!==(l=null==u?void 0:u.humanizeValue)&&void 0!==l?l:o)}))}(["minute"!==e&&t?t:[],"minute"!==e&&"hour"!==e&&l?l:[],"year"!==e&&"month"!==e||!n?[]:n,"year"===e&&o?o:[],"year"!==e&&"month"!==e&&"week"!==e||!r?[]:r],i,u);return d.join(" ")}function h(e,o,n,r,l){var t="";if(function(e,o){return e.length===o.max-o.min+1}(e,o)||0===e.length)t="*";else{var i=function(e){if(e.length>2){var o=e[1]-e[0];if(o>1)return o}}(e);t=i&&function(e,o){for(var n=1;no.max&&t)return!0;return!1}(e,o,i)?"*/".concat(i):"".concat(w(x(e),o,n,r,l),"-").concat(w(k(e),o,n,r,l),"/").concat(i):function(e){var o=[],n=null;return e.forEach((function(e,r,l){e!==l[r+1]-1?null!==n?(o.push([n,e]),n=null):o.push(e):null===n&&(n=e)})),o}(e).map((function(e){return Array.isArray(e)?"".concat(w(e[0],o,n,r,l),"-").concat(w(e[1],o,n,r,l)):w(e,o,n,r,l)})).join(",")}return t}function w(e,o,n,r,l){var t=e.toString(),i=o.type,a=o.alt,u=o.min,d=r&&(!0===r||r.includes(i)),s="24-hour-clock"===l&&("hours"===i||"minutes"===i);if(n&&"week-days"===i||n&&"months"===i?t=a[e-u]:e<10&&(d||s)&&(t=t.padStart(2,"0")),"hours"===i&&"12-hour-clock"===l){var c=e>=12?"PM":"AM",v=e%12||12;v<10&&d&&(v=v.toString().padStart(2,"0")),t="".concat(v).concat(c)}return t}function b(e,o){var n=s(c(O(e,o)));if(0===n.length)return n;var r=g(n,o);if(void 0!==r)throw new Error('Value "'.concat(r,'" out of range for ').concat(o.type));return n}function O(e,o){return"week-days"===o.type&&(e=e.map((function(e){return 7===e?0:e}))),e}function g(e,o){var n=e[0],r=e[e.length-1];return no.max?r:void 0}function x(e){return e[0]}function k(e){return e[e.length-1]}var j=Object.freeze({__proto__:null,setValuesFromCronString:f,getCronStringFromValues:y,partToString:h,formatValue:w,parsePartArray:b});function C(i){var a=i.value,d=i.grid,c=void 0===d||d,p=i.optionsList,m=i.setValue,f=i.locale,y=i.className,O=i.humanizeLabels,g=i.disabled,x=i.readOnly,k=i.leadingZero,j=i.clockFormat,C=i.period,M=i.unit,N=i.periodicityOnDoubleClick,D=i.mode,S=i.allowClear,P=i.filterOption,F=void 0===P?function(){return!0}:P,E=l(i,["value","grid","optionsList","setValue","locale","className","humanizeLabels","disabled","readOnly","leadingZero","clockFormat","period","unit","periodicityOnDoubleClick","mode","allowClear","filterOption"]),A=n.useMemo((function(){if(a&&Array.isArray(a))return a.map((function(e){return e.toString()}))}),[a]),V=n.useMemo((function(){return p?p.map((function(e,o){return{value:(0===M.min?o:o+1).toString(),label:e}})).filter(F):t([],Array(M.total),!0).map((function(e,o){var n=0===M.min?o:o+1;return{value:n.toString(),label:w(n,M,O,k,j)}})).filter(F)}),[p,k,O,j]),W=JSON.stringify(f),H=n.useCallback((function(o){var n=o.value;if(!a||a[0]!==Number(n))return e.jsx(e.Fragment,{});var r=h(b(a,M),M,O,k,j),l=r.match(/^\*\/([0-9]+),?/)||[];return e.jsx("div",{children:l[1]?"".concat(f.everyText||u.everyText," ").concat(l[1]):r})}),[a,W,O,k,j]),T=n.useCallback((function(e){var o=Array.isArray(e)?s(e):[e],n=o;a&&(n="single"===D?[]:t([],a,!0),o.forEach((function(e){var o=Number(e);n=a.some((function(e){return e===o}))?n.filter((function(e){return e!==o})):s(t(t([],n,!0),[o],!1))}))),n.length===M.total?m([]):m(n)}),[m,a]),I=n.useCallback((function(e){if(0!==e&&1!==e){for(var o=M.total+M.min,n=[],r=M.min;r1&&o[o.length-1].time-o[o.length-2].time<300?o[o.length-1].value===o[o.length-2].value?I(Number(e)):T([o[o.length-2].value,o[o.length-1].value]):T(Number(e)),L.current=[]}),300);return function(){window.clearTimeout(n)}}}),[L,T,I,x,N]),Z=n.useCallback((function(){x||m([])}),[m,x]),z=n.useMemo((function(){var e;return v(((e={"react-js-cron-select":!0,"react-js-cron-custom-select":!0})["".concat(y,"-select")]=!!y,e))}),[y]),U=n.useMemo((function(){var e;return v(((e={"react-js-cron-select-dropdown":!0})["react-js-cron-select-dropdown-".concat(M.type)]=!0,e["react-js-cron-custom-select-dropdown"]=!0,e["react-js-cron-custom-select-dropdown-".concat(M.type)]=!0,e["react-js-cron-custom-select-dropdown-minutes-large"]="minutes"===M.type&&"hour"!==C&&"day"!==C,e["react-js-cron-custom-select-dropdown-minutes-medium"]="minutes"===M.type&&("day"===C||"hour"===C),e["react-js-cron-custom-select-dropdown-hours-twelve-hour-clock"]="hours"===M.type&&"12-hour-clock"===j,e["react-js-cron-custom-select-dropdown-grid"]=!!c,e["".concat(y,"-select-dropdown")]=!!y,e["".concat(y,"-select-dropdown-").concat(M.type)]=!!y,e))}),[y,c,j,C]);return e.jsx(o.Select,r({mode:"single"!==D||N?"multiple":void 0,allowClear:null!=S?S:!x,virtual:!1,open:!x&&void 0,value:A,onClear:Z,tagRender:H,className:z,popupClassName:U,options:V,showSearch:!1,suffixIcon:x?null:void 0,menuItemSelectedIcon:null,popupMatchSelectWidth:!1,onSelect:J,onDeselect:J,disabled:g,dropdownAlign:"minutes"!==M.type&&"hours"!==M.type||"day"===C||"hour"===C?void 0:{points:["tr","br"]},"data-testid":"custom-select-".concat(M.type)},E))}function M(o){var l=o.value,t=o.setValue,i=o.locale,d=o.className,s=o.disabled,c=o.readOnly,p=o.leadingZero,m=o.clockFormat,f=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,O=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-hours":!0})["".concat(d,"-field")]=!!d,e["".concat(d,"-hours")]=!!d,e))}),[d]);return e.jsxs("div",r({className:O},{children:[""!==i.prefixHours&&e.jsx("span",{children:i.prefixHours||u.prefixHours}),e.jsx(C,{placeholder:i.emptyHours||u.emptyHours,value:l,unit:a[1],setValue:t,locale:i,className:d,disabled:s,readOnly:c,leadingZero:p,clockFormat:m,period:f,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]}))}function N(o){var l=o.value,t=o.setValue,i=o.locale,d=o.className,s=o.disabled,c=o.readOnly,p=o.leadingZero,m=o.clockFormat,f=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,O=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-minutes":!0})["".concat(d,"-field")]=!!d,e["".concat(d,"-minutes")]=!!d,e))}),[d]);return e.jsxs("div",r({className:O},{children:["hour"===f?""!==i.prefixMinutesForHourPeriod&&e.jsx("span",{children:i.prefixMinutesForHourPeriod||u.prefixMinutesForHourPeriod}):""!==i.prefixMinutes&&e.jsx("span",{children:i.prefixMinutes||u.prefixMinutes}),e.jsx(C,{placeholder:"hour"===f?i.emptyMinutesForHourPeriod||u.emptyMinutesForHourPeriod:i.emptyMinutes||u.emptyMinutes,value:l,unit:a[0],setValue:t,locale:i,className:d,disabled:s,readOnly:c,leadingZero:p,clockFormat:m,period:f,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b}),"hour"===f&&""!==i.suffixMinutesForHourPeriod&&e.jsx("span",{children:i.suffixMinutesForHourPeriod||u.suffixMinutesForHourPeriod})]}))}function D(o){var l=o.value,t=o.setValue,i=o.locale,d=o.className,s=o.weekDays,c=o.disabled,p=o.readOnly,m=o.leadingZero,f=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,O=!s||0===s.length,g=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-month-days":!0,"react-js-cron-month-days-placeholder":!O})["".concat(d,"-field")]=!!d,e["".concat(d,"-month-days")]=!!d,e))}),[d,O]),x=JSON.stringify(i),k=n.useMemo((function(){return O?i.emptyMonthDays||u.emptyMonthDays:i.emptyMonthDaysShort||u.emptyMonthDaysShort}),[O,x]);return!p||l&&l.length>0||(!l||0===l.length)&&(!s||0===s.length)?e.jsxs("div",r({className:g},{children:[""!==i.prefixMonthDays&&e.jsx("span",{children:i.prefixMonthDays||u.prefixMonthDays}),e.jsx(C,{placeholder:k,value:l,setValue:t,unit:a[2],locale:i,className:d,disabled:c,readOnly:p,leadingZero:m,period:f,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]})):null}function S(o){var l=o.value,t=o.setValue,i=o.locale,d=o.className,s=o.humanizeLabels,c=o.disabled,p=o.readOnly,m=o.period,f=o.periodicityOnDoubleClick,y=o.mode,h=o.allowClear,w=o.filterOption,b=i.months||u.months,O=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-months":!0})["".concat(d,"-field")]=!!d,e["".concat(d,"-months")]=!!d,e))}),[d]);return e.jsxs("div",r({className:O},{children:[""!==i.prefixMonths&&e.jsx("span",{children:i.prefixMonths||u.prefixMonths}),e.jsx(C,{placeholder:i.emptyMonths||u.emptyMonths,optionsList:b,grid:!1,value:l,unit:r(r({},a[3]),{alt:i.altMonths||u.altMonths}),setValue:t,locale:i,className:d,humanizeLabels:s,disabled:c,readOnly:p,period:m,periodicityOnDoubleClick:f,mode:y,allowClear:h,filterOption:w})]}))}function P(l){var t=l.value,i=l.setValue,a=l.locale,d=l.className,s=l.disabled,c=l.readOnly,p=l.shortcuts,m=l.allowedPeriods,f=l.allowClear,y=[];m.includes("year")&&y.push({value:"year",label:a.yearOption||u.yearOption}),m.includes("month")&&y.push({value:"month",label:a.monthOption||u.monthOption}),m.includes("week")&&y.push({value:"week",label:a.weekOption||u.weekOption}),m.includes("day")&&y.push({value:"day",label:a.dayOption||u.dayOption}),m.includes("hour")&&y.push({value:"hour",label:a.hourOption||u.hourOption}),m.includes("minute")&&y.push({value:"minute",label:a.minuteOption||u.minuteOption}),m.includes("reboot")&&p&&(!0===p||p.includes("@reboot"))&&y.push({value:"reboot",label:a.rebootOption||u.rebootOption});var h=n.useCallback((function(e){c||i(e)}),[i,c]),w=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-period":!0})["".concat(d,"-field")]=!!d,e["".concat(d,"-period")]=!!d,e))}),[d]),b=n.useMemo((function(){var e;return v(((e={"react-js-cron-select":!0,"react-js-cron-select-no-prefix":""===a.prefixPeriod})["".concat(d,"-select")]=!!d,e))}),[d,a.prefixPeriod]),O=n.useMemo((function(){var e;return v(((e={"react-js-cron-select-dropdown":!0,"react-js-cron-select-dropdown-period":!0})["".concat(d,"-select-dropdown")]=!!d,e["".concat(d,"-select-dropdown-period")]=!!d,e))}),[d]);return e.jsxs("div",r({className:w},{children:[""!==a.prefixPeriod&&e.jsx("span",{children:a.prefixPeriod||u.prefixPeriod}),e.jsx(o.Select,{defaultValue:t,value:t,onChange:h,options:y,className:b,popupClassName:O,disabled:s,suffixIcon:c?null:void 0,open:!c&&void 0,"data-testid":"select-period",allowClear:f},JSON.stringify(a))]}))}function F(o){var l=o.value,t=o.setValue,i=o.locale,d=o.className,s=o.humanizeLabels,c=o.monthDays,p=o.disabled,m=o.readOnly,f=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,O=i.weekDays||u.weekDays,g="week"===f||!c||0===c.length,x=n.useMemo((function(){var e;return v(((e={"react-js-cron-field":!0,"react-js-cron-week-days":!0,"react-js-cron-week-days-placeholder":!g})["".concat(d,"-field")]=!!d,e["".concat(d,"-week-days")]=!!d,e))}),[d,g]),k=JSON.stringify(i),j=n.useMemo((function(){return g?i.emptyWeekDays||u.emptyWeekDays:i.emptyWeekDaysShort||u.emptyWeekDaysShort}),[g,k]),M="week"===f||!m||l&&l.length>0||(!l||0===l.length)&&(!c||0===c.length),N=!m||c&&c.length>0||(!c||0===c.length)&&(!l||0===l.length);return M?e.jsxs("div",r({className:x},{children:[""!==i.prefixWeekDays&&("week"===f||!N)&&e.jsx("span",{children:i.prefixWeekDays||u.prefixWeekDays}),""!==i.prefixWeekDaysForMonthAndYearPeriod&&"week"!==f&&N&&e.jsx("span",{children:i.prefixWeekDaysForMonthAndYearPeriod||u.prefixWeekDaysForMonthAndYearPeriod}),e.jsx(C,{placeholder:j,optionsList:O,grid:!1,value:l,unit:r(r({},a[4]),{alt:i.altWeekDays||u.altWeekDays}),setValue:t,locale:i,className:d,humanizeLabels:s,disabled:p,readOnly:m,period:f,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]})):null}function E(t){var i,a,d,s,c,m,h,w,b,O,g,x,k,j,C,E,A,V,W,H,T,I,L,J,Z,z,U,R,B,_,Y,q,G,K,Q,X,$,ee,oe,ne,re,le,te,ie,ae,ue,de,se,ce,ve,pe,me,fe,ye,he,we,be,Oe,ge,xe,ke,je,Ce,Me,Ne,De,Se,Pe,Fe,Ee,Ae,Ve=t.clearButton,We=void 0===Ve||Ve,He=t.clearButtonProps,Te=void 0===He?{}:He,Ie=t.clearButtonAction,Le=void 0===Ie?"fill-with-every":Ie,Je=t.locale,Ze=void 0===Je?u:Je,ze=t.value,Ue=void 0===ze?"":ze,Re=t.setValue,Be=t.displayError,_e=void 0===Be||Be,Ye=t.onError,qe=t.className,Ge=t.defaultPeriod,Ke=void 0===Ge?"day":Ge,Qe=t.allowEmpty,Xe=void 0===Qe?"for-default-value":Qe,$e=t.humanizeLabels,eo=void 0===$e||$e,oo=t.humanizeValue,no=void 0!==oo&&oo,ro=t.disabled,lo=void 0!==ro&&ro,to=t.readOnly,io=void 0!==to&&to,ao=t.leadingZero,uo=void 0!==ao&&ao,so=t.shortcuts,co=void 0===so?["@yearly","@annually","@monthly","@weekly","@daily","@midnight","@hourly"]:so,vo=t.clockFormat,po=t.periodicityOnDoubleClick,mo=void 0===po||po,fo=t.mode,yo=void 0===fo?"multiple":fo,ho=t.allowedDropdowns,wo=void 0===ho?["period","months","month-days","week-days","hours","minutes"]:ho,bo=t.allowedPeriods,Oo=void 0===bo?["year","month","week","day","hour","minute","reboot"]:bo,go=t.allowClear,xo=t.dropdownsConfig,ko=n.useRef(Ue),jo=n.useRef(Ke),Co=n.useState(),Mo=Co[0],No=Co[1],Do=n.useState(),So=Do[0],Po=Do[1],Fo=n.useState(),Eo=Fo[0],Ao=Fo[1],Vo=n.useState(),Wo=Vo[0],Ho=Vo[1],To=n.useState(),Io=To[0],Lo=To[1],Jo=n.useState(),Zo=Jo[0],zo=Jo[1],Uo=n.useState(!1),Ro=Uo[0],Bo=Uo[1],_o=n.useState(!1),Yo=_o[0],qo=_o[1],Go=function(e){var o=n.useRef(e);return n.useEffect((function(){o.current=e}),[e]),o.current}(Yo),Ko=JSON.stringify(Ze);n.useEffect((function(){f(Ue,Bo,Ye,Xe,ko,!0,Ze,co,zo,Lo,Po,Ao,Ho,No)}),[]),n.useEffect((function(){Ue!==ko.current&&f(Ue,Bo,Ye,Xe,ko,!1,Ze,co,zo,Lo,Po,Ao,Ho,No)}),[Ue,ko,Ko,Xe,co]),n.useEffect((function(){if(!(Mo||Zo||Eo||So||Wo||Io)||Yo||Go)Yo&&qo(!1);else{var e=Mo||jo.current,o=y(e,Eo,So,Wo,Io,Zo,no,xo);Re(o,{selectedPeriod:e}),ko.current=o,Ye&&Ye(void 0),Bo(!1)}}),[Mo,So,Eo,Wo,Io,Zo,no,Yo,xo]);var Qo=n.useCallback((function(){Po(void 0),Ao(void 0),Ho(void 0),Lo(void 0),zo(void 0);var e="",o="reboot"!==Mo&&Mo?Mo:jo.current;(o!==Mo&&No(o),"fill-with-every"===Le)&&(e=y(o,void 0,void 0,void 0,void 0,void 0,void 0,void 0));Re(e,{selectedPeriod:o}),ko.current=e,qo(!0),"never"===Xe&&"empty"===Le?(Bo(!0),p(Ye,Ze)):(Ye&&Ye(void 0),Bo(!1))}),[Mo,Re,Ye,Le]),Xo=n.useMemo((function(){var e;return v(((e={"react-js-cron":!0,"react-js-cron-error":Ro&&_e,"react-js-cron-disabled":lo,"react-js-cron-read-only":io})["".concat(qe)]=!!qe,e["".concat(qe,"-error")]=Ro&&_e&&!!qe,e["".concat(qe,"-disabled")]=lo&&!!qe,e["".concat(qe,"-read-only")]=io&&!!qe,e))}),[qe,Ro,_e,lo,io]),$o=Te.className,en=l(Te,["className"]),on=n.useMemo((function(){var e;return v(((e={"react-js-cron-clear-button":!0})["".concat(qe,"-clear-button")]=!!qe,e["".concat($o)]=!!$o,e))}),[qe,$o]),nn=JSON.stringify(en),rn=n.useMemo((function(){return We&&!io?e.jsx(o.Button,r({className:on,danger:!0,type:"primary",disabled:lo},en,{onClick:Qo},{children:Ze.clearButtonText||u.clearButtonText})):null}),[We,io,Ko,on,lo,nn,Qo]),ln=Mo||jo.current;return e.jsxs("div",r({className:Xo},{children:[wo.includes("period")&&e.jsx(P,{value:ln,setValue:No,locale:Ze,className:qe,disabled:null!==(a=null===(i=null==xo?void 0:xo.period)||void 0===i?void 0:i.disabled)&&void 0!==a?a:lo,readOnly:null!==(s=null===(d=null==xo?void 0:xo.period)||void 0===d?void 0:d.readOnly)&&void 0!==s?s:io,shortcuts:co,allowedPeriods:Oo,allowClear:null!==(m=null===(c=null==xo?void 0:xo.period)||void 0===c?void 0:c.allowClear)&&void 0!==m?m:go}),"reboot"===ln?rn:e.jsxs(e.Fragment,{children:["year"===ln&&wo.includes("months")&&e.jsx(S,{value:Eo,setValue:Ao,locale:Ze,className:qe,humanizeLabels:null!==(w=null===(h=null==xo?void 0:xo.months)||void 0===h?void 0:h.humanizeLabels)&&void 0!==w?w:eo,disabled:null!==(O=null===(b=null==xo?void 0:xo.months)||void 0===b?void 0:b.disabled)&&void 0!==O?O:lo,readOnly:null!==(x=null===(g=null==xo?void 0:xo.months)||void 0===g?void 0:g.readOnly)&&void 0!==x?x:io,period:ln,periodicityOnDoubleClick:null!==(j=null===(k=null==xo?void 0:xo.months)||void 0===k?void 0:k.periodicityOnDoubleClick)&&void 0!==j?j:mo,mode:null!==(E=null===(C=null==xo?void 0:xo.months)||void 0===C?void 0:C.mode)&&void 0!==E?E:yo,allowClear:null!==(V=null===(A=null==xo?void 0:xo.months)||void 0===A?void 0:A.allowClear)&&void 0!==V?V:go,filterOption:null===(W=null==xo?void 0:xo.months)||void 0===W?void 0:W.filterOption}),("year"===ln||"month"===ln)&&wo.includes("month-days")&&e.jsx(D,{value:So,setValue:Po,locale:Ze,className:qe,weekDays:Wo,disabled:null!==(T=null===(H=null==xo?void 0:xo["month-days"])||void 0===H?void 0:H.disabled)&&void 0!==T?T:lo,readOnly:null!==(L=null===(I=null==xo?void 0:xo["month-days"])||void 0===I?void 0:I.readOnly)&&void 0!==L?L:io,leadingZero:null!==(Z=null===(J=null==xo?void 0:xo["month-days"])||void 0===J?void 0:J.leadingZero)&&void 0!==Z?Z:uo,period:ln,periodicityOnDoubleClick:null!==(U=null===(z=null==xo?void 0:xo["month-days"])||void 0===z?void 0:z.periodicityOnDoubleClick)&&void 0!==U?U:mo,mode:null!==(B=null===(R=null==xo?void 0:xo["month-days"])||void 0===R?void 0:R.mode)&&void 0!==B?B:yo,allowClear:null!==(Y=null===(_=null==xo?void 0:xo["month-days"])||void 0===_?void 0:_.allowClear)&&void 0!==Y?Y:go,filterOption:null===(q=null==xo?void 0:xo["month-days"])||void 0===q?void 0:q.filterOption}),("year"===ln||"month"===ln||"week"===ln)&&wo.includes("week-days")&&e.jsx(F,{value:Wo,setValue:Ho,locale:Ze,className:qe,humanizeLabels:null!==(K=null===(G=null==xo?void 0:xo["week-days"])||void 0===G?void 0:G.humanizeLabels)&&void 0!==K?K:eo,monthDays:So,disabled:null!==(X=null===(Q=null==xo?void 0:xo["week-days"])||void 0===Q?void 0:Q.disabled)&&void 0!==X?X:lo,readOnly:null!==(ee=null===($=null==xo?void 0:xo["week-days"])||void 0===$?void 0:$.readOnly)&&void 0!==ee?ee:io,period:ln,periodicityOnDoubleClick:null!==(ne=null===(oe=null==xo?void 0:xo["week-days"])||void 0===oe?void 0:oe.periodicityOnDoubleClick)&&void 0!==ne?ne:mo,mode:null!==(le=null===(re=null==xo?void 0:xo["week-days"])||void 0===re?void 0:re.mode)&&void 0!==le?le:yo,allowClear:null!==(ie=null===(te=null==xo?void 0:xo["week-days"])||void 0===te?void 0:te.allowClear)&&void 0!==ie?ie:go,filterOption:null===(ae=null==xo?void 0:xo["week-days"])||void 0===ae?void 0:ae.filterOption}),e.jsxs("div",{children:["minute"!==ln&&"hour"!==ln&&wo.includes("hours")&&e.jsx(M,{value:Io,setValue:Lo,locale:Ze,className:qe,disabled:null!==(de=null===(ue=null==xo?void 0:xo.hours)||void 0===ue?void 0:ue.disabled)&&void 0!==de?de:lo,readOnly:null!==(ce=null===(se=null==xo?void 0:xo.hours)||void 0===se?void 0:se.readOnly)&&void 0!==ce?ce:io,leadingZero:null!==(pe=null===(ve=null==xo?void 0:xo.hours)||void 0===ve?void 0:ve.leadingZero)&&void 0!==pe?pe:uo,clockFormat:vo,period:ln,periodicityOnDoubleClick:null!==(fe=null===(me=null==xo?void 0:xo.hours)||void 0===me?void 0:me.periodicityOnDoubleClick)&&void 0!==fe?fe:mo,mode:null!==(he=null===(ye=null==xo?void 0:xo.hours)||void 0===ye?void 0:ye.mode)&&void 0!==he?he:yo,allowClear:null!==(be=null===(we=null==xo?void 0:xo.hours)||void 0===we?void 0:we.allowClear)&&void 0!==be?be:go,filterOption:null===(Oe=null==xo?void 0:xo.hours)||void 0===Oe?void 0:Oe.filterOption}),"minute"!==ln&&wo.includes("minutes")&&e.jsx(N,{value:Zo,setValue:zo,locale:Ze,period:ln,className:qe,disabled:null!==(xe=null===(ge=null==xo?void 0:xo.minutes)||void 0===ge?void 0:ge.disabled)&&void 0!==xe?xe:lo,readOnly:null!==(je=null===(ke=null==xo?void 0:xo.minutes)||void 0===ke?void 0:ke.readOnly)&&void 0!==je?je:io,leadingZero:null!==(Me=null===(Ce=null==xo?void 0:xo.minutes)||void 0===Ce?void 0:Ce.leadingZero)&&void 0!==Me?Me:uo,clockFormat:vo,periodicityOnDoubleClick:null!==(De=null===(Ne=null==xo?void 0:xo.minutes)||void 0===Ne?void 0:Ne.periodicityOnDoubleClick)&&void 0!==De?De:mo,mode:null!==(Pe=null===(Se=null==xo?void 0:xo.minutes)||void 0===Se?void 0:Se.mode)&&void 0!==Pe?Pe:yo,allowClear:null!==(Ee=null===(Fe=null==xo?void 0:xo.minutes)||void 0===Fe?void 0:Fe.allowClear)&&void 0!==Ee?Ee:go,filterOption:null===(Ae=null==xo?void 0:xo.minutes)||void 0===Ae?void 0:Ae.filterOption}),rn]})]})]}))}exports.Cron=E,exports.converter=j,exports.default=E; diff --git a/dist/cjs/types/Cron.d.ts b/dist/cjs/types/Cron.d.ts new file mode 100644 index 0000000..91e1add --- /dev/null +++ b/dist/cjs/types/Cron.d.ts @@ -0,0 +1,3 @@ +/// +import { CronProps } from './types'; +export default function Cron(props: CronProps): JSX.Element; diff --git a/dist/cjs/types/components/CustomSelect.d.ts b/dist/cjs/types/components/CustomSelect.d.ts new file mode 100644 index 0000000..7816811 --- /dev/null +++ b/dist/cjs/types/components/CustomSelect.d.ts @@ -0,0 +1,3 @@ +/// +import { CustomSelectProps } from '../types'; +export default function CustomSelect(props: CustomSelectProps): JSX.Element; diff --git a/dist/cjs/types/constants.d.ts b/dist/cjs/types/constants.d.ts new file mode 100644 index 0000000..3a6787b --- /dev/null +++ b/dist/cjs/types/constants.d.ts @@ -0,0 +1,3 @@ +import { ShortcutsValues, Unit } from './types'; +export declare const SUPPORTED_SHORTCUTS: ShortcutsValues[]; +export declare const UNITS: Unit[]; diff --git a/dist/cjs/types/converter.d.ts b/dist/cjs/types/converter.d.ts new file mode 100644 index 0000000..97e28ec --- /dev/null +++ b/dist/cjs/types/converter.d.ts @@ -0,0 +1,7 @@ +import { MutableRefObject } from 'react'; +import { AllowEmpty, ClockFormat, DropdownsConfig, LeadingZero, Locale, OnError, PeriodType, SetInternalError, SetValueNumbersOrUndefined, SetValuePeriod, Shortcuts, Unit } from './types'; +export declare function setValuesFromCronString(cronString: string, setInternalError: SetInternalError, onError: OnError, allowEmpty: AllowEmpty, internalValueRef: MutableRefObject, firstRender: boolean, locale: Locale, shortcuts: Shortcuts, setMinutes: SetValueNumbersOrUndefined, setHours: SetValueNumbersOrUndefined, setMonthDays: SetValueNumbersOrUndefined, setMonths: SetValueNumbersOrUndefined, setWeekDays: SetValueNumbersOrUndefined, setPeriod: SetValuePeriod): void; +export declare function getCronStringFromValues(period: PeriodType, months: number[] | undefined, monthDays: number[] | undefined, weekDays: number[] | undefined, hours: number[] | undefined, minutes: number[] | undefined, humanizeValue: boolean | undefined, dropdownsConfig: DropdownsConfig | undefined): string; +export declare function partToString(cronPart: number[], unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +export declare function formatValue(value: number, unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +export declare function parsePartArray(arr: number[], unit: Unit): number[]; diff --git a/dist/cjs/types/fields/Hours.d.ts b/dist/cjs/types/fields/Hours.d.ts new file mode 100644 index 0000000..8363238 --- /dev/null +++ b/dist/cjs/types/fields/Hours.d.ts @@ -0,0 +1,3 @@ +/// +import { HoursProps } from '../types'; +export default function Hours(props: HoursProps): JSX.Element; diff --git a/dist/cjs/types/fields/Minutes.d.ts b/dist/cjs/types/fields/Minutes.d.ts new file mode 100644 index 0000000..67a2032 --- /dev/null +++ b/dist/cjs/types/fields/Minutes.d.ts @@ -0,0 +1,3 @@ +/// +import { MinutesProps } from '../types'; +export default function Minutes(props: MinutesProps): JSX.Element; diff --git a/dist/cjs/types/fields/MonthDays.d.ts b/dist/cjs/types/fields/MonthDays.d.ts new file mode 100644 index 0000000..4cb26ae --- /dev/null +++ b/dist/cjs/types/fields/MonthDays.d.ts @@ -0,0 +1,3 @@ +/// +import { MonthDaysProps } from '../types'; +export default function MonthDays(props: MonthDaysProps): JSX.Element | null; diff --git a/dist/cjs/types/fields/Months.d.ts b/dist/cjs/types/fields/Months.d.ts new file mode 100644 index 0000000..6666264 --- /dev/null +++ b/dist/cjs/types/fields/Months.d.ts @@ -0,0 +1,3 @@ +/// +import { MonthsProps } from '../types'; +export default function Months(props: MonthsProps): JSX.Element; diff --git a/dist/cjs/types/fields/Period.d.ts b/dist/cjs/types/fields/Period.d.ts new file mode 100644 index 0000000..3a2364a --- /dev/null +++ b/dist/cjs/types/fields/Period.d.ts @@ -0,0 +1,3 @@ +/// +import { PeriodProps } from '../types'; +export default function Period(props: PeriodProps): JSX.Element; diff --git a/dist/cjs/types/fields/WeekDays.d.ts b/dist/cjs/types/fields/WeekDays.d.ts new file mode 100644 index 0000000..4ad1e21 --- /dev/null +++ b/dist/cjs/types/fields/WeekDays.d.ts @@ -0,0 +1,3 @@ +/// +import { WeekDaysProps } from '../types'; +export default function WeekDays(props: WeekDaysProps): JSX.Element | null; diff --git a/dist/cjs/types/index.d.ts b/dist/cjs/types/index.d.ts new file mode 100644 index 0000000..e7a6865 --- /dev/null +++ b/dist/cjs/types/index.d.ts @@ -0,0 +1,5 @@ +import Cron from './Cron'; +import * as converter from './converter'; +export * from './types'; +export { Cron, converter }; +export default Cron; diff --git a/dist/cjs/types/locale.d.ts b/dist/cjs/types/locale.d.ts new file mode 100644 index 0000000..bac2501 --- /dev/null +++ b/dist/cjs/types/locale.d.ts @@ -0,0 +1,2 @@ +import { DefaultLocale } from './types'; +export declare const DEFAULT_LOCALE_EN: DefaultLocale; diff --git a/dist/cjs/types/types.d.ts b/dist/cjs/types/types.d.ts new file mode 100644 index 0000000..39f5f5d --- /dev/null +++ b/dist/cjs/types/types.d.ts @@ -0,0 +1,216 @@ +import { ButtonProps, SelectProps } from 'antd'; +import { Dispatch, SetStateAction } from 'react'; +export interface CronProps { + value: string; + setValue: SetValue; + className?: string; + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: LeadingZero; + defaultPeriod?: PeriodType; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + allowEmpty?: AllowEmpty; + shortcuts?: Shortcuts; + clockFormat?: ClockFormat; + clearButton?: boolean; + clearButtonProps?: ClearButtonProps; + clearButtonAction?: ClearButtonAction; + displayError?: boolean; + onError?: OnError; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + allowedDropdowns?: CronType[]; + allowedPeriods?: PeriodType[]; + dropdownsConfig?: DropdownsConfig; + locale?: Locale; +} +export interface Locale { + everyText?: string; + emptyMonths?: string; + emptyMonthDays?: string; + emptyMonthDaysShort?: string; + emptyWeekDays?: string; + emptyWeekDaysShort?: string; + emptyHours?: string; + emptyMinutes?: string; + emptyMinutesForHourPeriod?: string; + yearOption?: string; + monthOption?: string; + weekOption?: string; + dayOption?: string; + hourOption?: string; + minuteOption?: string; + rebootOption?: string; + prefixPeriod?: string; + prefixMonths?: string; + prefixMonthDays?: string; + prefixWeekDays?: string; + prefixWeekDaysForMonthAndYearPeriod?: string; + prefixHours?: string; + prefixMinutes?: string; + prefixMinutesForHourPeriod?: string; + suffixMinutesForHourPeriod?: string; + errorInvalidCron?: string; + clearButtonText?: string; + weekDays?: string[]; + months?: string[]; + altWeekDays?: string[]; + altMonths?: string[]; +} +export type SetValueFunction = (value: string, extra: SetValueFunctionExtra) => void; +export interface SetValueFunctionExtra { + selectedPeriod: PeriodType; +} +export type SetValue = SetValueFunction | Dispatch>; +export type CronError = { + type: 'invalid_cron'; + description: string; +} | undefined; +export type OnErrorFunction = (error: CronError) => void; +export type OnError = OnErrorFunction | Dispatch> | undefined; +export interface ClearButtonProps extends Omit { +} +export type ClearButtonAction = 'empty' | 'fill-with-every'; +export type PeriodType = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'reboot'; +export type AllowEmpty = 'always' | 'never' | 'for-default-value'; +export type CronType = 'period' | 'months' | 'month-days' | 'week-days' | 'hours' | 'minutes'; +export type LeadingZeroType = 'month-days' | 'hours' | 'minutes'; +export type LeadingZero = boolean | LeadingZeroType[]; +export type ClockFormat = '24-hour-clock' | '12-hour-clock'; +export type ShortcutsType = '@yearly' | '@annually' | '@monthly' | '@weekly' | '@daily' | '@midnight' | '@hourly' | '@reboot'; +export type Shortcuts = boolean | ShortcutsType[]; +export type Mode = 'multiple' | 'single'; +export type DropdownConfig = { + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: boolean; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + filterOption?: FilterOption; +}; +export type DropdownsConfig = { + 'period'?: Pick; + 'months'?: Omit; + 'month-days'?: Omit; + 'week-days'?: Omit; + 'hours'?: Omit; + 'minutes'?: Omit; +}; +export interface FieldProps { + value?: number[]; + setValue: SetValueNumbersOrUndefined; + locale: Locale; + className?: string; + disabled: boolean; + readOnly: boolean; + period: PeriodType; + periodicityOnDoubleClick: boolean; + mode: Mode; + allowClear?: boolean; + filterOption?: FilterOption; +} +export interface PeriodProps extends Omit { + value: PeriodType; + setValue: SetValuePeriod; + shortcuts: Shortcuts; + allowedPeriods: PeriodType[]; +} +export interface MonthsProps extends FieldProps { + humanizeLabels: boolean; +} +export interface MonthDaysProps extends FieldProps { + weekDays?: number[]; + leadingZero: LeadingZero; +} +export interface WeekDaysProps extends FieldProps { + humanizeLabels: boolean; + monthDays?: number[]; +} +export interface HoursProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +export interface MinutesProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +export interface CustomSelectProps extends Omit, 'mode' | 'tokenSeparators' | 'virtual' | 'onClick' | 'onBlur' | 'tagRender' | 'dropdownRender' | 'showSearch' | 'suffixIcon' | 'onChange' | 'dropdownMatchSelectWidth' | 'options' | 'onSelect' | 'onDeselect' | 'filterOption'> { + grid?: boolean; + setValue: SetValueNumbersOrUndefined; + optionsList?: string[]; + locale: Locale; + value?: number[]; + humanizeLabels?: boolean; + disabled: boolean; + readOnly: boolean; + leadingZero?: LeadingZero; + clockFormat?: ClockFormat; + period: PeriodType; + unit: Unit; + periodicityOnDoubleClick: boolean; + mode: Mode; + filterOption?: FilterOption; +} +export type SetValueNumbersOrUndefined = Dispatch>; +export type SetValuePeriod = Dispatch>; +export type SetInternalError = Dispatch>; +export interface DefaultLocale { + everyText: string; + emptyMonths: string; + emptyMonthDays: string; + emptyMonthDaysShort: string; + emptyWeekDays: string; + emptyWeekDaysShort: string; + emptyHours: string; + emptyMinutes: string; + emptyMinutesForHourPeriod: string; + yearOption: string; + monthOption: string; + weekOption: string; + dayOption: string; + hourOption: string; + minuteOption: string; + rebootOption: string; + prefixPeriod: string; + prefixMonths: string; + prefixMonthDays: string; + prefixWeekDays: string; + prefixWeekDaysForMonthAndYearPeriod: string; + prefixHours: string; + prefixMinutes: string; + prefixMinutesForHourPeriod: string; + suffixMinutesForHourPeriod: string; + errorInvalidCron: string; + clearButtonText: string; + weekDays: string[]; + months: string[]; + altWeekDays: string[]; + altMonths: string[]; +} +export interface Classes { + [key: string]: boolean; +} +export interface ShortcutsValues { + name: ShortcutsType; + value: string; +} +export interface Unit { + type: CronType; + min: number; + max: number; + total: number; + alt?: string[]; +} +export interface Clicks { + time: number; + value: number; +} +export type FilterOption = ({ value, label, }: { + value: string; + label: string; +}) => boolean; diff --git a/dist/cjs/types/utils.d.ts b/dist/cjs/types/utils.d.ts new file mode 100644 index 0000000..9a0686f --- /dev/null +++ b/dist/cjs/types/utils.d.ts @@ -0,0 +1,8 @@ +import { Classes, Locale, OnError } from './types'; +export declare function range(start: number, end: number): number[]; +export declare function sort(array: number[]): number[]; +export declare function dedup(array: number[]): number[]; +export declare function classNames(classes: Classes): string; +export declare function setError(onError: OnError, locale: Locale): void; +export declare function usePrevious(value: any): any; +export declare function convertStringToNumber(str: string): number; diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 0000000..868abe6 --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1 @@ +import{jsx as e,Fragment as o,jsxs as n}from"react/jsx-runtime";import{Select as r,Button as l}from"antd";import{useRef as i,useEffect as t,useMemo as a,useCallback as u,useState as d}from"react";var c=function(){return c=Object.assign||function(e){for(var o,n=1,r=arguments.length;n2)throw new Error('Invalid value "'.concat(e,' for "').concat(o.type,'"'));var i=l[0],t=l[1];r="*"===i?y(o.min,o.max):function(e,o,n){var r=e.split("-");if(1===r.length){var l=g(r[0]);if(isNaN(l))throw new Error('Invalid value "'.concat(o,'" for ').concat(n.type));return[l]}if(2===r.length){var i=g(r[0]),t=g(r[1]);if(isNaN(i)||isNaN(t))throw new Error('Invalid value "'.concat(o,'" for ').concat(n.type));if(t0)return"year";if(e[2].length>0)return"month";if(e[4].length>0)return"week";if(e[1].length>0)return"day";if(e[0].length>0)return"hour";return"minute"}(C);f(N),u(C[0]),d(C[1]),c(C[2]),s(C[3]),v(C[4])}catch(e){O=!0}}O&&(l.current=e,o(!0),b(n,t))}function C(e,o,n,r,l,i,t,a){if("reboot"===e)return"@reboot";var u=function(e,o,n){return e.map((function(e,r){var l,i=m[r],t=x(e,i),a=null==n?void 0:n[i.type];return N(t,i,null!==(l=null==a?void 0:a.humanizeValue)&&void 0!==l?l:o)}))}(["minute"!==e&&i?i:[],"minute"!==e&&"hour"!==e&&l?l:[],"year"!==e&&"month"!==e||!n?[]:n,"year"===e&&o?o:[],"year"!==e&&"month"!==e&&"week"!==e||!r?[]:r],t,a);return u.join(" ")}function N(e,o,n,r,l){var i="";if(function(e,o){return e.length===o.max-o.min+1}(e,o)||0===e.length)i="*";else{var t=function(e){if(e.length>2){var o=e[1]-e[0];if(o>1)return o}}(e);i=t&&function(e,o){for(var n=1;no.max&&i)return!0;return!1}(e,o,t)?"*/".concat(t):"".concat(D(P(e),o,n,r,l),"-").concat(D(S(e),o,n,r,l),"/").concat(t):function(e){var o=[],n=null;return e.forEach((function(e,r,l){e!==l[r+1]-1?null!==n?(o.push([n,e]),n=null):o.push(e):null===n&&(n=e)})),o}(e).map((function(e){return Array.isArray(e)?"".concat(D(e[0],o,n,r,l),"-").concat(D(e[1],o,n,r,l)):D(e,o,n,r,l)})).join(",")}return i}function D(e,o,n,r,l){var i=e.toString(),t=o.type,a=o.alt,u=o.min,d=r&&(!0===r||r.includes(t)),c="24-hour-clock"===l&&("hours"===t||"minutes"===t);if(n&&"week-days"===t||n&&"months"===t?i=a[e-u]:e<10&&(d||c)&&(i=i.padStart(2,"0")),"hours"===t&&"12-hour-clock"===l){var s=e>=12?"PM":"AM",v=e%12||12;v<10&&d&&(v=v.toString().padStart(2,"0")),i="".concat(v).concat(s)}return i}function x(e,o){var n=h(w(M(e,o)));if(0===n.length)return n;var r=j(n,o);if(void 0!==r)throw new Error('Value "'.concat(r,'" out of range for ').concat(o.type));return n}function M(e,o){return"week-days"===o.type&&(e=e.map((function(e){return 7===e?0:e}))),e}function j(e,o){var n=e[0],r=e[e.length-1];return no.max?r:void 0}function P(e){return e[0]}function S(e){return e[e.length-1]}var F=Object.freeze({__proto__:null,setValuesFromCronString:k,getCronStringFromValues:C,partToString:N,formatValue:D,parsePartArray:x});function A(n){var l=n.value,t=n.grid,d=void 0===t||t,p=n.optionsList,m=n.setValue,y=n.locale,w=n.className,b=n.humanizeLabels,g=n.disabled,k=n.readOnly,C=n.leadingZero,M=n.clockFormat,j=n.period,P=n.unit,S=n.periodicityOnDoubleClick,F=n.mode,A=n.allowClear,V=n.filterOption,E=void 0===V?function(){return!0}:V,W=s(n,["value","grid","optionsList","setValue","locale","className","humanizeLabels","disabled","readOnly","leadingZero","clockFormat","period","unit","periodicityOnDoubleClick","mode","allowClear","filterOption"]),H=a((function(){if(l&&Array.isArray(l))return l.map((function(e){return e.toString()}))}),[l]),T=a((function(){return p?p.map((function(e,o){return{value:(0===P.min?o:o+1).toString(),label:e}})).filter(E):v([],Array(P.total),!0).map((function(e,o){var n=0===P.min?o:o+1;return{value:n.toString(),label:D(n,P,b,C,M)}})).filter(E)}),[p,C,b,M]),I=JSON.stringify(y),L=u((function(n){var r=n.value;if(!l||l[0]!==Number(r))return e(o,{});var i=N(x(l,P),P,b,C,M),t=i.match(/^\*\/([0-9]+),?/)||[];return e("div",{children:t[1]?"".concat(y.everyText||f.everyText," ").concat(t[1]):i})}),[l,I,b,C,M]),J=u((function(e){var o=Array.isArray(e)?h(e):[e],n=o;l&&(n="single"===F?[]:v([],l,!0),o.forEach((function(e){var o=Number(e);n=l.some((function(e){return e===o}))?n.filter((function(e){return e!==o})):h(v(v([],n,!0),[o],!1))}))),n.length===P.total?m([]):m(n)}),[m,l]),Z=u((function(e){if(0!==e&&1!==e){for(var o=P.total+P.min,n=[],r=P.min;r1&&o[o.length-1].time-o[o.length-2].time<300?o[o.length-1].value===o[o.length-2].value?Z(Number(e)):J([o[o.length-2].value,o[o.length-1].value]):J(Number(e)),z.current=[]}),300);return function(){window.clearTimeout(n)}}}),[z,J,Z,k,S]),B=u((function(){k||m([])}),[m,k]),R=a((function(){var e;return O(((e={"react-js-cron-select":!0,"react-js-cron-custom-select":!0})["".concat(w,"-select")]=!!w,e))}),[w]),Y=a((function(){var e;return O(((e={"react-js-cron-select-dropdown":!0})["react-js-cron-select-dropdown-".concat(P.type)]=!0,e["react-js-cron-custom-select-dropdown"]=!0,e["react-js-cron-custom-select-dropdown-".concat(P.type)]=!0,e["react-js-cron-custom-select-dropdown-minutes-large"]="minutes"===P.type&&"hour"!==j&&"day"!==j,e["react-js-cron-custom-select-dropdown-minutes-medium"]="minutes"===P.type&&("day"===j||"hour"===j),e["react-js-cron-custom-select-dropdown-hours-twelve-hour-clock"]="hours"===P.type&&"12-hour-clock"===M,e["react-js-cron-custom-select-dropdown-grid"]=!!d,e["".concat(w,"-select-dropdown")]=!!w,e["".concat(w,"-select-dropdown-").concat(P.type)]=!!w,e))}),[w,d,M,j]);return e(r,c({mode:"single"!==F||S?"multiple":void 0,allowClear:null!=A?A:!k,virtual:!1,open:!k&&void 0,value:H,onClear:B,tagRender:L,className:R,popupClassName:Y,options:T,showSearch:!1,suffixIcon:k?null:void 0,menuItemSelectedIcon:null,popupMatchSelectWidth:!1,onSelect:U,onDeselect:U,disabled:g,dropdownAlign:"minutes"!==P.type&&"hours"!==P.type||"day"===j||"hour"===j?void 0:{points:["tr","br"]},"data-testid":"custom-select-".concat(P.type)},W))}function V(o){var r=o.value,l=o.setValue,i=o.locale,t=o.className,u=o.disabled,d=o.readOnly,s=o.leadingZero,v=o.clockFormat,p=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,g=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-hours":!0})["".concat(t,"-field")]=!!t,e["".concat(t,"-hours")]=!!t,e))}),[t]);return n("div",c({className:g},{children:[""!==i.prefixHours&&e("span",{children:i.prefixHours||f.prefixHours}),e(A,{placeholder:i.emptyHours||f.emptyHours,value:r,unit:m[1],setValue:l,locale:i,className:t,disabled:u,readOnly:d,leadingZero:s,clockFormat:v,period:p,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]}))}function E(o){var r=o.value,l=o.setValue,i=o.locale,t=o.className,u=o.disabled,d=o.readOnly,s=o.leadingZero,v=o.clockFormat,p=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,g=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-minutes":!0})["".concat(t,"-field")]=!!t,e["".concat(t,"-minutes")]=!!t,e))}),[t]);return n("div",c({className:g},{children:["hour"===p?""!==i.prefixMinutesForHourPeriod&&e("span",{children:i.prefixMinutesForHourPeriod||f.prefixMinutesForHourPeriod}):""!==i.prefixMinutes&&e("span",{children:i.prefixMinutes||f.prefixMinutes}),e(A,{placeholder:"hour"===p?i.emptyMinutesForHourPeriod||f.emptyMinutesForHourPeriod:i.emptyMinutes||f.emptyMinutes,value:r,unit:m[0],setValue:l,locale:i,className:t,disabled:u,readOnly:d,leadingZero:s,clockFormat:v,period:p,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b}),"hour"===p&&""!==i.suffixMinutesForHourPeriod&&e("span",{children:i.suffixMinutesForHourPeriod||f.suffixMinutesForHourPeriod})]}))}function W(o){var r=o.value,l=o.setValue,i=o.locale,t=o.className,u=o.weekDays,d=o.disabled,s=o.readOnly,v=o.leadingZero,p=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,g=!u||0===u.length,k=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-month-days":!0,"react-js-cron-month-days-placeholder":!g})["".concat(t,"-field")]=!!t,e["".concat(t,"-month-days")]=!!t,e))}),[t,g]),C=JSON.stringify(i),N=a((function(){return g?i.emptyMonthDays||f.emptyMonthDays:i.emptyMonthDaysShort||f.emptyMonthDaysShort}),[g,C]);return!s||r&&r.length>0||(!r||0===r.length)&&(!u||0===u.length)?n("div",c({className:k},{children:[""!==i.prefixMonthDays&&e("span",{children:i.prefixMonthDays||f.prefixMonthDays}),e(A,{placeholder:N,value:r,setValue:l,unit:m[2],locale:i,className:t,disabled:d,readOnly:s,leadingZero:v,period:p,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]})):null}function H(o){var r=o.value,l=o.setValue,i=o.locale,t=o.className,u=o.humanizeLabels,d=o.disabled,s=o.readOnly,v=o.period,p=o.periodicityOnDoubleClick,y=o.mode,h=o.allowClear,w=o.filterOption,b=i.months||f.months,g=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-months":!0})["".concat(t,"-field")]=!!t,e["".concat(t,"-months")]=!!t,e))}),[t]);return n("div",c({className:g},{children:[""!==i.prefixMonths&&e("span",{children:i.prefixMonths||f.prefixMonths}),e(A,{placeholder:i.emptyMonths||f.emptyMonths,optionsList:b,grid:!1,value:r,unit:c(c({},m[3]),{alt:i.altMonths||f.altMonths}),setValue:l,locale:i,className:t,humanizeLabels:u,disabled:d,readOnly:s,period:v,periodicityOnDoubleClick:p,mode:y,allowClear:h,filterOption:w})]}))}function T(o){var l=o.value,i=o.setValue,t=o.locale,d=o.className,s=o.disabled,v=o.readOnly,p=o.shortcuts,m=o.allowedPeriods,y=o.allowClear,h=[];m.includes("year")&&h.push({value:"year",label:t.yearOption||f.yearOption}),m.includes("month")&&h.push({value:"month",label:t.monthOption||f.monthOption}),m.includes("week")&&h.push({value:"week",label:t.weekOption||f.weekOption}),m.includes("day")&&h.push({value:"day",label:t.dayOption||f.dayOption}),m.includes("hour")&&h.push({value:"hour",label:t.hourOption||f.hourOption}),m.includes("minute")&&h.push({value:"minute",label:t.minuteOption||f.minuteOption}),m.includes("reboot")&&p&&(!0===p||p.includes("@reboot"))&&h.push({value:"reboot",label:t.rebootOption||f.rebootOption});var w=u((function(e){v||i(e)}),[i,v]),b=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-period":!0})["".concat(d,"-field")]=!!d,e["".concat(d,"-period")]=!!d,e))}),[d]),g=a((function(){var e;return O(((e={"react-js-cron-select":!0,"react-js-cron-select-no-prefix":""===t.prefixPeriod})["".concat(d,"-select")]=!!d,e))}),[d,t.prefixPeriod]),k=a((function(){var e;return O(((e={"react-js-cron-select-dropdown":!0,"react-js-cron-select-dropdown-period":!0})["".concat(d,"-select-dropdown")]=!!d,e["".concat(d,"-select-dropdown-period")]=!!d,e))}),[d]);return n("div",c({className:b},{children:[""!==t.prefixPeriod&&e("span",{children:t.prefixPeriod||f.prefixPeriod}),e(r,{defaultValue:l,value:l,onChange:w,options:h,className:g,popupClassName:k,disabled:s,suffixIcon:v?null:void 0,open:!v&&void 0,"data-testid":"select-period",allowClear:y},JSON.stringify(t))]}))}function I(o){var r=o.value,l=o.setValue,i=o.locale,t=o.className,u=o.humanizeLabels,d=o.monthDays,s=o.disabled,v=o.readOnly,p=o.period,y=o.periodicityOnDoubleClick,h=o.mode,w=o.allowClear,b=o.filterOption,g=i.weekDays||f.weekDays,k="week"===p||!d||0===d.length,C=a((function(){var e;return O(((e={"react-js-cron-field":!0,"react-js-cron-week-days":!0,"react-js-cron-week-days-placeholder":!k})["".concat(t,"-field")]=!!t,e["".concat(t,"-week-days")]=!!t,e))}),[t,k]),N=JSON.stringify(i),D=a((function(){return k?i.emptyWeekDays||f.emptyWeekDays:i.emptyWeekDaysShort||f.emptyWeekDaysShort}),[k,N]),x="week"===p||!v||r&&r.length>0||(!r||0===r.length)&&(!d||0===d.length),M=!v||d&&d.length>0||(!d||0===d.length)&&(!r||0===r.length);return x?n("div",c({className:C},{children:[""!==i.prefixWeekDays&&("week"===p||!M)&&e("span",{children:i.prefixWeekDays||f.prefixWeekDays}),""!==i.prefixWeekDaysForMonthAndYearPeriod&&"week"!==p&&M&&e("span",{children:i.prefixWeekDaysForMonthAndYearPeriod||f.prefixWeekDaysForMonthAndYearPeriod}),e(A,{placeholder:D,optionsList:g,grid:!1,value:r,unit:c(c({},m[4]),{alt:i.altWeekDays||f.altWeekDays}),setValue:l,locale:i,className:t,humanizeLabels:u,disabled:s,readOnly:v,period:p,periodicityOnDoubleClick:y,mode:h,allowClear:w,filterOption:b})]})):null}function L(r){var v,p,m,y,h,w,g,N,D,x,M,j,P,S,F,A,L,J,Z,z,U,B,R,Y,_,G,q,K,Q,X,$,ee,oe,ne,re,le,ie,te,ae,ue,de,ce,se,ve,pe,me,fe,ye,he,we,Oe,be,ge,ke,Ce,Ne,De,xe,Me,je,Pe,Se,Fe,Ae,Ve,Ee,We,He,Te,Ie,Le,Je=r.clearButton,Ze=void 0===Je||Je,ze=r.clearButtonProps,Ue=void 0===ze?{}:ze,Be=r.clearButtonAction,Re=void 0===Be?"fill-with-every":Be,Ye=r.locale,_e=void 0===Ye?f:Ye,Ge=r.value,qe=void 0===Ge?"":Ge,Ke=r.setValue,Qe=r.displayError,Xe=void 0===Qe||Qe,$e=r.onError,eo=r.className,oo=r.defaultPeriod,no=void 0===oo?"day":oo,ro=r.allowEmpty,lo=void 0===ro?"for-default-value":ro,io=r.humanizeLabels,to=void 0===io||io,ao=r.humanizeValue,uo=void 0!==ao&&ao,co=r.disabled,so=void 0!==co&&co,vo=r.readOnly,po=void 0!==vo&&vo,mo=r.leadingZero,fo=void 0!==mo&&mo,yo=r.shortcuts,ho=void 0===yo?["@yearly","@annually","@monthly","@weekly","@daily","@midnight","@hourly"]:yo,wo=r.clockFormat,Oo=r.periodicityOnDoubleClick,bo=void 0===Oo||Oo,go=r.mode,ko=void 0===go?"multiple":go,Co=r.allowedDropdowns,No=void 0===Co?["period","months","month-days","week-days","hours","minutes"]:Co,Do=r.allowedPeriods,xo=void 0===Do?["year","month","week","day","hour","minute","reboot"]:Do,Mo=r.allowClear,jo=r.dropdownsConfig,Po=i(qe),So=i(no),Fo=d(),Ao=Fo[0],Vo=Fo[1],Eo=d(),Wo=Eo[0],Ho=Eo[1],To=d(),Io=To[0],Lo=To[1],Jo=d(),Zo=Jo[0],zo=Jo[1],Uo=d(),Bo=Uo[0],Ro=Uo[1],Yo=d(),_o=Yo[0],Go=Yo[1],qo=d(!1),Ko=qo[0],Qo=qo[1],Xo=d(!1),$o=Xo[0],en=Xo[1],on=function(e){var o=i(e);return t((function(){o.current=e}),[e]),o.current}($o),nn=JSON.stringify(_e);t((function(){k(qe,Qo,$e,lo,Po,!0,_e,ho,Go,Ro,Ho,Lo,zo,Vo)}),[]),t((function(){qe!==Po.current&&k(qe,Qo,$e,lo,Po,!1,_e,ho,Go,Ro,Ho,Lo,zo,Vo)}),[qe,Po,nn,lo,ho]),t((function(){if(!(Ao||_o||Io||Wo||Zo||Bo)||$o||on)$o&&en(!1);else{var e=Ao||So.current,o=C(e,Io,Wo,Zo,Bo,_o,uo,jo);Ke(o,{selectedPeriod:e}),Po.current=o,$e&&$e(void 0),Qo(!1)}}),[Ao,Wo,Io,Zo,Bo,_o,uo,$o,jo]);var rn=u((function(){Ho(void 0),Lo(void 0),zo(void 0),Ro(void 0),Go(void 0);var e="",o="reboot"!==Ao&&Ao?Ao:So.current;(o!==Ao&&Vo(o),"fill-with-every"===Re)&&(e=C(o,void 0,void 0,void 0,void 0,void 0,void 0,void 0));Ke(e,{selectedPeriod:o}),Po.current=e,en(!0),"never"===lo&&"empty"===Re?(Qo(!0),b($e,_e)):($e&&$e(void 0),Qo(!1))}),[Ao,Ke,$e,Re]),ln=a((function(){var e;return O(((e={"react-js-cron":!0,"react-js-cron-error":Ko&&Xe,"react-js-cron-disabled":so,"react-js-cron-read-only":po})["".concat(eo)]=!!eo,e["".concat(eo,"-error")]=Ko&&Xe&&!!eo,e["".concat(eo,"-disabled")]=so&&!!eo,e["".concat(eo,"-read-only")]=po&&!!eo,e))}),[eo,Ko,Xe,so,po]),tn=Ue.className,an=s(Ue,["className"]),un=a((function(){var e;return O(((e={"react-js-cron-clear-button":!0})["".concat(eo,"-clear-button")]=!!eo,e["".concat(tn)]=!!tn,e))}),[eo,tn]),dn=JSON.stringify(an),cn=a((function(){return Ze&&!po?e(l,c({className:un,danger:!0,type:"primary",disabled:so},an,{onClick:rn},{children:_e.clearButtonText||f.clearButtonText})):null}),[Ze,po,nn,un,so,dn,rn]),sn=Ao||So.current;return n("div",c({className:ln},{children:[No.includes("period")&&e(T,{value:sn,setValue:Vo,locale:_e,className:eo,disabled:null!==(p=null===(v=null==jo?void 0:jo.period)||void 0===v?void 0:v.disabled)&&void 0!==p?p:so,readOnly:null!==(y=null===(m=null==jo?void 0:jo.period)||void 0===m?void 0:m.readOnly)&&void 0!==y?y:po,shortcuts:ho,allowedPeriods:xo,allowClear:null!==(w=null===(h=null==jo?void 0:jo.period)||void 0===h?void 0:h.allowClear)&&void 0!==w?w:Mo}),"reboot"===sn?cn:n(o,{children:["year"===sn&&No.includes("months")&&e(H,{value:Io,setValue:Lo,locale:_e,className:eo,humanizeLabels:null!==(N=null===(g=null==jo?void 0:jo.months)||void 0===g?void 0:g.humanizeLabels)&&void 0!==N?N:to,disabled:null!==(x=null===(D=null==jo?void 0:jo.months)||void 0===D?void 0:D.disabled)&&void 0!==x?x:so,readOnly:null!==(j=null===(M=null==jo?void 0:jo.months)||void 0===M?void 0:M.readOnly)&&void 0!==j?j:po,period:sn,periodicityOnDoubleClick:null!==(S=null===(P=null==jo?void 0:jo.months)||void 0===P?void 0:P.periodicityOnDoubleClick)&&void 0!==S?S:bo,mode:null!==(A=null===(F=null==jo?void 0:jo.months)||void 0===F?void 0:F.mode)&&void 0!==A?A:ko,allowClear:null!==(J=null===(L=null==jo?void 0:jo.months)||void 0===L?void 0:L.allowClear)&&void 0!==J?J:Mo,filterOption:null===(Z=null==jo?void 0:jo.months)||void 0===Z?void 0:Z.filterOption}),("year"===sn||"month"===sn)&&No.includes("month-days")&&e(W,{value:Wo,setValue:Ho,locale:_e,className:eo,weekDays:Zo,disabled:null!==(U=null===(z=null==jo?void 0:jo["month-days"])||void 0===z?void 0:z.disabled)&&void 0!==U?U:so,readOnly:null!==(R=null===(B=null==jo?void 0:jo["month-days"])||void 0===B?void 0:B.readOnly)&&void 0!==R?R:po,leadingZero:null!==(_=null===(Y=null==jo?void 0:jo["month-days"])||void 0===Y?void 0:Y.leadingZero)&&void 0!==_?_:fo,period:sn,periodicityOnDoubleClick:null!==(q=null===(G=null==jo?void 0:jo["month-days"])||void 0===G?void 0:G.periodicityOnDoubleClick)&&void 0!==q?q:bo,mode:null!==(Q=null===(K=null==jo?void 0:jo["month-days"])||void 0===K?void 0:K.mode)&&void 0!==Q?Q:ko,allowClear:null!==($=null===(X=null==jo?void 0:jo["month-days"])||void 0===X?void 0:X.allowClear)&&void 0!==$?$:Mo,filterOption:null===(ee=null==jo?void 0:jo["month-days"])||void 0===ee?void 0:ee.filterOption}),("year"===sn||"month"===sn||"week"===sn)&&No.includes("week-days")&&e(I,{value:Zo,setValue:zo,locale:_e,className:eo,humanizeLabels:null!==(ne=null===(oe=null==jo?void 0:jo["week-days"])||void 0===oe?void 0:oe.humanizeLabels)&&void 0!==ne?ne:to,monthDays:Wo,disabled:null!==(le=null===(re=null==jo?void 0:jo["week-days"])||void 0===re?void 0:re.disabled)&&void 0!==le?le:so,readOnly:null!==(te=null===(ie=null==jo?void 0:jo["week-days"])||void 0===ie?void 0:ie.readOnly)&&void 0!==te?te:po,period:sn,periodicityOnDoubleClick:null!==(ue=null===(ae=null==jo?void 0:jo["week-days"])||void 0===ae?void 0:ae.periodicityOnDoubleClick)&&void 0!==ue?ue:bo,mode:null!==(ce=null===(de=null==jo?void 0:jo["week-days"])||void 0===de?void 0:de.mode)&&void 0!==ce?ce:ko,allowClear:null!==(ve=null===(se=null==jo?void 0:jo["week-days"])||void 0===se?void 0:se.allowClear)&&void 0!==ve?ve:Mo,filterOption:null===(pe=null==jo?void 0:jo["week-days"])||void 0===pe?void 0:pe.filterOption}),n("div",{children:["minute"!==sn&&"hour"!==sn&&No.includes("hours")&&e(V,{value:Bo,setValue:Ro,locale:_e,className:eo,disabled:null!==(fe=null===(me=null==jo?void 0:jo.hours)||void 0===me?void 0:me.disabled)&&void 0!==fe?fe:so,readOnly:null!==(he=null===(ye=null==jo?void 0:jo.hours)||void 0===ye?void 0:ye.readOnly)&&void 0!==he?he:po,leadingZero:null!==(Oe=null===(we=null==jo?void 0:jo.hours)||void 0===we?void 0:we.leadingZero)&&void 0!==Oe?Oe:fo,clockFormat:wo,period:sn,periodicityOnDoubleClick:null!==(ge=null===(be=null==jo?void 0:jo.hours)||void 0===be?void 0:be.periodicityOnDoubleClick)&&void 0!==ge?ge:bo,mode:null!==(Ce=null===(ke=null==jo?void 0:jo.hours)||void 0===ke?void 0:ke.mode)&&void 0!==Ce?Ce:ko,allowClear:null!==(De=null===(Ne=null==jo?void 0:jo.hours)||void 0===Ne?void 0:Ne.allowClear)&&void 0!==De?De:Mo,filterOption:null===(xe=null==jo?void 0:jo.hours)||void 0===xe?void 0:xe.filterOption}),"minute"!==sn&&No.includes("minutes")&&e(E,{value:_o,setValue:Go,locale:_e,period:sn,className:eo,disabled:null!==(je=null===(Me=null==jo?void 0:jo.minutes)||void 0===Me?void 0:Me.disabled)&&void 0!==je?je:so,readOnly:null!==(Se=null===(Pe=null==jo?void 0:jo.minutes)||void 0===Pe?void 0:Pe.readOnly)&&void 0!==Se?Se:po,leadingZero:null!==(Ae=null===(Fe=null==jo?void 0:jo.minutes)||void 0===Fe?void 0:Fe.leadingZero)&&void 0!==Ae?Ae:fo,clockFormat:wo,periodicityOnDoubleClick:null!==(Ee=null===(Ve=null==jo?void 0:jo.minutes)||void 0===Ve?void 0:Ve.periodicityOnDoubleClick)&&void 0!==Ee?Ee:bo,mode:null!==(He=null===(We=null==jo?void 0:jo.minutes)||void 0===We?void 0:We.mode)&&void 0!==He?He:ko,allowClear:null!==(Ie=null===(Te=null==jo?void 0:jo.minutes)||void 0===Te?void 0:Te.allowClear)&&void 0!==Ie?Ie:Mo,filterOption:null===(Le=null==jo?void 0:jo.minutes)||void 0===Le?void 0:Le.filterOption}),cn]})]})]}))}export{L as Cron,F as converter,L as default}; diff --git a/dist/esm/types/Cron.d.ts b/dist/esm/types/Cron.d.ts new file mode 100644 index 0000000..91e1add --- /dev/null +++ b/dist/esm/types/Cron.d.ts @@ -0,0 +1,3 @@ +/// +import { CronProps } from './types'; +export default function Cron(props: CronProps): JSX.Element; diff --git a/dist/esm/types/components/CustomSelect.d.ts b/dist/esm/types/components/CustomSelect.d.ts new file mode 100644 index 0000000..7816811 --- /dev/null +++ b/dist/esm/types/components/CustomSelect.d.ts @@ -0,0 +1,3 @@ +/// +import { CustomSelectProps } from '../types'; +export default function CustomSelect(props: CustomSelectProps): JSX.Element; diff --git a/dist/esm/types/constants.d.ts b/dist/esm/types/constants.d.ts new file mode 100644 index 0000000..3a6787b --- /dev/null +++ b/dist/esm/types/constants.d.ts @@ -0,0 +1,3 @@ +import { ShortcutsValues, Unit } from './types'; +export declare const SUPPORTED_SHORTCUTS: ShortcutsValues[]; +export declare const UNITS: Unit[]; diff --git a/dist/esm/types/converter.d.ts b/dist/esm/types/converter.d.ts new file mode 100644 index 0000000..97e28ec --- /dev/null +++ b/dist/esm/types/converter.d.ts @@ -0,0 +1,7 @@ +import { MutableRefObject } from 'react'; +import { AllowEmpty, ClockFormat, DropdownsConfig, LeadingZero, Locale, OnError, PeriodType, SetInternalError, SetValueNumbersOrUndefined, SetValuePeriod, Shortcuts, Unit } from './types'; +export declare function setValuesFromCronString(cronString: string, setInternalError: SetInternalError, onError: OnError, allowEmpty: AllowEmpty, internalValueRef: MutableRefObject, firstRender: boolean, locale: Locale, shortcuts: Shortcuts, setMinutes: SetValueNumbersOrUndefined, setHours: SetValueNumbersOrUndefined, setMonthDays: SetValueNumbersOrUndefined, setMonths: SetValueNumbersOrUndefined, setWeekDays: SetValueNumbersOrUndefined, setPeriod: SetValuePeriod): void; +export declare function getCronStringFromValues(period: PeriodType, months: number[] | undefined, monthDays: number[] | undefined, weekDays: number[] | undefined, hours: number[] | undefined, minutes: number[] | undefined, humanizeValue: boolean | undefined, dropdownsConfig: DropdownsConfig | undefined): string; +export declare function partToString(cronPart: number[], unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +export declare function formatValue(value: number, unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +export declare function parsePartArray(arr: number[], unit: Unit): number[]; diff --git a/dist/esm/types/fields/Hours.d.ts b/dist/esm/types/fields/Hours.d.ts new file mode 100644 index 0000000..8363238 --- /dev/null +++ b/dist/esm/types/fields/Hours.d.ts @@ -0,0 +1,3 @@ +/// +import { HoursProps } from '../types'; +export default function Hours(props: HoursProps): JSX.Element; diff --git a/dist/esm/types/fields/Minutes.d.ts b/dist/esm/types/fields/Minutes.d.ts new file mode 100644 index 0000000..67a2032 --- /dev/null +++ b/dist/esm/types/fields/Minutes.d.ts @@ -0,0 +1,3 @@ +/// +import { MinutesProps } from '../types'; +export default function Minutes(props: MinutesProps): JSX.Element; diff --git a/dist/esm/types/fields/MonthDays.d.ts b/dist/esm/types/fields/MonthDays.d.ts new file mode 100644 index 0000000..4cb26ae --- /dev/null +++ b/dist/esm/types/fields/MonthDays.d.ts @@ -0,0 +1,3 @@ +/// +import { MonthDaysProps } from '../types'; +export default function MonthDays(props: MonthDaysProps): JSX.Element | null; diff --git a/dist/esm/types/fields/Months.d.ts b/dist/esm/types/fields/Months.d.ts new file mode 100644 index 0000000..6666264 --- /dev/null +++ b/dist/esm/types/fields/Months.d.ts @@ -0,0 +1,3 @@ +/// +import { MonthsProps } from '../types'; +export default function Months(props: MonthsProps): JSX.Element; diff --git a/dist/esm/types/fields/Period.d.ts b/dist/esm/types/fields/Period.d.ts new file mode 100644 index 0000000..3a2364a --- /dev/null +++ b/dist/esm/types/fields/Period.d.ts @@ -0,0 +1,3 @@ +/// +import { PeriodProps } from '../types'; +export default function Period(props: PeriodProps): JSX.Element; diff --git a/dist/esm/types/fields/WeekDays.d.ts b/dist/esm/types/fields/WeekDays.d.ts new file mode 100644 index 0000000..4ad1e21 --- /dev/null +++ b/dist/esm/types/fields/WeekDays.d.ts @@ -0,0 +1,3 @@ +/// +import { WeekDaysProps } from '../types'; +export default function WeekDays(props: WeekDaysProps): JSX.Element | null; diff --git a/dist/esm/types/index.d.ts b/dist/esm/types/index.d.ts new file mode 100644 index 0000000..e7a6865 --- /dev/null +++ b/dist/esm/types/index.d.ts @@ -0,0 +1,5 @@ +import Cron from './Cron'; +import * as converter from './converter'; +export * from './types'; +export { Cron, converter }; +export default Cron; diff --git a/dist/esm/types/locale.d.ts b/dist/esm/types/locale.d.ts new file mode 100644 index 0000000..bac2501 --- /dev/null +++ b/dist/esm/types/locale.d.ts @@ -0,0 +1,2 @@ +import { DefaultLocale } from './types'; +export declare const DEFAULT_LOCALE_EN: DefaultLocale; diff --git a/dist/esm/types/types.d.ts b/dist/esm/types/types.d.ts new file mode 100644 index 0000000..39f5f5d --- /dev/null +++ b/dist/esm/types/types.d.ts @@ -0,0 +1,216 @@ +import { ButtonProps, SelectProps } from 'antd'; +import { Dispatch, SetStateAction } from 'react'; +export interface CronProps { + value: string; + setValue: SetValue; + className?: string; + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: LeadingZero; + defaultPeriod?: PeriodType; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + allowEmpty?: AllowEmpty; + shortcuts?: Shortcuts; + clockFormat?: ClockFormat; + clearButton?: boolean; + clearButtonProps?: ClearButtonProps; + clearButtonAction?: ClearButtonAction; + displayError?: boolean; + onError?: OnError; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + allowedDropdowns?: CronType[]; + allowedPeriods?: PeriodType[]; + dropdownsConfig?: DropdownsConfig; + locale?: Locale; +} +export interface Locale { + everyText?: string; + emptyMonths?: string; + emptyMonthDays?: string; + emptyMonthDaysShort?: string; + emptyWeekDays?: string; + emptyWeekDaysShort?: string; + emptyHours?: string; + emptyMinutes?: string; + emptyMinutesForHourPeriod?: string; + yearOption?: string; + monthOption?: string; + weekOption?: string; + dayOption?: string; + hourOption?: string; + minuteOption?: string; + rebootOption?: string; + prefixPeriod?: string; + prefixMonths?: string; + prefixMonthDays?: string; + prefixWeekDays?: string; + prefixWeekDaysForMonthAndYearPeriod?: string; + prefixHours?: string; + prefixMinutes?: string; + prefixMinutesForHourPeriod?: string; + suffixMinutesForHourPeriod?: string; + errorInvalidCron?: string; + clearButtonText?: string; + weekDays?: string[]; + months?: string[]; + altWeekDays?: string[]; + altMonths?: string[]; +} +export type SetValueFunction = (value: string, extra: SetValueFunctionExtra) => void; +export interface SetValueFunctionExtra { + selectedPeriod: PeriodType; +} +export type SetValue = SetValueFunction | Dispatch>; +export type CronError = { + type: 'invalid_cron'; + description: string; +} | undefined; +export type OnErrorFunction = (error: CronError) => void; +export type OnError = OnErrorFunction | Dispatch> | undefined; +export interface ClearButtonProps extends Omit { +} +export type ClearButtonAction = 'empty' | 'fill-with-every'; +export type PeriodType = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'reboot'; +export type AllowEmpty = 'always' | 'never' | 'for-default-value'; +export type CronType = 'period' | 'months' | 'month-days' | 'week-days' | 'hours' | 'minutes'; +export type LeadingZeroType = 'month-days' | 'hours' | 'minutes'; +export type LeadingZero = boolean | LeadingZeroType[]; +export type ClockFormat = '24-hour-clock' | '12-hour-clock'; +export type ShortcutsType = '@yearly' | '@annually' | '@monthly' | '@weekly' | '@daily' | '@midnight' | '@hourly' | '@reboot'; +export type Shortcuts = boolean | ShortcutsType[]; +export type Mode = 'multiple' | 'single'; +export type DropdownConfig = { + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: boolean; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + filterOption?: FilterOption; +}; +export type DropdownsConfig = { + 'period'?: Pick; + 'months'?: Omit; + 'month-days'?: Omit; + 'week-days'?: Omit; + 'hours'?: Omit; + 'minutes'?: Omit; +}; +export interface FieldProps { + value?: number[]; + setValue: SetValueNumbersOrUndefined; + locale: Locale; + className?: string; + disabled: boolean; + readOnly: boolean; + period: PeriodType; + periodicityOnDoubleClick: boolean; + mode: Mode; + allowClear?: boolean; + filterOption?: FilterOption; +} +export interface PeriodProps extends Omit { + value: PeriodType; + setValue: SetValuePeriod; + shortcuts: Shortcuts; + allowedPeriods: PeriodType[]; +} +export interface MonthsProps extends FieldProps { + humanizeLabels: boolean; +} +export interface MonthDaysProps extends FieldProps { + weekDays?: number[]; + leadingZero: LeadingZero; +} +export interface WeekDaysProps extends FieldProps { + humanizeLabels: boolean; + monthDays?: number[]; +} +export interface HoursProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +export interface MinutesProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +export interface CustomSelectProps extends Omit, 'mode' | 'tokenSeparators' | 'virtual' | 'onClick' | 'onBlur' | 'tagRender' | 'dropdownRender' | 'showSearch' | 'suffixIcon' | 'onChange' | 'dropdownMatchSelectWidth' | 'options' | 'onSelect' | 'onDeselect' | 'filterOption'> { + grid?: boolean; + setValue: SetValueNumbersOrUndefined; + optionsList?: string[]; + locale: Locale; + value?: number[]; + humanizeLabels?: boolean; + disabled: boolean; + readOnly: boolean; + leadingZero?: LeadingZero; + clockFormat?: ClockFormat; + period: PeriodType; + unit: Unit; + periodicityOnDoubleClick: boolean; + mode: Mode; + filterOption?: FilterOption; +} +export type SetValueNumbersOrUndefined = Dispatch>; +export type SetValuePeriod = Dispatch>; +export type SetInternalError = Dispatch>; +export interface DefaultLocale { + everyText: string; + emptyMonths: string; + emptyMonthDays: string; + emptyMonthDaysShort: string; + emptyWeekDays: string; + emptyWeekDaysShort: string; + emptyHours: string; + emptyMinutes: string; + emptyMinutesForHourPeriod: string; + yearOption: string; + monthOption: string; + weekOption: string; + dayOption: string; + hourOption: string; + minuteOption: string; + rebootOption: string; + prefixPeriod: string; + prefixMonths: string; + prefixMonthDays: string; + prefixWeekDays: string; + prefixWeekDaysForMonthAndYearPeriod: string; + prefixHours: string; + prefixMinutes: string; + prefixMinutesForHourPeriod: string; + suffixMinutesForHourPeriod: string; + errorInvalidCron: string; + clearButtonText: string; + weekDays: string[]; + months: string[]; + altWeekDays: string[]; + altMonths: string[]; +} +export interface Classes { + [key: string]: boolean; +} +export interface ShortcutsValues { + name: ShortcutsType; + value: string; +} +export interface Unit { + type: CronType; + min: number; + max: number; + total: number; + alt?: string[]; +} +export interface Clicks { + time: number; + value: number; +} +export type FilterOption = ({ value, label, }: { + value: string; + label: string; +}) => boolean; diff --git a/dist/esm/types/utils.d.ts b/dist/esm/types/utils.d.ts new file mode 100644 index 0000000..9a0686f --- /dev/null +++ b/dist/esm/types/utils.d.ts @@ -0,0 +1,8 @@ +import { Classes, Locale, OnError } from './types'; +export declare function range(start: number, end: number): number[]; +export declare function sort(array: number[]): number[]; +export declare function dedup(array: number[]): number[]; +export declare function classNames(classes: Classes): string; +export declare function setError(onError: OnError, locale: Locale): void; +export declare function usePrevious(value: any): any; +export declare function convertStringToNumber(str: string): number; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..93fc866 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,243 @@ +/// +import { ButtonProps, SelectProps } from 'antd'; +import { Dispatch, SetStateAction, MutableRefObject } from 'react'; + +interface CronProps { + value: string; + setValue: SetValue; + className?: string; + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: LeadingZero; + defaultPeriod?: PeriodType; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + allowEmpty?: AllowEmpty; + shortcuts?: Shortcuts; + clockFormat?: ClockFormat; + clearButton?: boolean; + clearButtonProps?: ClearButtonProps; + clearButtonAction?: ClearButtonAction; + displayError?: boolean; + onError?: OnError; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + allowedDropdowns?: CronType[]; + allowedPeriods?: PeriodType[]; + dropdownsConfig?: DropdownsConfig; + locale?: Locale; +} +interface Locale { + everyText?: string; + emptyMonths?: string; + emptyMonthDays?: string; + emptyMonthDaysShort?: string; + emptyWeekDays?: string; + emptyWeekDaysShort?: string; + emptyHours?: string; + emptyMinutes?: string; + emptyMinutesForHourPeriod?: string; + yearOption?: string; + monthOption?: string; + weekOption?: string; + dayOption?: string; + hourOption?: string; + minuteOption?: string; + rebootOption?: string; + prefixPeriod?: string; + prefixMonths?: string; + prefixMonthDays?: string; + prefixWeekDays?: string; + prefixWeekDaysForMonthAndYearPeriod?: string; + prefixHours?: string; + prefixMinutes?: string; + prefixMinutesForHourPeriod?: string; + suffixMinutesForHourPeriod?: string; + errorInvalidCron?: string; + clearButtonText?: string; + weekDays?: string[]; + months?: string[]; + altWeekDays?: string[]; + altMonths?: string[]; +} +type SetValueFunction = (value: string, extra: SetValueFunctionExtra) => void; +interface SetValueFunctionExtra { + selectedPeriod: PeriodType; +} +type SetValue = SetValueFunction | Dispatch>; +type CronError = { + type: 'invalid_cron'; + description: string; +} | undefined; +type OnErrorFunction = (error: CronError) => void; +type OnError = OnErrorFunction | Dispatch> | undefined; +interface ClearButtonProps extends Omit { +} +type ClearButtonAction = 'empty' | 'fill-with-every'; +type PeriodType = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'reboot'; +type AllowEmpty = 'always' | 'never' | 'for-default-value'; +type CronType = 'period' | 'months' | 'month-days' | 'week-days' | 'hours' | 'minutes'; +type LeadingZeroType = 'month-days' | 'hours' | 'minutes'; +type LeadingZero = boolean | LeadingZeroType[]; +type ClockFormat = '24-hour-clock' | '12-hour-clock'; +type ShortcutsType = '@yearly' | '@annually' | '@monthly' | '@weekly' | '@daily' | '@midnight' | '@hourly' | '@reboot'; +type Shortcuts = boolean | ShortcutsType[]; +type Mode = 'multiple' | 'single'; +type DropdownConfig = { + humanizeLabels?: boolean; + humanizeValue?: boolean; + leadingZero?: boolean; + disabled?: boolean; + readOnly?: boolean; + allowClear?: boolean; + periodicityOnDoubleClick?: boolean; + mode?: Mode; + filterOption?: FilterOption; +}; +type DropdownsConfig = { + 'period'?: Pick; + 'months'?: Omit; + 'month-days'?: Omit; + 'week-days'?: Omit; + 'hours'?: Omit; + 'minutes'?: Omit; +}; +interface FieldProps { + value?: number[]; + setValue: SetValueNumbersOrUndefined; + locale: Locale; + className?: string; + disabled: boolean; + readOnly: boolean; + period: PeriodType; + periodicityOnDoubleClick: boolean; + mode: Mode; + allowClear?: boolean; + filterOption?: FilterOption; +} +interface PeriodProps extends Omit { + value: PeriodType; + setValue: SetValuePeriod; + shortcuts: Shortcuts; + allowedPeriods: PeriodType[]; +} +interface MonthsProps extends FieldProps { + humanizeLabels: boolean; +} +interface MonthDaysProps extends FieldProps { + weekDays?: number[]; + leadingZero: LeadingZero; +} +interface WeekDaysProps extends FieldProps { + humanizeLabels: boolean; + monthDays?: number[]; +} +interface HoursProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +interface MinutesProps extends FieldProps { + leadingZero: LeadingZero; + clockFormat?: ClockFormat; +} +interface CustomSelectProps extends Omit, 'mode' | 'tokenSeparators' | 'virtual' | 'onClick' | 'onBlur' | 'tagRender' | 'dropdownRender' | 'showSearch' | 'suffixIcon' | 'onChange' | 'dropdownMatchSelectWidth' | 'options' | 'onSelect' | 'onDeselect' | 'filterOption'> { + grid?: boolean; + setValue: SetValueNumbersOrUndefined; + optionsList?: string[]; + locale: Locale; + value?: number[]; + humanizeLabels?: boolean; + disabled: boolean; + readOnly: boolean; + leadingZero?: LeadingZero; + clockFormat?: ClockFormat; + period: PeriodType; + unit: Unit; + periodicityOnDoubleClick: boolean; + mode: Mode; + filterOption?: FilterOption; +} +type SetValueNumbersOrUndefined = Dispatch>; +type SetValuePeriod = Dispatch>; +type SetInternalError = Dispatch>; +interface DefaultLocale { + everyText: string; + emptyMonths: string; + emptyMonthDays: string; + emptyMonthDaysShort: string; + emptyWeekDays: string; + emptyWeekDaysShort: string; + emptyHours: string; + emptyMinutes: string; + emptyMinutesForHourPeriod: string; + yearOption: string; + monthOption: string; + weekOption: string; + dayOption: string; + hourOption: string; + minuteOption: string; + rebootOption: string; + prefixPeriod: string; + prefixMonths: string; + prefixMonthDays: string; + prefixWeekDays: string; + prefixWeekDaysForMonthAndYearPeriod: string; + prefixHours: string; + prefixMinutes: string; + prefixMinutesForHourPeriod: string; + suffixMinutesForHourPeriod: string; + errorInvalidCron: string; + clearButtonText: string; + weekDays: string[]; + months: string[]; + altWeekDays: string[]; + altMonths: string[]; +} +interface Classes { + [key: string]: boolean; +} +interface ShortcutsValues { + name: ShortcutsType; + value: string; +} +interface Unit { + type: CronType; + min: number; + max: number; + total: number; + alt?: string[]; +} +interface Clicks { + time: number; + value: number; +} +type FilterOption = ({ value, label, }: { + value: string; + label: string; +}) => boolean; + +declare function Cron(props: CronProps): JSX.Element; + +declare function setValuesFromCronString(cronString: string, setInternalError: SetInternalError, onError: OnError, allowEmpty: AllowEmpty, internalValueRef: MutableRefObject, firstRender: boolean, locale: Locale, shortcuts: Shortcuts, setMinutes: SetValueNumbersOrUndefined, setHours: SetValueNumbersOrUndefined, setMonthDays: SetValueNumbersOrUndefined, setMonths: SetValueNumbersOrUndefined, setWeekDays: SetValueNumbersOrUndefined, setPeriod: SetValuePeriod): void; +declare function getCronStringFromValues(period: PeriodType, months: number[] | undefined, monthDays: number[] | undefined, weekDays: number[] | undefined, hours: number[] | undefined, minutes: number[] | undefined, humanizeValue: boolean | undefined, dropdownsConfig: DropdownsConfig | undefined): string; +declare function partToString(cronPart: number[], unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +declare function formatValue(value: number, unit: Unit, humanize?: boolean, leadingZero?: LeadingZero, clockFormat?: ClockFormat): string; +declare function parsePartArray(arr: number[], unit: Unit): number[]; + +declare const converter_d_setValuesFromCronString: typeof setValuesFromCronString; +declare const converter_d_getCronStringFromValues: typeof getCronStringFromValues; +declare const converter_d_partToString: typeof partToString; +declare const converter_d_formatValue: typeof formatValue; +declare const converter_d_parsePartArray: typeof parsePartArray; +declare namespace converter_d { + export { + converter_d_setValuesFromCronString as setValuesFromCronString, + converter_d_getCronStringFromValues as getCronStringFromValues, + converter_d_partToString as partToString, + converter_d_formatValue as formatValue, + converter_d_parsePartArray as parsePartArray, + }; +} + +export { AllowEmpty, Classes, ClearButtonAction, ClearButtonProps, Clicks, ClockFormat, Cron, CronError, CronProps, CronType, CustomSelectProps, DefaultLocale, DropdownConfig, DropdownsConfig, FieldProps, FilterOption, HoursProps, LeadingZero, LeadingZeroType, Locale, MinutesProps, Mode, MonthDaysProps, MonthsProps, OnError, OnErrorFunction, PeriodProps, PeriodType, SetInternalError, SetValue, SetValueFunction, SetValueFunctionExtra, SetValueNumbersOrUndefined, SetValuePeriod, Shortcuts, ShortcutsType, ShortcutsValues, Unit, WeekDaysProps, converter_d as converter, Cron as default }; diff --git a/dist/styles.css b/dist/styles.css new file mode 100644 index 0000000..2f324fa --- /dev/null +++ b/dist/styles.css @@ -0,0 +1,126 @@ +.react-js-cron { + display: flex; + align-items: flex-start; + flex-wrap: wrap; +} +.react-js-cron > div, +.react-js-cron-field { + display: flex; + align-items: center; +} +.react-js-cron-field { + margin-bottom: 10px; +} +.react-js-cron-field > span { + margin-left: 5px; +} +div.react-js-cron-select { + margin-left: 5px; +} +.react-js-cron-select.react-js-cron-select-no-prefix { + margin-left: 0; +} +div.react-js-cron-error .react-js-cron-select .ant-select-selector { + border-color: #ff4d4f; + background: #fff6f6; +} +div.react-js-cron-custom-select { + min-width: 70px; + z-index: 1; +} +div.react-js-cron-error div.react-js-cron-custom-select { + background: #fff6f6; +} +div.react-js-cron-select.react-js-cron-custom-select.ant-select + div.ant-select-selector { + padding-left: 11px; + padding-right: 30px; +} +.react-js-cron-read-only + div.react-js-cron-select.react-js-cron-custom-select.ant-select + div.ant-select-selector { + padding-right: 11px; +} +div.react-js-cron-custom-select .ant-select-selection-search { + width: 0 !important; + margin: 0 !important; +} +div.react-js-cron-custom-select .ant-select-selection-placeholder { + position: static; + top: 50%; + right: auto; + left: auto; + transform: none; + transition: none; + opacity: 1; + color: inherit; +} +.react-js-cron-week-days-placeholder + .react-js-cron-custom-select + .ant-select-selection-placeholder, +.react-js-cron-month-days-placeholder + .react-js-cron-custom-select + .ant-select-selection-placeholder { + opacity: 0.4; +} +.react-js-cron-custom-select-dropdown { + min-width: 0 !important; + width: 174px !important; +} +.react-js-cron-custom-select-dropdown .rc-virtual-list { + max-height: none !important; +} +.react-js-cron-custom-select-dropdown-grid .rc-virtual-list-holder { + max-height: initial !important; +} +.react-js-cron-custom-select-dropdown-grid .rc-virtual-list-holder-inner { + display: grid !important; + grid-template-columns: repeat(4, 1fr); +} +.react-js-cron-custom-select-dropdown-grid + .rc-virtual-list-holder-inner + .ant-select-item-option-content { + text-align: center; +} +.react-js-cron-custom-select-dropdown-hours-twelve-hour-clock { + width: 260px !important; +} +.react-js-cron-custom-select-dropdown-minutes-large { + width: 300px !important; +} +.react-js-cron-custom-select-dropdown-minutes-large + .rc-virtual-list-holder-inner { + grid-template-columns: repeat(6, 1fr); +} +.react-js-cron-custom-select-dropdown-minutes-medium { + width: 220px !important; +} +.react-js-cron-custom-select-dropdown-minutes-medium + .rc-virtual-list-holder-inner { + grid-template-columns: repeat(5, 1fr); +} +.react-js-cron-period > span:first-child { + margin-left: 0 !important; +} +.react-js-cron-period + .react-js-cron-select.ant-select-single.ant-select-open + .ant-select-selection-item { + opacity: 1; +} +.react-js-cron-select-dropdown-period { + min-width: 0 !important; + width: auto !important; +} +.react-js-cron-clear-button { + margin-left: 10px; + margin-bottom: 10px; +} +.react-js-cron-disabled .react-js-cron-select.ant-select-disabled { + background: #f5f5f5; +} +div.react-js-cron-select.react-js-cron-custom-select.ant-select + div.ant-select-selector + > .ant-select-selection-overflow { + align-items: center; + flex: initial; +}