@instincthub/react-ui 0.1.40 → 0.1.42

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,2 +1,2 @@
1
- import{slicedToArray as e,asyncToGenerator as a,regenerator as r}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as t}from"react/jsx-runtime";import{useState as n,useEffect as i}from"react";import l from"../forms/TextField.js";import{isValidAlphanumeric as o,isValidEmail as s,reqOptions as u,API_HOST_URL as c}from"../lib/helpFunction.js";function d(d){var m=d.name,f=d.type,v=d.label,p=d.required,b=d.key;d.setIsValid;var h=n({note:"",valid:!1}),y=e(h,2),g=y[0],_=y[1];function S(e){return T.apply(this,arguments)}function T(){return(T=a(r().m(function e(a){var t,n,i,l,o;return r().w(function(e){for(;;)switch(e.n){case 0:return(t=new FormData).append("field",m),t.append("field_value",a),n=u("POST",t),i="".concat(c,"auth/username_email_available/"),e.n=1,fetch(i,n);case 1:return l=e.v,e.n=2,l.json();case 2:return o=e.v,e.a(2,o.message)}},e)}))).apply(this,arguments)}var w=function(){var e=a(r().m(function e(a){var t;return r().w(function(e){for(;;)switch(e.n){case 0:if(t=null,m.includes("username")?t=o(a.target.value):"email"===m&&(t=s(a.target.value)),t||null===t){e.n=1;break}a.target.classList.add("ihub-is_invalid"),_({valid:!1,note:m.includes("username")?"Should contain only letters (a-z, A-Z) and numbers (0-9).":"Please enter a valid email."}),e.n=3;break;case 1:return e.n=2,S(a.target.value);case 2:e.v?(a.target.style.borderColor="#69779B",a.target.classList.remove("ihub-is_invalid"),_({valid:!0,note:""})):(a.target.classList.add("ihub-is_invalid"),_({valid:!1,note:"This ".concat(m," is already taken. Please try a different ").concat(m,".")}));case 3:return e.a(2)}},e)}));return function(a){return e.apply(this,arguments)}}();return i(function(){if("undefined"!=typeof document&&document.querySelector("#SubmitBtn")){var e=document.querySelector("#SubmitBtn"),a=document.querySelector(".ihub-is_invalid");e&&(a||!g.valid&&!a?e.disabled=!0:e.disabled=!1)}},[g]),t("div",{children:t(l,{name:m,type:f,label:v,required:p,onChange:w,note:g.note,TextTransform:"lowercase"})},b)}export{d as default};
1
+ import{slicedToArray as n,asyncToGenerator as e,regenerator as t,toConsumableArray as r}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as a,jsx as c}from"react/jsx-runtime";import{useState as o,useRef as u,useCallback as i,useEffect as l}from"react";import s from"../forms/TextField.js";import{API_HOST_URL as p,reqOptions as f,isValidAlphanumeric as d,isValidEmail as m}from"../lib/helpFunction.js";function h(n,e){var t=n.toLowerCase().trim().replace(/[^a-z0-9\s]/g,"").split(/\s+/).filter(Boolean);if(0===t.length)return[];var a=t[0],c=t.length>1?t[t.length-1]:"",o=(new Date).getFullYear().toString().slice(-2),u=Math.floor(900*Math.random()+100),i=[];return a&&c?(i.push("".concat(a).concat(c)),i.push("".concat(a,"-").concat(c)),i.push("".concat(a).concat(c).concat(o)),i.push("".concat(c,"-").concat(a)),i.push("".concat(a,"-").concat(c,"-").concat(o)),i.push("".concat(a).concat(u))):(i.push("".concat(a).concat(o)),i.push("".concat(a).concat(u)),i.push("".concat(a,"-hub")),i.push("".concat(a,"-").concat(o))),e&&(i.push("".concat(e).concat(o)),i.push("".concat(e,"-").concat(u))),r(new Set(i)).filter(function(n){return n!==e.toLowerCase()&&n.length>=3}).slice(0,4)}function v(r){var v=r.name,g=r.type,b=r.label,y=r.required,w=r.key,T=r.setIsValid,x=r.apiUrl,_=r.rawName,S=o({note:"",valid:!1}),k=n(S,2),C=k[0],L=k[1],j=o([]),q=n(j,2),z=q[0],A=q[1],B=u(null),F=u(null),P=u(null),D=u(""),E=x||"".concat(p,"auth/username_email_available/"),M=i(function(){var n=B.current;return n?n.querySelector("input"):null},[]),N=i(function(){var n=e(t().m(function n(e){var r,a,c,o;return t().w(function(n){for(;;)switch(n.p=n.n){case 0:return n.p=0,(r=new FormData).append("field",v),r.append("field_value",e),a=f("POST",r),n.n=1,fetch(E,a);case 1:return c=n.v,n.n=2,c.json();case 2:return o=n.v,n.a(2,!!o.message);case 3:return n.p=3,n.v,n.a(2,!1)}},n,null,[[0,3]])}));return function(e){return n.apply(this,arguments)}}(),[v,E]),O=i(function(n){var e,t=M();if(t){var r=null===(e=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value"))||void 0===e?void 0:e.set;null==r||r.call(t,n),t.dispatchEvent(new Event("input",{bubbles:!0}))}},[M]),H=i(function(n,r){F.current&&clearTimeout(F.current),F.current=setTimeout(e(t().m(function e(){var a;return t().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,N(n);case 1:e.v?(r&&(r.style.borderColor="#69779B",r.classList.remove("ihub-is_invalid")),null==T||T(!0),A([]),L({valid:!0,note:""})):(null==r||r.classList.add("ihub-is_invalid"),null==T||T(!1),a=_?h(_,n):[],A(a),L({valid:!1,note:"This ".concat("channel"===v?"handle":v," is already taken.").concat(a.length>0?" Try one of these:":"")}));case 2:return e.a(2)}},e)})),500)},[v,_,N,T]),I=i(function(){var n=e(t().m(function n(e){var r,a;return t().w(function(n){for(;;)switch(n.n){case 0:if(r=e.target.value.trim(),A([]),r){n.n=1;break}return L({note:"",valid:!1}),null==T||T(!1),n.a(2);case 1:if(a=null,"channel"===v?a=r.length>=3&&/^[a-zA-Z0-9-]+$/.test(r):v.includes("username")?a=d(r):"email"===v&&(a=m(r)),!1!==a){n.n=2;break}return e.target.classList.add("ihub-is_invalid"),null==T||T(!1),L({valid:!1,note:"email"===v?"Please enter a valid email.":"channel"===v?"Should contain only letters, numbers, and hyphens (min 3 characters).":"Should contain only letters (a-z, A-Z) and numbers (0-9)."}),n.a(2);case 2:H(r,e.target);case 3:return n.a(2)}},n)}));return function(e){return n.apply(this,arguments)}}(),[v,T,H]);return l(function(){if(_){var n=function(n){return n.toLowerCase().trim().replace(/[^a-z0-9\s-]/g,"").replace(/[\s_]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}(_);if(n&&n!==D.current)return P.current&&clearTimeout(P.current),P.current=setTimeout(function(){D.current=n,O(n)},600),function(){P.current&&clearTimeout(P.current)}}},[_,O]),l(function(){if("undefined"!=typeof document){var n=document.querySelector("#SubmitBtn");if(n){var e=document.querySelector(".ihub-is_invalid");n.disabled=!(!e&&C.valid)}}},[C]),l(function(){return function(){F.current&&clearTimeout(F.current),P.current&&clearTimeout(P.current)}},[]),a("div",{ref:B,children:[c(s,{name:v,type:g,label:b,required:y,onChange:I,note:C.note,TextTransform:"lowercase"}),z.length>0&&c("div",{className:"ihub-username-suggestions",children:z.map(function(n){return c("button",{type:"button",className:"ihub-username-suggestion",onClick:function(){return O(n)},children:n},n)})}),c("style",{children:"\n .ihub-username-suggestions {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n margin-top: 6px;\n margin-bottom: 8px;\n }\n .ihub-username-suggestion {\n padding: 4px 12px;\n font-size: 13px;\n border: 1px solid #00838f;\n background: rgba(0, 131, 143, 0.08);\n color: #00838f;\n border-radius: 16px;\n cursor: pointer;\n transition: all 0.15s ease;\n font-weight: 500;\n }\n .ihub-username-suggestion:hover {\n background: #00838f;\n color: #fff;\n }\n "})]},w)}export{v as default};
2
2
  //# sourceMappingURL=IsUsernameEmailTaken.js.map
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,objectSpread2 as t,defineProperty as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as n,jsx as i,Fragment as r}from"react/jsx-runtime";import d from"@mui/icons-material/CalendarMonthOutlined";import o from"@mui/icons-material/AccessTime";import{useState as l,useRef as u,useEffect as s,useCallback as c,useMemo as m}from"react";import{createPortal as h}from"react-dom";import{startOfDay as p}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfDay.js";import{isBefore as f}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isBefore.js";import{isAfter as y}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isAfter.js";import{endOfDay as b}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfDay.js";import{startOfMonth as v}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfMonth.js";import{getDay as g}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDay.js";import{getDaysInMonth as M}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDaysInMonth.js";import{isSameDay as N}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isSameDay.js";import{isValid as H}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isValid.js";import{setHours as _}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setHours.js";import{setMinutes as S}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setMinutes.js";import{setSeconds as w}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setSeconds.js";import{subMonths as D}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subMonths.js";import{addMonths as k}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js";import{parse as x}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/parse.js";import{formatDate as C}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/format.js";var I=function(I){var A=I.label,T=I.value,j=void 0===T?"":T,P=I.onChange,L=I.required,F=void 0!==L&&L,O=I.minDate,E=I.maxDate,W=I.minTime,Y=I.maxTime,q=I.disabledDates,K=void 0===q?[]:q,B=I.disabledTimes,z=void 0===B?[]:B,R=I.use12Hour,Q=void 0!==R&&R,V=I.includeSeconds,G=void 0!==V&&V,J=I.timeStep,U=void 0===J?30:J,X=I.dateFormat,Z=void 0===X?"yyyy-MM-dd":X,$=I.timeFormat,ee=void 0===$?Q?"hh:mm a":"HH:mm":$;I.locale;var te=I.placeholder,ae=I.errorMessage,ne=I.className,ie=void 0===ne?"":ne,re=I.name,de=I.id,oe=I.disabled,le=void 0!==oe&&oe,ue=I.showCalendarIcon,se=void 0===ue||ue,ce=I.showTimeIcon,me=void 0===ce||ce,he=I.showQuickActions,pe=void 0===he||he,fe=I.ariaLabel,ye=I.autoFocus,be=void 0!==ye&&ye,ve=I.onFocus,ge=I.onBlur,Me=I.useSeparateFields,Ne=void 0!==Me&&Me,He=I.mode,_e=void 0===He?"datetime":He,Se=I.maxWidth,we=void 0===Se?600:Se,De=function(e){if(!e)return null;try{var t=new Date(e);return H(t)?t:null}catch(e){return null}},ke=l(De(j)),xe=e(ke,2),Ce=xe[0],Ie=xe[1],Ae=l(""),Te=e(Ae,2),je=Te[0],Pe=Te[1],Le=l(!1),Fe=e(Le,2),Oe=Fe[0],Ee=Fe[1],We=l(!1),Ye=e(We,2),qe=Ye[0],Ke=Ye[1],Be=l("time"===_e?"time":"calendar"),ze=e(Be,2),Re=ze[0],Qe=ze[1],Ve=l(ae||null),Ge=e(Ve,2),Je=Ge[0],Ue=Ge[1],Xe=l(0),Ze=e(Xe,2);Ze[0];var $e=Ze[1],et=l({year:"",month:"",day:"",hour:"",minute:"",second:"",ampm:"AM"}),tt=e(et,2),at=tt[0],nt=tt[1],it=l(Ce||new Date),rt=e(it,2),dt=rt[0],ot=rt[1],lt=l(Ce?C(Ce,"HH"):"00"),ut=e(lt,2),st=ut[0],ct=ut[1],mt=l(Ce?C(Ce,"mm"):"00"),ht=e(mt,2),pt=ht[0],ft=ht[1],yt=l(Ce?C(Ce,"ss"):"00"),bt=e(yt,2),vt=bt[0],gt=bt[1],Mt=l(Ce&&Ce.getHours()>=12?"PM":"AM"),Nt=e(Mt,2),Ht=Nt[0],_t=Nt[1],St=u(null),wt=u(null),Dt=u(null),kt=u(null),xt=u({}),Ct=l({}),It=e(Ct,2),At=It[0],Tt=It[1];s(function(){Ce&&(ct(C(Ce,"HH")),ft(C(Ce,"mm")),gt(C(Ce,"ss")),_t(Ce.getHours()>=12?"PM":"AM"))},[Ce]);var jt=c(function(){var e=Ne?Dt.current:kt.current;if(e)if(window.innerWidth<=768)Tt({position:"fixed",top:"50%",left:"50%",right:"auto",transform:"translate(-50%, -50%)",width:Math.min(.95*window.innerWidth,400),maxWidth:we,maxHeight:"90vh",marginTop:0,zIndex:9999});else{var a=e.getBoundingClientRect(),n=window.innerHeight,i=n-a.bottom<450&&a.top>450,r=Math.min(Math.max(a.width,320),we);Tt(t(t({position:"fixed",left:a.left,right:"auto",width:r,maxWidth:we,marginTop:0},i?{bottom:n-a.top+4,top:"auto"}:{top:a.bottom+4,bottom:"auto"}),{},{zIndex:9999}))}},[Ne,we]);s(function(){if(qe)return jt(),window.addEventListener("scroll",jt,!0),window.addEventListener("resize",jt),function(){window.removeEventListener("scroll",jt,!0),window.removeEventListener("resize",jt)}},[qe,jt]);var Pt=c(function(e){if(!e)return"";switch(_e){case"date":return C(p(e),"yyyy-MM-dd");case"time":return C(e,G?"HH:mm:ss":"HH:mm");default:return e.toISOString()}},[_e,G]),Lt=c(function(e){var t=e||Ce;if(!t)return"";try{if("date"===_e)return C(t,Z);if("time"===_e)return C(t,G?ee:ee.replace(":ss",""));var a=C(t,Z),n=C(t,G?ee:ee.replace(":ss",""));return"".concat(a," ").concat(n)}catch(e){return""}},[Ce,_e,Z,ee,G]);s(function(){if(void 0!==j){var e=De(j);Ie(e),Oe||Pe(e?Lt(e):"")}},[j,Oe,Lt]),s(function(){if(qe){var e=function(e){var t,a,n,i=e.target;null!==(t=St.current)&&void 0!==t&&t.contains(i)||Ne&&null!==(a=Dt.current)&&void 0!==a&&a.contains(i)||!Ne&&null!==(n=kt.current)&&void 0!==n&&n.contains(i)||Ke(!1)},t=setTimeout(function(){document.addEventListener("mousedown",e)},0);return function(){clearTimeout(t),document.removeEventListener("mousedown",e)}}},[qe,Ne]);var Ft=c(function(e){var t=C(e,"yyyy-MM-dd");return K.includes(t)},[K]),Ot=c(function(e){return(!O||!f(e,p(new Date(O))))&&(!E||!y(e,b(new Date(E))))},[O,E]),Et=c(function(t,a){if(!W&&!Y)return!0;var n=60*t+a;if(W){var i=W.split(":").map(Number),r=e(i,2);if(n<60*r[0]+r[1])return!1}if(Y){var d=Y.split(":").map(Number),o=e(d,2);if(n>60*o[0]+o[1])return!1}return!0},[W,Y]),Wt=c(function(e,t){var a="".concat(e.toString().padStart(2,"0"),":").concat(t.toString().padStart(2,"0"));return z.includes(a)},[z]),Yt=c(function(){if(Ue(null),F&&!Ce)return Ue("Date and time are required"),!1;if(!Ce)return!0;if(!Ot(Ce))return Ue("Selected date is outside allowed range"),!1;if(Ft(Ce))return Ue("Selected date is not available"),!1;var e=Ce.getHours(),t=Ce.getMinutes();return Et(e,t)?!Wt(e,t)||(Ue("Selected time is not available"),!1):(Ue("Selected time is outside allowed range"),!1)},[Ce,F,Ot,Ft,Et,Wt]),qt=function(e){if(!Ft(e)&&Ot(e)){var t=e;if("date"===_e)t=p(e),Ie(t),ot(t),null==P||P(Pt(t)),Ke(!1),Ue(null);else{if(Ce)t=_(e,Ce.getHours()),t=S(t,Ce.getMinutes()),t=w(t,Ce.getSeconds());else{var a=new Date;t=_(e,a.getHours()),t=S(t,a.getMinutes()),t=w(t,0)}Ie(t),ot(t),null==P||P(Pt(t)),"datetime"===_e&&Qe("time")}}},Kt=m(function(){for(var e=dt.getFullYear(),t=dt.getMonth(),a=v(dt),n=g(a),i=M(dt),r=[],d=0;d<n;d++)r.push(null);for(var o=1;o<=i;o++)r.push(new Date(e,t,o));return r},[dt]),Bt=m(function(){for(var e=[],t=0;t<24;t++)for(var a=0;a<60;a+=U)if(!Wt(t,a)&&Et(t,a)){var n=t,i="";Q&&(i=t<12?" AM":" PM",n=0===t?12:t>12?t-12:t);var r="".concat(n.toString().padStart(2,"0"),":").concat(a.toString().padStart(2,"0")).concat(i);e.push({hours:t,minutes:a,display:r})}return e},[U,Q,Wt,Et]),zt=function(e){if(!e.trim())return null;for(var t=0,a=["".concat(Z," ").concat(ee),"".concat(Z," ").concat(ee.replace(":ss","")),"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd HH:mm","yyyy-MM-dd'T'HH:mm:ss","yyyy-MM-dd'T'HH:mm","MM/dd/yyyy HH:mm","MM/dd/yyyy hh:mm a","MM-dd-yyyy HH:mm","MM-dd-yyyy hh:mm a","dd/MM/yyyy HH:mm","dd/MM/yyyy hh:mm a","dd-MM-yyyy HH:mm","dd-MM-yyyy hh:mm a","yyyy-MM-dd","MM/dd/yyyy","dd/MM/yyyy","MM-dd-yyyy","dd-MM-yyyy"];t<a.length;t++){var n=a[t];try{var i=x(e,n,new Date);if(H(i))return i}catch(e){}}try{var r=new Date(e);if(H(r))return r}catch(e){}return null},Rt=function(){var e=new Date,t="date"===_e?p(e):e;Ie(t),ot(t),null==P||P(Pt(t)),Ue(null)},Qt=function(){Ie(null),ct("00"),ft("00"),gt("00"),_t("AM"),null==P||P(""),Ue(null)},Vt=function(e,n){var i=t(t({},at),{},a({},e,n));nt(i);var r=i.year,d=i.month,o=i.day,l=i.hour,u=i.minute,s=i.second,c=i.ampm;if(r&&d&&o&&l&&u)try{var m=parseInt(l);Q&&("PM"===c&&12!==m&&(m+=12),"AM"===c&&12===m&&(m=0));var h=new Date(parseInt(r),parseInt(d)-1,parseInt(o),m,parseInt(u),G?parseInt(s||"0"):0);if(H(h)){var f="date"===_e?p(h):h;Ie(f),null==P||P(Pt(f)),Ue(null)}}catch(e){}},Gt=function(e,t,a,n){if(e.target.value.length>=a&&n&&/\d/.test(e.key)){e.preventDefault();var i=xt.current[n];i&&(i.focus(),i.select())}};return s(function(){Ce&&Ne&&nt({year:Ce.getFullYear().toString(),month:(Ce.getMonth()+1).toString().padStart(2,"0"),day:Ce.getDate().toString().padStart(2,"0"),hour:Q?(Ce.getHours()%12||12).toString().padStart(2,"0"):Ce.getHours().toString().padStart(2,"0"),minute:Ce.getMinutes().toString().padStart(2,"0"),second:Ce.getSeconds().toString().padStart(2,"0"),ampm:Ce.getHours()>=12?"PM":"AM"})},[Ce,Ne,Q]),n("div",{className:"ihub-datetime-picker-wrapper ".concat(ie),style:{maxWidth:we},children:[n("div",{className:"ihub-datetime-picker ".concat(Je?"ihub-error":""),children:[n("label",{className:"ihub-datetime-label",htmlFor:de||re,children:[A,F&&i("span",{className:"ihub-required",children:"*"})]}),n("div",Ne?{ref:Dt,className:"ihub-datetime-separate-fields",children:[("date"===_e||"datetime"===_e)&&n("div",{className:"ihub-datetime-date-fields",children:[i("input",{ref:function(e){xt.current.year=e},type:"text",className:"ihub-datetime-field ihub-datetime-year",value:at.year,onChange:function(e){return Vt("year",e.target.value.replace(/\D/g,"").slice(0,4))},onKeyDown:function(e){return Gt(e,0,4,"month")},placeholder:"YYYY",maxLength:4,disabled:le,id:"".concat(de,"-year"),"aria-label":"Year"}),i("span",{className:"ihub-datetime-separator",children:"/"}),i("input",{ref:function(e){xt.current.month=e},type:"text",className:"ihub-datetime-field ihub-datetime-month",value:at.month,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<=12||""===t)&&Vt("month",t)},onKeyDown:function(e){return Gt(e,0,2,"day")},placeholder:"MM",maxLength:2,disabled:le,id:"".concat(de,"-month"),"aria-label":"Month"}),i("span",{className:"ihub-datetime-separator",children:"/"}),i("input",{ref:function(e){xt.current.day=e},type:"text",className:"ihub-datetime-field ihub-datetime-day",value:at.day,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<=31||""===t)&&Vt("day",t)},onKeyDown:function(e){return Gt(e,0,2,"hour")},placeholder:"DD",maxLength:2,disabled:le,id:"".concat(de,"-day"),"aria-label":"Day"})]}),("time"===_e||"datetime"===_e)&&n("div",{className:"ihub-datetime-time-fields",children:[i("input",{ref:function(e){xt.current.hour=e},type:"text",className:"ihub-datetime-field ihub-datetime-hour",value:at.hour,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2),a=Q?12:23;(parseInt(t)<=a||""===t)&&Vt("hour",t)},onKeyDown:function(e){return Gt(e,0,2,"minute")},placeholder:"HH",maxLength:2,disabled:le,id:"".concat(de,"-hour"),"aria-label":"Hour"}),i("span",{className:"ihub-datetime-separator",children:":"}),i("input",{ref:function(e){xt.current.minute=e},type:"text",className:"ihub-datetime-field ihub-datetime-minute",value:at.minute,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<60||""===t)&&Vt("minute",t)},onKeyDown:function(e){return Gt(e,0,2,G?"second":void 0)},placeholder:"MM",maxLength:2,disabled:le,id:"".concat(de,"-minute"),"aria-label":"Minute"}),G&&n(r,{children:[i("span",{className:"ihub-datetime-separator",children:":"}),i("input",{ref:function(e){xt.current.second=e},type:"text",className:"ihub-datetime-field ihub-datetime-second",value:at.second,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<60||""===t)&&Vt("second",t)},placeholder:"SS",maxLength:2,disabled:le,id:"".concat(de,"-second"),"aria-label":"Second"})]}),Q&&i("button",{type:"button",className:"ihub-datetime-field ihub-datetime-ampm-toggle",onClick:function(){return Vt("ampm","AM"===at.ampm?"PM":"AM")},disabled:le,"aria-label":"Toggle AM/PM, currently ".concat(at.ampm),children:at.ampm})]}),n("div",{className:"ihub-datetime-icons",children:[se&&("date"===_e||"datetime"===_e)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(Ke(!0),Qe("calendar"))},disabled:le,"aria-label":"Open calendar",children:i(d,{})}),me&&("time"===_e||"datetime"===_e)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(Ke(!0),Qe("time"))},disabled:le,"aria-label":"Open time picker",children:i(o,{})})]})]}:{ref:kt,className:"ihub-datetime-input-container",children:[i("input",{ref:wt,type:"text",className:"ihub-datetime-input",value:Oe?je:Lt(),onChange:function(e){var t=e.target,a=t.value;t.selectionStart;var n=function(e){var t=G?"".concat(Z," ").concat(ee):"".concat(Z," ").concat(ee.replace(":ss","")),a=e.replace(/\D/g,""),n={"yyyy-MM-dd HH:mm:ss":[4,2,2,2,2,2],"yyyy-MM-dd HH:mm":[4,2,2,2,2],"MM/dd/yyyy HH:mm":[2,2,4,2,2],"MM/dd/yyyy hh:mm a":[2,2,4,2,2],"dd/MM/yyyy HH:mm":[2,2,4,2,2],"dd/MM/yyyy hh:mm a":[2,2,4,2,2]}[t];n||(n=[4,2,2,2,2]);for(var i=t.replace(/[yMdHhms]/g,"").split("").filter(function(e){return e.trim()}),r="",d=0,o=0,l=0;l<n.length;l++){var u=n[l],s=a.slice(d,d+u);s&&(r+=s,d+=u,l<n.length-1&&d<a.length&&o<i.length&&(r+=i[o]),o++)}return{formatted:r,cursorPos:r.length}}(a),i=n.formatted,r=n.cursorPos;if(Pe(i),$e(r),setTimeout(function(){t&&t.setSelectionRange&&t.setSelectionRange(r,r)},0),!i.trim())return Ie(null),null==P||P(""),void Ue(null);var d=zt(i);if(d){var o="date"===_e?p(d):d;Ie(o),null==P||P(Pt(o)),Ue(null)}},onFocus:function(e){Ee(!0),Ce&&!je&&Pe(Lt()),null==ve||ve(e)},onBlur:function(e){if(Ee(!1),je.trim()){var t=zt(je);if(t){var a="date"===_e?p(t):t;Ie(a),null==P||P(Pt(a)),Pe(Lt(a)),Ue(null)}else Ue("Invalid date/time format")}else Ue(F?"Date and time are required":null);Yt(),null==ge||ge(e)},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Ke(!qe)),"Escape"===e.key&&Ke(!1),"Tab"===e.key&&qe&&e.stopPropagation()},placeholder:Oe?function(e){for(var t=("date"===_e?Z:"time"===_e?G?ee:ee.replace(":ss",""):G?"".concat(Z," ").concat(ee):"".concat(Z," ").concat(ee.replace(":ss",""))).replace(/yyyy/g,"____").replace(/yy/g,"__").replace(/MM/g,"__").replace(/dd/g,"__").replace(/HH/g,"__").replace(/hh/g,"__").replace(/mm/g,"__").replace(/ss/g,"__").replace(/a/g,"__"),a="",n=0,i=0;i<t.length&&n<e.length;i++){var r=t[i],d=e[n];"_"===r?d&&/[^\d]/.test(d)&&i+1<t.length&&/[^_]/.test(t[i+1])?(a+=t[i+1],n++,i++):d&&/\d/.test(d)?(a+=d,n++):a+="_":(a+=r,d===r&&n++)}return a.length<t.length&&(a+=t.slice(a.length)),a}(je):"date"===_e?te||Z:"time"===_e?te||ee:te||"".concat(Z," ").concat(ee),disabled:le,required:F,name:re,id:de,"aria-label":fe||A,"aria-invalid":!!Je,"aria-describedby":Je?"".concat(de,"-error"):void 0,autoFocus:be}),n("div",{className:"ihub-datetime-icons",children:[se&&("date"===_e||"datetime"===_e)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(Ke(!0),Qe("calendar"))},disabled:le,"aria-label":"Open calendar",children:i(d,{})}),me&&("time"===_e||"datetime"===_e)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(Ke(!0),Qe("time"))},disabled:le,"aria-label":"Open time picker",children:i(o,{})})]})]}),Je&&i("div",{id:"".concat(de,"-error"),className:"ihub-datetime-error",children:Je}),qe&&!le&&"undefined"!=typeof document&&h(n("div",{ref:St,className:"ihub-datetime-picker-dropdown",style:At,role:"dialog","aria-label":"Date and time picker",onMouseDown:function(e){return e.stopPropagation()},children:["datetime"===_e&&n("div",{className:"ihub-datetime-tabs",children:[i("button",{className:"ihub-datetime-tab ".concat("calendar"===Re?"active":""),onClick:function(){return Qe("calendar")},type:"button",children:"Date"}),i("button",{className:"ihub-datetime-tab ".concat("time"===Re?"active":""),onClick:function(){return Qe("time")},type:"button",children:"Time"})]}),("calendar"===Re||"date"===_e)&&("date"===_e||"datetime"===_e)&&n("div",{className:"ihub-datetime-calendar",children:[n("div",{className:"ihub-datetime-month-nav",children:[i("button",{type:"button",onClick:function(){ot(D(dt,1))},className:"ihub-datetime-nav-btn","aria-label":"Previous month",children:"‹"}),i("span",{className:"ihub-datetime-month-year",children:C(dt,"MMMM yyyy")}),i("button",{type:"button",onClick:function(){ot(k(dt,1))},className:"ihub-datetime-nav-btn","aria-label":"Next month",children:"›"})]}),i("div",{className:"ihub-datetime-weekdays",children:["Su","Mo","Tu","We","Th","Fr","Sa"].map(function(e){return i("div",{className:"ihub-datetime-weekday",children:e},e)})}),i("div",{className:"ihub-datetime-days",children:Kt.map(function(e,t){if(!e)return i("div",{className:"ihub-datetime-day-empty"},"empty-".concat(t));var a=!!Ce&&N(e,Ce),n=N(e,new Date),r=Ft(e)||!Ot(e);return i("button",{type:"button",className:"ihub-datetime-day ".concat(a?"selected":""," ").concat(n?"today":""," ").concat(r?"disabled":""),onClick:function(){return qt(e)},disabled:r,"aria-label":C(e,"MMMM d, yyyy"),"aria-selected":!!a||void 0,children:e.getDate()},e.getTime())})})]}),("time"===Re||"time"===_e)&&("time"===_e||"datetime"===_e)&&n("div",{className:"ihub-datetime-time",children:[n("div",{className:"ihub-datetime-time-inputs",children:[n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Hours"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:Q?(parseInt(st)%12||12).toString().padStart(2,"0"):st,onChange:function(e){var t=e.target.value.replace(/\D/g,"");(Q&&parseInt(t)<=12||!Q&&parseInt(t)<24)&&ct(t)},maxLength:2,placeholder:"HH"})]}),i("span",{className:"ihub-datetime-time-separator",children:":"}),n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Minutes"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:pt,onChange:function(e){var t=e.target.value.replace(/\D/g,"");parseInt(t)<60&&ft(t)},maxLength:2,placeholder:"MM"})]}),G&&n(r,{children:[i("span",{className:"ihub-datetime-time-separator",children:":"}),n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Seconds"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:vt,onChange:function(e){var t=e.target.value.replace(/\D/g,"");parseInt(t)<60&&gt(t)},maxLength:2,placeholder:"SS"})]})]}),Q&&n("div",{className:"ihub-datetime-ampm",children:[i("button",{type:"button",className:"ihub-datetime-ampm-btn ".concat("AM"===Ht?"active":""),onClick:function(){return _t("AM")},children:"AM"}),i("button",{type:"button",className:"ihub-datetime-ampm-btn ".concat("PM"===Ht?"active":""),onClick:function(){return _t("PM")},children:"PM"})]})]}),n("div",{className:"ihub-datetime-time-list",children:[i("div",{className:"ihub-datetime-time-list-header",children:"Quick select:"}),i("div",{className:"ihub-datetime-time-options",children:Bt.map(function(e,t){var a=Ce&&Ce.getHours()===e.hours&&Ce.getMinutes()===e.minutes;return i("button",{type:"button",className:"ihub-datetime-time-option ".concat(a?"selected":""),onClick:function(){ct(e.hours.toString().padStart(2,"0")),ft(e.minutes.toString().padStart(2,"0")),Q&&_t(e.hours>=12?"PM":"AM")},children:e.display},t)})})]}),i("div",{className:"ihub-datetime-time-actions",children:i("button",{type:"button",className:"ihub-datetime-apply-btn",onClick:function(){var e=Ce;if(!e){if("time"!==_e){var t=new Date;return void qt(t)}e=new Date}var a=parseInt(st),n=parseInt(pt),i=G?parseInt(vt):0;if(Q&&("PM"===Ht&&12!==a?a+=12:"AM"===Ht&&12===a&&(a=0)),!Wt(a,n)&&Et(a,n)){var r=_(e,a);r=S(r,n),r=w(r,i),Ie(r),null==P||P(Pt(r)),Ke(!1),Ue(null)}else Ue("Selected time is not available")},children:"Apply Time"})})]}),pe&&n("div",{className:"ihub-datetime-actions",children:[i("button",{type:"button",className:"ihub-datetime-action-btn",onClick:Rt,children:"Now"}),i("button",{type:"button",className:"ihub-datetime-action-btn",onClick:Qt,children:"Clear"})]})]}),document.body)]}),pe&&!le&&!qe&&n("div",{className:"ihub-datetime-quick-links",children:[i("button",{type:"button",className:"ihub-datetime-link",onClick:Rt,children:"Now"}),i("span",{className:"ihub-datetime-separator",children:"|"}),i("button",{type:"button",className:"ihub-datetime-link",onClick:Qt,children:"Clear"})]}),re&&i("input",{type:"hidden",name:re,value:Ce?Pt(Ce):""})]})};export{I as default};
1
+ import{slicedToArray as e,objectSpread2 as t,defineProperty as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as n,jsx as i,Fragment as r}from"react/jsx-runtime";import o from"@mui/icons-material/CalendarMonthOutlined";import d from"@mui/icons-material/AccessTime";import{useState as l,useRef as u,useEffect as c,useCallback as s,useMemo as m}from"react";import{createPortal as p}from"react-dom";import{startOfDay as h}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfDay.js";import{isBefore as f}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isBefore.js";import{isAfter as y}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isAfter.js";import{endOfDay as b}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfDay.js";import{startOfMonth as v}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfMonth.js";import{getDay as g}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDay.js";import{getDaysInMonth as M}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDaysInMonth.js";import{isSameDay as N}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isSameDay.js";import{setHours as S}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setHours.js";import{setMinutes as H}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setMinutes.js";import{setSeconds as _}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/setSeconds.js";import{isValid as w}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isValid.js";import{subMonths as D}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subMonths.js";import{addMonths as k}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js";import{parse as x}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/parse.js";import{formatDate as C}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/format.js";var I=function(I){var A=I.label,P=I.value,T=void 0===P?"":P,j=I.onChange,L=I.required,F=void 0!==L&&L,O=I.minDate,B=I.maxDate,E=I.minTime,W=I.maxTime,Y=I.disabledDates,q=void 0===Y?[]:Y,K=I.disabledTimes,z=void 0===K?[]:K,R=I.use12Hour,Q=void 0!==R&&R,V=I.includeSeconds,G=void 0!==V&&V,J=I.timeStep,U=void 0===J?30:J,X=I.dateFormat,Z=void 0===X?"yyyy-MM-dd":X,$=I.timeFormat,ee=void 0===$?Q?"hh:mm a":"HH:mm":$;I.locale;var te=I.placeholder,ae=I.errorMessage,ne=I.className,ie=void 0===ne?"":ne,re=I.name,oe=I.id,de=I.disabled,le=void 0!==de&&de,ue=I.showCalendarIcon,ce=void 0===ue||ue,se=I.showTimeIcon,me=void 0===se||se,pe=I.showQuickActions,he=void 0===pe||pe,fe=I.ariaLabel,ye=I.autoFocus,be=void 0!==ye&&ye,ve=I.onFocus,ge=I.onBlur,Me=I.useSeparateFields,Ne=void 0!==Me&&Me,Se=I.mode,He=void 0===Se?"datetime":Se,_e=I.maxWidth,we=void 0===_e?600:_e,De=function(e){if(!e)return null;try{var t=new Date(e);return w(t)?t:null}catch(e){return null}},ke=l(De(T)),xe=e(ke,2),Ce=xe[0],Ie=xe[1],Ae=l(""),Pe=e(Ae,2),Te=Pe[0],je=Pe[1],Le=l(!1),Fe=e(Le,2),Oe=Fe[0],Be=Fe[1],Ee=l(!1),We=e(Ee,2),Ye=We[0],qe=We[1],Ke=l("time"===He?"time":"calendar"),ze=e(Ke,2),Re=ze[0],Qe=ze[1],Ve=l(ae||null),Ge=e(Ve,2),Je=Ge[0],Ue=Ge[1],Xe=l(0),Ze=e(Xe,2);Ze[0];var $e=Ze[1],et=l({year:"",month:"",day:"",hour:"",minute:"",second:"",ampm:"AM"}),tt=e(et,2),at=tt[0],nt=tt[1],it=l(Ce||new Date),rt=e(it,2),ot=rt[0],dt=rt[1],lt=l(Ce?C(Ce,"HH"):"00"),ut=e(lt,2),ct=ut[0],st=ut[1],mt=l(Ce?C(Ce,"mm"):"00"),pt=e(mt,2),ht=pt[0],ft=pt[1],yt=l(Ce?C(Ce,"ss"):"00"),bt=e(yt,2),vt=bt[0],gt=bt[1],Mt=l(Ce&&Ce.getHours()>=12?"PM":"AM"),Nt=e(Mt,2),St=Nt[0],Ht=Nt[1],_t=l(!1),wt=e(_t,2),Dt=wt[0],kt=wt[1],xt=l(!1),Ct=e(xt,2);Ct[0];var It=Ct[1],At=l(!1),Pt=e(At,2);Pt[0];var Tt=Pt[1],jt=u(null),Lt=u(null),Ft=u(null),Ot=u(null),Bt=u({}),Et=l({}),Wt=e(Et,2),Yt=Wt[0],qt=Wt[1];c(function(){Ce&&(st(C(Ce,"HH")),ft(C(Ce,"mm")),gt(C(Ce,"ss")),Ht(Ce.getHours()>=12?"PM":"AM"))},[Ce]);var Kt=s(function(){var e=Ne?Ft.current:Ot.current;if(e)if(window.innerWidth<=768)qt({position:"fixed",top:"50%",left:"50%",right:"auto",transform:"translate(-50%, -50%)",width:Math.min(.95*window.innerWidth,400),maxWidth:we,maxHeight:"90vh",marginTop:0,zIndex:9999});else{var a=e.getBoundingClientRect(),n=window.innerHeight,i=n-a.bottom<450&&a.top>450,r=Math.min(Math.max(a.width,320),we);qt(t(t({position:"fixed",left:a.left,right:"auto",width:r,maxWidth:we,marginTop:0},i?{bottom:n-a.top+4,top:"auto"}:{top:a.bottom+4,bottom:"auto"}),{},{zIndex:9999}))}},[Ne,we]);c(function(){if(Ye)return Kt(),window.addEventListener("scroll",Kt,!0),window.addEventListener("resize",Kt),function(){window.removeEventListener("scroll",Kt,!0),window.removeEventListener("resize",Kt)}},[Ye,Kt]);var zt=s(function(e){if(!e)return"";switch(He){case"date":return C(h(e),"yyyy-MM-dd");case"time":return C(e,G?"HH:mm:ss":"HH:mm");default:return e.toISOString()}},[He,G]),Rt=s(function(e){var t=e||Ce;if(!t)return"";try{if("date"===He)return C(t,Z);if("time"===He)return C(t,G?ee:ee.replace(":ss",""));var a=C(t,Z),n=C(t,G?ee:ee.replace(":ss",""));return"".concat(a," ").concat(n)}catch(e){return""}},[Ce,He,Z,ee,G]);c(function(){if(void 0!==T){var e=De(T);Ie(e),Oe||je(e?Rt(e):"")}},[T,Oe,Rt]),c(function(){if(Ye){var e=function(e){var t,a,n,i=e.target;null!==(t=jt.current)&&void 0!==t&&t.contains(i)||Ne&&null!==(a=Ft.current)&&void 0!==a&&a.contains(i)||!Ne&&null!==(n=Ot.current)&&void 0!==n&&n.contains(i)||qe(!1)},t=setTimeout(function(){document.addEventListener("mousedown",e)},0);return function(){clearTimeout(t),document.removeEventListener("mousedown",e)}}},[Ye,Ne]);var Qt=s(function(e){var t=C(e,"yyyy-MM-dd");return q.includes(t)},[q]),Vt=s(function(e){return(!O||!f(e,h(new Date(O))))&&(!B||!y(e,b(new Date(B))))},[O,B]),Gt=s(function(t,a){if(!E&&!W)return!0;var n=60*t+a;if(E){var i=E.split(":").map(Number),r=e(i,2);if(n<60*r[0]+r[1])return!1}if(W){var o=W.split(":").map(Number),d=e(o,2);if(n>60*d[0]+d[1])return!1}return!0},[E,W]),Jt=s(function(e,t){var a="".concat(e.toString().padStart(2,"0"),":").concat(t.toString().padStart(2,"0"));return z.includes(a)},[z]),Ut=s(function(){if(Ue(null),F&&!Ce)return Ue("Date and time are required"),!1;if(!Ce)return!0;if(!Vt(Ce))return Ue("Selected date is outside allowed range"),!1;if(Qt(Ce))return Ue("Selected date is not available"),!1;var e=Ce.getHours(),t=Ce.getMinutes();return Gt(e,t)?!Jt(e,t)||(Ue("Selected time is not available"),!1):(Ue("Selected time is outside allowed range"),!1)},[Ce,F,Vt,Qt,Gt,Jt]),Xt=function(e){if(!Qt(e)&&Vt(e)){var t=e;if("date"===He)t=h(e),Ie(t),dt(t),null==j||j(zt(t)),qe(!1),Ue(null);else{if(Ce)t=S(e,Ce.getHours()),t=H(t,Ce.getMinutes()),t=_(t,Ce.getSeconds());else{var a=new Date;t=S(e,a.getHours()),t=H(t,a.getMinutes()),t=_(t,0)}Ie(t),dt(t),null==j||j(zt(t)),"datetime"===He&&Qe("time")}}},Zt=m(function(){for(var e=ot.getFullYear(),t=ot.getMonth(),a=v(ot),n=g(a),i=M(ot),r=[],o=0;o<n;o++)r.push(null);for(var d=1;d<=i;d++)r.push(new Date(e,t,d));return r},[ot]),$t=m(function(){for(var e=[],t=0;t<24;t++)for(var a=0;a<60;a+=U)if(!Jt(t,a)&&Gt(t,a)){var n=t,i="";Q&&(i=t<12?" AM":" PM",n=0===t?12:t>12?t-12:t);var r="".concat(n.toString().padStart(2,"0"),":").concat(a.toString().padStart(2,"0")).concat(i);e.push({hours:t,minutes:a,display:r})}return e},[U,Q,Jt,Gt]),ea=function(e){if(!e.trim())return null;for(var t=0,a=["".concat(Z," ").concat(ee),"".concat(Z," ").concat(ee.replace(":ss","")),"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd HH:mm","yyyy-MM-dd'T'HH:mm:ss","yyyy-MM-dd'T'HH:mm","MM/dd/yyyy HH:mm","MM/dd/yyyy hh:mm a","MM-dd-yyyy HH:mm","MM-dd-yyyy hh:mm a","dd/MM/yyyy HH:mm","dd/MM/yyyy hh:mm a","dd-MM-yyyy HH:mm","dd-MM-yyyy hh:mm a","yyyy-MM-dd","MM/dd/yyyy","dd/MM/yyyy","MM-dd-yyyy","dd-MM-yyyy"];t<a.length;t++){var n=a[t];try{var i=x(e,n,new Date);if(w(i))return i}catch(e){}}try{var r=new Date(e);if(w(r))return r}catch(e){}return null},ta=function(){var e=new Date,t="date"===He?h(e):e;Ie(t),dt(t),null==j||j(zt(t)),Ue(null)},aa=function(){Ie(null),st("00"),ft("00"),gt("00"),Ht("AM"),null==j||j(""),Ue(null)},na=function(e,n){var i=t(t({},at),{},a({},e,n));nt(i);var r=i.year,o=i.month,d=i.day,l=i.hour,u=i.minute,c=i.second,s=i.ampm;if(r&&o&&d&&l&&u)try{var m=parseInt(l);Q&&("PM"===s&&12!==m&&(m+=12),"AM"===s&&12===m&&(m=0));var p=new Date(parseInt(r),parseInt(o)-1,parseInt(d),m,parseInt(u),G?parseInt(c||"0"):0);if(w(p)){var f="date"===He?h(p):p;Ie(f),null==j||j(zt(f)),Ue(null)}}catch(e){}},ia=function(e,t,a,n){if(e.target.value.length>=a&&n&&/\d/.test(e.key)){e.preventDefault();var i=Bt.current[n];i&&(i.focus(),i.select())}};return c(function(){Ce&&Ne&&nt({year:Ce.getFullYear().toString(),month:(Ce.getMonth()+1).toString().padStart(2,"0"),day:Ce.getDate().toString().padStart(2,"0"),hour:Q?(Ce.getHours()%12||12).toString().padStart(2,"0"):Ce.getHours().toString().padStart(2,"0"),minute:Ce.getMinutes().toString().padStart(2,"0"),second:Ce.getSeconds().toString().padStart(2,"0"),ampm:Ce.getHours()>=12?"PM":"AM"})},[Ce,Ne,Q]),n("div",{className:"ihub-datetime-picker-wrapper ".concat(ie),style:{maxWidth:we},children:[n("div",{className:"ihub-datetime-picker ".concat(Je?"ihub-error":""),children:[n("label",{className:"ihub-datetime-label",htmlFor:oe||re,children:[A,F&&i("span",{className:"ihub-required",children:"*"})]}),n("div",Ne?{ref:Ft,className:"ihub-datetime-separate-fields",children:[("date"===He||"datetime"===He)&&n("div",{className:"ihub-datetime-date-fields",children:[i("input",{ref:function(e){Bt.current.year=e},type:"text",className:"ihub-datetime-field ihub-datetime-year",value:at.year,onChange:function(e){return na("year",e.target.value.replace(/\D/g,"").slice(0,4))},onKeyDown:function(e){return ia(e,0,4,"month")},placeholder:"YYYY",maxLength:4,disabled:le,id:"".concat(oe,"-year"),"aria-label":"Year"}),i("span",{className:"ihub-datetime-separator",children:"/"}),i("input",{ref:function(e){Bt.current.month=e},type:"text",className:"ihub-datetime-field ihub-datetime-month",value:at.month,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<=12||""===t)&&na("month",t)},onKeyDown:function(e){return ia(e,0,2,"day")},placeholder:"MM",maxLength:2,disabled:le,id:"".concat(oe,"-month"),"aria-label":"Month"}),i("span",{className:"ihub-datetime-separator",children:"/"}),i("input",{ref:function(e){Bt.current.day=e},type:"text",className:"ihub-datetime-field ihub-datetime-day",value:at.day,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<=31||""===t)&&na("day",t)},onKeyDown:function(e){return ia(e,0,2,"hour")},placeholder:"DD",maxLength:2,disabled:le,id:"".concat(oe,"-day"),"aria-label":"Day"})]}),("time"===He||"datetime"===He)&&n("div",{className:"ihub-datetime-time-fields",children:[i("input",{ref:function(e){Bt.current.hour=e},type:"text",className:"ihub-datetime-field ihub-datetime-hour",value:at.hour,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2),a=Q?12:23;(parseInt(t)<=a||""===t)&&na("hour",t)},onKeyDown:function(e){return ia(e,0,2,"minute")},placeholder:"HH",maxLength:2,disabled:le,id:"".concat(oe,"-hour"),"aria-label":"Hour"}),i("span",{className:"ihub-datetime-separator",children:":"}),i("input",{ref:function(e){Bt.current.minute=e},type:"text",className:"ihub-datetime-field ihub-datetime-minute",value:at.minute,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<60||""===t)&&na("minute",t)},onKeyDown:function(e){return ia(e,0,2,G?"second":void 0)},placeholder:"MM",maxLength:2,disabled:le,id:"".concat(oe,"-minute"),"aria-label":"Minute"}),G&&n(r,{children:[i("span",{className:"ihub-datetime-separator",children:":"}),i("input",{ref:function(e){Bt.current.second=e},type:"text",className:"ihub-datetime-field ihub-datetime-second",value:at.second,onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(parseInt(t)<60||""===t)&&na("second",t)},placeholder:"SS",maxLength:2,disabled:le,id:"".concat(oe,"-second"),"aria-label":"Second"})]}),Q&&i("button",{type:"button",className:"ihub-datetime-field ihub-datetime-ampm-toggle",onClick:function(){return na("ampm","AM"===at.ampm?"PM":"AM")},disabled:le,"aria-label":"Toggle AM/PM, currently ".concat(at.ampm),children:at.ampm})]}),n("div",{className:"ihub-datetime-icons",children:[ce&&("date"===He||"datetime"===He)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(qe(!0),Qe("calendar"))},disabled:le,"aria-label":"Open calendar",children:i(o,{})}),me&&("time"===He||"datetime"===He)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(qe(!0),Qe("time"))},disabled:le,"aria-label":"Open time picker",children:i(d,{})})]})]}:{ref:Ot,className:"ihub-datetime-input-container",children:[i("input",{ref:Lt,type:"text",className:"ihub-datetime-input",value:Oe?Te:Rt(),onChange:function(e){var t=e.target,a=t.value;t.selectionStart;var n=function(e){var t=G?"".concat(Z," ").concat(ee):"".concat(Z," ").concat(ee.replace(":ss","")),a=e.replace(/\D/g,""),n={"yyyy-MM-dd HH:mm:ss":[4,2,2,2,2,2],"yyyy-MM-dd HH:mm":[4,2,2,2,2],"MM/dd/yyyy HH:mm":[2,2,4,2,2],"MM/dd/yyyy hh:mm a":[2,2,4,2,2],"dd/MM/yyyy HH:mm":[2,2,4,2,2],"dd/MM/yyyy hh:mm a":[2,2,4,2,2]}[t];n||(n=[4,2,2,2,2]);for(var i=t.replace(/[yMdHhms]/g,"").split("").filter(function(e){return e.trim()}),r="",o=0,d=0,l=0;l<n.length;l++){var u=n[l],c=a.slice(o,o+u);c&&(r+=c,o+=u,l<n.length-1&&o<a.length&&d<i.length&&(r+=i[d]),d++)}return{formatted:r,cursorPos:r.length}}(a),i=n.formatted,r=n.cursorPos;if(je(i),$e(r),setTimeout(function(){t&&t.setSelectionRange&&t.setSelectionRange(r,r)},0),!i.trim())return Ie(null),null==j||j(""),void Ue(null);var o=ea(i);if(o){var d="date"===He?h(o):o;Ie(d),null==j||j(zt(d)),Ue(null)}},onFocus:function(e){Be(!0),Ce&&!Te&&je(Rt()),null==ve||ve(e)},onBlur:function(e){if(Be(!1),Te.trim()){var t=ea(Te);if(t){var a="date"===He?h(t):t;Ie(a),null==j||j(zt(a)),je(Rt(a)),Ue(null)}else Ue("Invalid date/time format")}else Ue(F?"Date and time are required":null);Ut(),null==ge||ge(e)},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),qe(!Ye)),"Escape"===e.key&&qe(!1),"Tab"===e.key&&Ye&&e.stopPropagation()},placeholder:Oe?function(e){for(var t=("date"===He?Z:"time"===He?G?ee:ee.replace(":ss",""):G?"".concat(Z," ").concat(ee):"".concat(Z," ").concat(ee.replace(":ss",""))).replace(/yyyy/g,"____").replace(/yy/g,"__").replace(/MM/g,"__").replace(/dd/g,"__").replace(/HH/g,"__").replace(/hh/g,"__").replace(/mm/g,"__").replace(/ss/g,"__").replace(/a/g,"__"),a="",n=0,i=0;i<t.length&&n<e.length;i++){var r=t[i],o=e[n];"_"===r?o&&/[^\d]/.test(o)&&i+1<t.length&&/[^_]/.test(t[i+1])?(a+=t[i+1],n++,i++):o&&/\d/.test(o)?(a+=o,n++):a+="_":(a+=r,o===r&&n++)}return a.length<t.length&&(a+=t.slice(a.length)),a}(Te):"date"===He?te||Z:"time"===He?te||ee:te||"".concat(Z," ").concat(ee),disabled:le,required:F,name:re,id:oe,"aria-label":fe||A,"aria-invalid":!!Je,"aria-describedby":Je?"".concat(oe,"-error"):void 0,autoFocus:be}),n("div",{className:"ihub-datetime-icons",children:[ce&&("date"===He||"datetime"===He)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(qe(!0),Qe("calendar"))},disabled:le,"aria-label":"Open calendar",children:i(o,{})}),me&&("time"===He||"datetime"===He)&&i("button",{type:"button",className:"ihub-datetime-icon-btn",onClick:function(){le||(qe(!0),Qe("time"))},disabled:le,"aria-label":"Open time picker",children:i(d,{})})]})]}),Je&&i("div",{id:"".concat(oe,"-error"),className:"ihub-datetime-error",children:Je}),Ye&&!le&&"undefined"!=typeof document&&p(n("div",{ref:jt,className:"ihub-datetime-picker-dropdown",style:Yt,role:"dialog","aria-label":"Date and time picker",onMouseDown:function(e){return e.stopPropagation()},children:["datetime"===He&&n("div",{className:"ihub-datetime-tabs",children:[i("button",{className:"ihub-datetime-tab ".concat("calendar"===Re?"active":""),onClick:function(){return Qe("calendar")},type:"button",children:"Date"}),i("button",{className:"ihub-datetime-tab ".concat("time"===Re?"active":""),onClick:function(){return Qe("time")},type:"button",children:"Time"})]}),("calendar"===Re||"date"===He)&&("date"===He||"datetime"===He)&&n("div",{className:"ihub-datetime-calendar",children:[n("div",{className:"ihub-datetime-month-nav",children:[i("button",{type:"button",onClick:function(){dt(D(ot,1))},className:"ihub-datetime-nav-btn","aria-label":"Previous month",children:"‹"}),i("span",{className:"ihub-datetime-month-year",children:C(ot,"MMMM yyyy")}),i("button",{type:"button",onClick:function(){dt(k(ot,1))},className:"ihub-datetime-nav-btn","aria-label":"Next month",children:"›"})]}),i("div",{className:"ihub-datetime-weekdays",children:["Su","Mo","Tu","We","Th","Fr","Sa"].map(function(e){return i("div",{className:"ihub-datetime-weekday",children:e},e)})}),i("div",{className:"ihub-datetime-days",children:Zt.map(function(e,t){if(!e)return i("div",{className:"ihub-datetime-day-empty"},"empty-".concat(t));var a=!!Ce&&N(e,Ce),n=N(e,new Date),r=Qt(e)||!Vt(e);return i("button",{type:"button",className:"ihub-datetime-day ".concat(a?"selected":""," ").concat(n?"today":""," ").concat(r?"disabled":""),onClick:function(){return Xt(e)},disabled:r,"aria-label":C(e,"MMMM d, yyyy"),"aria-selected":!!a||void 0,children:e.getDate()},e.getTime())})})]}),("time"===Re||"time"===He)&&("time"===He||"datetime"===He)&&n("div",{className:"ihub-datetime-time",children:[n("div",{className:"ihub-datetime-time-inputs",children:[n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Hours"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:Dt?ct:Q?(parseInt(ct)%12||12).toString().padStart(2,"0"):ct,onFocus:function(){if(kt(!0),Q){var e=(parseInt(ct)%12||12).toString().padStart(2,"0");st(e)}},onBlur:function(){if(kt(!1),""===ct)st("00");else if(Q){var e=parseInt(ct)||0;e>12&&(e=12),e<1&&(e=12),st(("PM"===St?12===e?12:e+12:12===e?0:e).toString().padStart(2,"0"))}else st(ct.padStart(2,"0"))},onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2),a=Q?12:23;(""===t||parseInt(t)<=a)&&st(t)},maxLength:2,placeholder:"HH"})]}),i("span",{className:"ihub-datetime-time-separator",children:":"}),n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Minutes"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:ht,onFocus:function(){return It(!0)},onBlur:function(){It(!1),ft(""===ht?"00":ht.padStart(2,"0"))},onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(""===t||parseInt(t)<60)&&ft(t)},maxLength:2,placeholder:"MM"})]}),G&&n(r,{children:[i("span",{className:"ihub-datetime-time-separator",children:":"}),n("div",{className:"ihub-datetime-time-group",children:[i("label",{children:"Seconds"}),i("input",{type:"text",className:"ihub-datetime-time-input",value:vt,onFocus:function(){return Tt(!0)},onBlur:function(){Tt(!1),gt(""===vt?"00":vt.padStart(2,"0"))},onChange:function(e){var t=e.target.value.replace(/\D/g,"").slice(0,2);(""===t||parseInt(t)<60)&&gt(t)},maxLength:2,placeholder:"SS"})]})]}),Q&&n("div",{className:"ihub-datetime-ampm",children:[i("button",{type:"button",className:"ihub-datetime-ampm-btn ".concat("AM"===St?"active":""),onClick:function(){return Ht("AM")},children:"AM"}),i("button",{type:"button",className:"ihub-datetime-ampm-btn ".concat("PM"===St?"active":""),onClick:function(){return Ht("PM")},children:"PM"})]})]}),n("div",{className:"ihub-datetime-time-list",children:[i("div",{className:"ihub-datetime-time-list-header",children:"Quick select:"}),i("div",{className:"ihub-datetime-time-options",children:$t.map(function(e,t){var a=Ce&&Ce.getHours()===e.hours&&Ce.getMinutes()===e.minutes;return i("button",{type:"button",className:"ihub-datetime-time-option ".concat(a?"selected":""),onClick:function(){var t=e.hours,a=e.minutes;st(t.toString().padStart(2,"0")),ft(a.toString().padStart(2,"0")),Q&&Ht(t>=12?"PM":"AM");var n=Ce||new Date,i=S(n,t);i=H(i,a),i=_(i,0),Ie(i),null==j||j(zt(i)),qe(!1),Ue(null)},children:e.display},t)})})]}),i("div",{className:"ihub-datetime-time-actions",children:i("button",{type:"button",className:"ihub-datetime-apply-btn",onClick:function(){var e=Ce;if(!e){if("time"!==He){var t=new Date;return void Xt(t)}e=new Date}var a=parseInt(ct),n=parseInt(ht),i=G?parseInt(vt):0;if(Q&&("PM"===St&&12!==a?a+=12:"AM"===St&&12===a&&(a=0)),!Jt(a,n)&&Gt(a,n)){var r=S(e,a);r=H(r,n),r=_(r,i),Ie(r),null==j||j(zt(r)),qe(!1),Ue(null)}else Ue("Selected time is not available")},children:"Apply Time"})})]}),he&&n("div",{className:"ihub-datetime-actions",children:[i("button",{type:"button",className:"ihub-datetime-action-btn",onClick:ta,children:"Now"}),i("button",{type:"button",className:"ihub-datetime-action-btn",onClick:aa,children:"Clear"})]})]}),document.body)]}),he&&!le&&!Ye&&n("div",{className:"ihub-datetime-quick-links",children:[i("button",{type:"button",className:"ihub-datetime-link",onClick:ta,children:"Now"}),i("span",{className:"ihub-datetime-separator",children:"|"}),i("button",{type:"button",className:"ihub-datetime-link",onClick:aa,children:"Clear"})]}),re&&i("input",{type:"hidden",name:re,value:Ce?zt(Ce):""})]})};export{I as default};
2
2
  //# sourceMappingURL=DateTimePicker.js.map
@@ -5,17 +5,28 @@ interface IsUsernameEmailTakenProps {
5
5
  required?: boolean;
6
6
  key?: string | number;
7
7
  setIsValid?: (isValid: boolean) => void;
8
+ /** Custom API URL for availability checking. Defaults to `${API_HOST_URL}auth/username_email_available/` */
9
+ apiUrl?: string;
10
+ /**
11
+ * Raw display name used to auto-generate a username and suggestions.
12
+ * When provided, the component slugifies the name into the input field
13
+ * automatically. If that slug is taken, clickable alternatives appear.
14
+ */
15
+ rawName?: string;
8
16
  }
9
17
  /**
10
- * @param props
11
- * @returns
18
+ * Real-time username/email availability checker with auto-generation
19
+ * from a raw name and clickable suggestions when taken.
20
+ *
12
21
  * @example
13
22
  * <IsUsernameEmailTaken
14
- * name="username"
15
- * type="text"
16
- * label="Username *"
17
- * required={true}
18
- * setIsValid={setEmailIsValid} // optional
23
+ * name="channel"
24
+ * type="text"
25
+ * label="Channel Handle"
26
+ * required
27
+ * rawName={companyName}
28
+ * apiUrl={`${API_HOST_URL}companies/username_available/`}
29
+ * setIsValid={setIsValid}
19
30
  * />
20
31
  */
21
32
  export default function IsUsernameEmailTaken(props: IsUsernameEmailTakenProps): import("react/jsx-runtime").JSX.Element;