From ff1ac726253f59984690676c7d4e486d32fd4506 Mon Sep 17 00:00:00 2001 From: Konstantin Fandelyuk Date: Wed, 11 Dec 2024 01:00:35 +0200 Subject: [PATCH] updated AUTH Recaptcha Init fix --- .../__dropins__/storefront-auth/chunks/Button2.js | 2 +- .../storefront-auth/chunks/ResetPasswordForm.js | 2 +- .../configs/excludedFocusClasses.d.ts | 15 +++++++++++++++ .../storefront-auth/hooks/components/useForm.d.ts | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 scripts/__dropins__/storefront-auth/configs/excludedFocusClasses.d.ts diff --git a/scripts/__dropins__/storefront-auth/chunks/Button2.js b/scripts/__dropins__/storefront-auth/chunks/Button2.js index c461db4f2..677294cfb 100644 --- a/scripts/__dropins__/storefront-auth/chunks/Button2.js +++ b/scripts/__dropins__/storefront-auth/chunks/Button2.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as h,Fragment as Z,jsxs as U}from"@dropins/tools/preact-jsx-runtime.js";import{useState as R,useCallback as L,useRef as H,useEffect as P}from"@dropins/tools/preact-hooks.js";import*as $ from"@dropins/tools/preact-compat.js";import{memo as W,useCallback as _}from"@dropins/tools/preact-compat.js";import{initReCaptcha as G}from"@dropins/tools/recaptcha.js";import{useText as j}from"@dropins/tools/i18n.js";import{classes as M}from"@dropins/tools/lib.js";import{Field as w,Picker as q,Input as X,InputDate as C,Checkbox as z,TextArea as B,Button as J}from"@dropins/tools/components.js";/* empty css */const De=e=>{if(!e)return null;const t=new FormData(e);if(t&&typeof t.entries=="function"){const n=t.entries();if(n&&typeof n[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(n)))||{}}return{}},xe=e=>typeof e=="function",Y=e=>$.createElement("svg",{id:"Icon_Warning_Base",width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},$.createElement("g",{clipPath:"url(#clip0_841_1324)"},$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.9949 2.30237L0.802734 21.6977H23.1977L11.9949 2.30237Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M12.4336 10.5504L12.3373 14.4766H11.6632L11.5669 10.5504V9.51273H12.4336V10.5504ZM11.5883 18.2636V17.2687H12.4229V18.2636H11.5883Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),$.createElement("defs",null,$.createElement("clipPath",{id:"clip0_841_1324"},$.createElement("rect",{width:24,height:21,fill:"white",transform:"translate(0 1.5)"})))),K=e=>$.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),Q=e=>$.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),$.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),g={success:h(K,{}),warning:h(Y,{}),error:h(Q,{})},be=()=>{const[e,t]=R({}),n=L(l=>{if(!l||!l.type){t({});return}const c=g[l.type];t({...l,icon:c})},[]);return{inLineAlertProps:e,handleSetInLineAlertProps:n}};var v=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(v||{});const ee=W(({loading:e,values:t,fields:n=[],errors:l,className:c="",onChange:u,onBlur:p,onFocus:A})=>{const s=`${c}__field`,f=_((r,o,a)=>{var T;const E=(T=r.options.find(N=>N.isDefault))==null?void 0:T.value;return h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:h(q,{name:r.customUpperCode,floatingLabel:`${r.label} ${r.required?"*":""}`,placeholder:r.label,"aria-label":r.label,options:r.options,onBlur:p,handleSelect:u,defaultValue:E??o??r.defaultValue,value:E??o??r.defaultValue})},r.id)},[c,e,s,p,u]),D=_((r,o,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(X,{type:"text",name:r.customUpperCode,value:o??r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,onFocus:A})},r.id),[c,e,s,p,u,A]),x=_((r,o,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:h(C,{type:"text",name:r.customUpperCode,value:o||r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,disabled:e||r.disabled})},r.id),[c,e,s,p,u]),m=_((r,o,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(z,{name:r.customUpperCode,checked:o||r.defaultValue,placeholder:r.label,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]),b=_((r,o,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(B,{type:"text",name:r.customUpperCode,value:o??r.defaultValue,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]);return n.length?h(Z,{children:n.map(r=>{const o=l==null?void 0:l[r.customUpperCode],a=t==null?void 0:t[r.customUpperCode];switch(r.fieldType){case v.TEXT:return r.options.length?f(r,a,o):D(r,a,o);case v.MULTILINE:return D(r,a,o);case v.SELECT:return f(r,a,o);case v.DATE:return x(r,a,o);case v.BOOLEAN:return m(r,a,o);case v.TEXTAREA:return b(r,a,o);default:return null}})}):null}),re=e=>e.reduce((t,{customUpperCode:n,required:l,defaultValue:c})=>(l&&n&&(t.initialData[n]=c||"",t.errorList[n]=""),t),{initialData:{},errorList:{}}),te=e=>e.reduce((t,n)=>({...t,[n.name]:n.value}),{}),ae=e=>/^\d+$/.test(e),ne=e=>/^[a-zA-Z0-9\s]+$/.test(e),oe=e=>/^[a-zA-Z0-9]+$/.test(e),le=e=>/^[a-zA-Z]+$/.test(e),se=e=>/^[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+(\.[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i.test(e),ce=e=>/^\d{4}-\d{2}-\d{2}$/.test(e)&&!isNaN(Date.parse(e)),de=(e,t,n)=>{const l=new Date(e).getTime()/1e3;return!(isNaN(l)||l<0||typeof t<"u"&&ln)},k=e=>{if(!e||e.trim()==="")return"";const t=parseInt(e,10);if(!isNaN(t)){const c=new Date(t*1e3);return isNaN(c.getTime())?"":c.toISOString().split("T")[0]}const n=new Date(e);if(isNaN(n.getTime()))return"";const l=parseInt(e.split("-")[1],10);return l>12||l<1?"":n.toISOString().split("T")[0]},ue=e=>/^(https?|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i.test(e),ie=(e,t,n)=>{const l=e.length;return l>=t&&l<=n},O=(e,t,n,l)=>{var y,F;const{requiredFieldError:c,lengthTextError:u,numericError:p,alphaNumWithSpacesError:A,alphaNumericError:s,alphaError:f,emailError:D,dateError:x,urlError:m,dateLengthError:b,dateMaxError:r,dateMinError:o}=n,a=t==null?void 0:t.customUpperCode,E={[a]:""};if(l[a]&&delete l[a],t!=null&&t.required&&!e)return{[a]:c};if(!(t!=null&&t.required)&&!e||!((y=t==null?void 0:t.validateRules)!=null&&y.length))return E;const T=te(t==null?void 0:t.validateRules),N=T.MIN_TEXT_LENGTH??1,I=T.MAX_TEXT_LENGTH??255,d=T.DATE_RANGE_MIN,i=T.DATE_RANGE_MAX;if(!ie(e,+N,+I)&&!(d||i))return{[a]:u.replace("{min}",N).replace("{max}",I)};if(!de(e,+d,+i)&&(d||i)){if(d&&d)return{[a]:b.replace("{min}",k(d)).replace("{max}",k(i))};if(typeof d>"u"||typeof i>"u")return{[a]:i?r.replace("{max}",k(i)):o.replace("{min}",k(d))}}const V={numeric:{validate:ae,error:p},"alphanum-with-spaces":{validate:ne,error:A},alphanumeric:{validate:oe,error:s},alpha:{validate:le,error:f},email:{validate:se,error:D},date:{validate:ce,error:x},url:{validate:ue,error:m}}[T.INPUT_VALIDATION];return V&&!V.validate(e)&&!((F=l[a])!=null&&F.length)?{[a]:V.error}:E},pe=({fieldsConfig:e,onSubmit:t})=>{const n=j({requiredFieldError:"Auth.FormText.requiredFieldError",lengthTextError:"Auth.FormText.lengthTextError",numericError:"Auth.FormText.numericError",alphaNumWithSpacesError:"Account.FormText.alphaNumWithSpacesError",alphaNumericError:"Auth.FormText.alphaNumericError",alphaError:"Auth.FormText.alphaError",emailError:"Auth.FormText.emailError",dateError:"Auth.FormText.dateError",dateLengthError:"Auth.FormText.dateLengthError",dateMaxError:"Auth.FormText.dateMaxError",dateMinError:"Auth.FormText.dateMinError",urlError:"Auth.FormText.urlError"}),l=H(null),c=H(!1),[u,p]=R({}),[A,s]=R({}),f=L(()=>{let r=!0;const o={...A};let a=null;for(const[E,T]of Object.entries(u)){const N=e==null?void 0:e.find(d=>{var i;return(i=d==null?void 0:d.customUpperCode)==null?void 0:i.includes(E)}),I=O(T.toString(),N,n,o);I[E]&&(Object.assign(o,I),r=!1),a||(a=Object.keys(o).find(d=>o[d])??null)}if(s(o),a&&l.current){const E=l.current.elements.namedItem(a);E==null||E.focus()}return r},[A,e,u,n]);P(()=>{if(e!=null&&e.length){const{initialData:r,errorList:o}=re(e);p(a=>({...r,...a})),s(o)}},[JSON.stringify(e)]);const D=L(async r=>{console.log("event",r),c.current||(await G(0),c.current=!0)},[]),x=L(r=>{const{name:o,value:a,type:E,checked:T}=r==null?void 0:r.target,N=E==="checkbox"?T:a;p(i=>({...i,[o]:N}));const I=e==null?void 0:e.find(i=>{var S;return(S=i==null?void 0:i.customUpperCode)==null?void 0:S.includes(o)});let d={...A};if(I){const i=O(N.toString(),I,n,d);i&&Object.assign(d,i),s(d)}},[e,A,n]),m=L(r=>{const{name:o,value:a,type:E,checked:T}=r==null?void 0:r.target,N=E==="checkbox"?T:a,I=e==null?void 0:e.find(d=>d.customUpperCode===o);if(I){const d={...A},i=O(N.toString(),I,n,d);i&&Object.assign(d,i),s(d)}},[A,e,n]),b=L(r=>{r.preventDefault();const o=f();t==null||t(r,o)},[f,t]);return{formData:u,errors:A,formRef:l,handleChange:x,handleBlur:m,handleSubmit:b,handleFocus:D}},me=({name:e,loading:t,children:n,className:l="defaultForm",fieldsConfig:c=[],onSubmit:u,...p})=>{const{formData:A,errors:s,formRef:f,handleChange:D,handleBlur:x,handleSubmit:m,handleFocus:b}=pe({onSubmit:u,fieldsConfig:c});return U("form",{className:l,onSubmit:m,name:e,ref:f,onFocus:b,...p,children:[h(ee,{className:l,onFocus:b,fields:c,onChange:D,onBlur:x,errors:s,values:A,loading:t}),n]})},ve=({type:e,buttonText:t,variant:n,className:l="",enableLoader:c=!1,onClick:u,style:p,icon:A,...s})=>{const f=L(x=>{u==null||u(x)},[u]);return U(J,{icon:A,style:p,type:e,variant:n,className:M(["auth-button",l,c?"enableLoader":""]),onClick:f,...s,children:[h("span",{className:"auth-button__text",children:t}),c?h("div",{className:"auth-button__wrapper",children:h("span",{className:"auth-button__loader"})}):null]})};export{ve as B,me as F,xe as c,De as g,be as u}; +import{jsx as h,Fragment as Z,jsxs as U}from"@dropins/tools/preact-jsx-runtime.js";import{useState as R,useCallback as L,useRef as H,useEffect as P}from"@dropins/tools/preact-hooks.js";import*as f from"@dropins/tools/preact-compat.js";import{memo as W,useCallback as _}from"@dropins/tools/preact-compat.js";import{initReCaptcha as G}from"@dropins/tools/recaptcha.js";import{useText as j}from"@dropins/tools/i18n.js";import{classes as M}from"@dropins/tools/lib.js";import{Field as w,Picker as q,Input as C,InputDate as X,Checkbox as z,TextArea as B,Button as J}from"@dropins/tools/components.js";/* empty css */const xe=e=>{if(!e)return null;const t=new FormData(e);if(t&&typeof t.entries=="function"){const o=t.entries();if(o&&typeof o[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(o)))||{}}return{}},be=e=>typeof e=="function",Y=e=>f.createElement("svg",{id:"Icon_Warning_Base",width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("g",{clipPath:"url(#clip0_841_1324)"},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.9949 2.30237L0.802734 21.6977H23.1977L11.9949 2.30237Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M12.4336 10.5504L12.3373 14.4766H11.6632L11.5669 10.5504V9.51273H12.4336V10.5504ZM11.5883 18.2636V17.2687H12.4229V18.2636H11.5883Z",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})),f.createElement("defs",null,f.createElement("clipPath",{id:"clip0_841_1324"},f.createElement("rect",{width:24,height:21,fill:"white",transform:"translate(0 1.5)"})))),K=e=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),Q=e=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),f.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),g={success:h(K,{}),warning:h(Y,{}),error:h(Q,{})},me=()=>{const[e,t]=R({}),o=L(l=>{if(!l||!l.type){t({});return}const c=g[l.type];t({...l,icon:c})},[]);return{inLineAlertProps:e,handleSetInLineAlertProps:o}};var v=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(v||{});const ee=W(({loading:e,values:t,fields:o=[],errors:l,className:c="",onChange:u,onBlur:p,onFocus:A})=>{const s=`${c}__field`,$=_((r,n,a)=>{var T;const E=(T=r.options.find(N=>N.isDefault))==null?void 0:T.value;return h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:h(q,{name:r.customUpperCode,floatingLabel:`${r.label} ${r.required?"*":""}`,placeholder:r.label,"aria-label":r.label,options:r.options,onBlur:p,handleSelect:u,defaultValue:E??n??r.defaultValue,value:E??n??r.defaultValue})},r.id)},[c,e,s,p,u]),D=_((r,n,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(C,{type:"text",name:r.customUpperCode,value:n??r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,onFocus:A})},r.id),[c,e,s,p,u,A]),x=_((r,n,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e||r.disabled,children:h(X,{type:"text",name:r.customUpperCode,value:n||r.defaultValue,placeholder:r.label,floatingLabel:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u,disabled:e||r.disabled})},r.id),[c,e,s,p,u]),m=_((r,n,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(z,{name:r.customUpperCode,checked:n||r.defaultValue,placeholder:r.label,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]),b=_((r,n,a)=>h(w,{error:a,className:M([s,`${s}--${r.id}`,[`${s}--${r.id}-hidden`,r.isHidden],r.className]),"data-testid":`${c}--${r.id}`,disabled:e,children:h(B,{type:"text",name:r.customUpperCode,value:n??r.defaultValue,label:`${r.label} ${r.required?"*":""}`,onBlur:p,onChange:u})},r.id),[c,e,s,p,u]);return o.length?h(Z,{children:o.map(r=>{const n=l==null?void 0:l[r.customUpperCode],a=t==null?void 0:t[r.customUpperCode];switch(r.fieldType){case v.TEXT:return r.options.length?$(r,a,n):D(r,a,n);case v.MULTILINE:return D(r,a,n);case v.SELECT:return $(r,a,n);case v.DATE:return x(r,a,n);case v.BOOLEAN:return m(r,a,n);case v.TEXTAREA:return b(r,a,n);default:return null}})}):null}),re=e=>e.reduce((t,{customUpperCode:o,required:l,defaultValue:c})=>(l&&o&&(t.initialData[o]=c||"",t.errorList[o]=""),t),{initialData:{},errorList:{}}),te=e=>e.reduce((t,o)=>({...t,[o.name]:o.value}),{}),ae=e=>/^\d+$/.test(e),ne=e=>/^[a-zA-Z0-9\s]+$/.test(e),oe=e=>/^[a-zA-Z0-9]+$/.test(e),le=e=>/^[a-zA-Z]+$/.test(e),se=e=>/^[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+(\.[a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]+)*@([a-z0-9-]+\.)+[a-z]{2,}$/i.test(e),ce=e=>/^\d{4}-\d{2}-\d{2}$/.test(e)&&!isNaN(Date.parse(e)),de=(e,t,o)=>{const l=new Date(e).getTime()/1e3;return!(isNaN(l)||l<0||typeof t<"u"&&lo)},S=e=>{if(!e||e.trim()==="")return"";const t=parseInt(e,10);if(!isNaN(t)){const c=new Date(t*1e3);return isNaN(c.getTime())?"":c.toISOString().split("T")[0]}const o=new Date(e);if(isNaN(o.getTime()))return"";const l=parseInt(e.split("-")[1],10);return l>12||l<1?"":o.toISOString().split("T")[0]},ue=e=>/^(https?|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i.test(e),ie=(e,t,o)=>{const l=e.length;return l>=t&&l<=o},O=(e,t,o,l)=>{var F,y;const{requiredFieldError:c,lengthTextError:u,numericError:p,alphaNumWithSpacesError:A,alphaNumericError:s,alphaError:$,emailError:D,dateError:x,urlError:m,dateLengthError:b,dateMaxError:r,dateMinError:n}=o,a=t==null?void 0:t.customUpperCode,E={[a]:""};if(l[a]&&delete l[a],t!=null&&t.required&&!e)return{[a]:c};if(!(t!=null&&t.required)&&!e||!((F=t==null?void 0:t.validateRules)!=null&&F.length))return E;const T=te(t==null?void 0:t.validateRules),N=T.MIN_TEXT_LENGTH??1,I=T.MAX_TEXT_LENGTH??255,d=T.DATE_RANGE_MIN,i=T.DATE_RANGE_MAX;if(!ie(e,+N,+I)&&!(d||i))return{[a]:u.replace("{min}",N).replace("{max}",I)};if(!de(e,+d,+i)&&(d||i)){if(d&&d)return{[a]:b.replace("{min}",S(d)).replace("{max}",S(i))};if(typeof d>"u"||typeof i>"u")return{[a]:i?r.replace("{max}",S(i)):n.replace("{min}",S(d))}}const V={numeric:{validate:ae,error:p},"alphanum-with-spaces":{validate:ne,error:A},alphanumeric:{validate:oe,error:s},alpha:{validate:le,error:$},email:{validate:se,error:D},date:{validate:ce,error:x},url:{validate:ue,error:m}}[T.INPUT_VALIDATION];return V&&!V.validate(e)&&!((y=l[a])!=null&&y.length)?{[a]:V.error}:E},pe=["auth-reset-password-form__buttons--back"],he=({fieldsConfig:e,onSubmit:t})=>{const o=j({requiredFieldError:"Auth.FormText.requiredFieldError",lengthTextError:"Auth.FormText.lengthTextError",numericError:"Auth.FormText.numericError",alphaNumWithSpacesError:"Account.FormText.alphaNumWithSpacesError",alphaNumericError:"Auth.FormText.alphaNumericError",alphaError:"Auth.FormText.alphaError",emailError:"Auth.FormText.emailError",dateError:"Auth.FormText.dateError",dateLengthError:"Auth.FormText.dateLengthError",dateMaxError:"Auth.FormText.dateMaxError",dateMinError:"Auth.FormText.dateMinError",urlError:"Auth.FormText.urlError"}),l=H(null),c=H(!1),[u,p]=R({}),[A,s]=R({}),$=L(()=>{let r=!0;const n={...A};let a=null;for(const[E,T]of Object.entries(u)){const N=e==null?void 0:e.find(d=>{var i;return(i=d==null?void 0:d.customUpperCode)==null?void 0:i.includes(E)}),I=O(T.toString(),N,o,n);I[E]&&(Object.assign(n,I),r=!1),a||(a=Object.keys(n).find(d=>n[d])??null)}if(s(n),a&&l.current){const E=l.current.elements.namedItem(a);E==null||E.focus()}return r},[A,e,u,o]);P(()=>{if(e!=null&&e.length){const{initialData:r,errorList:n}=re(e);p(a=>({...r,...a})),s(n)}},[JSON.stringify(e)]);const D=L(async r=>{const n=r.target;!c.current&&pe.includes(n.className)&&(await G(0),c.current=!0)},[]),x=L(r=>{const{name:n,value:a,type:E,checked:T}=r==null?void 0:r.target,N=E==="checkbox"?T:a;p(i=>({...i,[n]:N}));const I=e==null?void 0:e.find(i=>{var k;return(k=i==null?void 0:i.customUpperCode)==null?void 0:k.includes(n)});let d={...A};if(I){const i=O(N.toString(),I,o,d);i&&Object.assign(d,i),s(d)}},[e,A,o]),m=L(r=>{const{name:n,value:a,type:E,checked:T}=r==null?void 0:r.target,N=E==="checkbox"?T:a,I=e==null?void 0:e.find(d=>d.customUpperCode===n);if(I){const d={...A},i=O(N.toString(),I,o,d);i&&Object.assign(d,i),s(d)}},[A,e,o]),b=L(r=>{r.preventDefault();const n=$();t==null||t(r,n)},[$,t]);return{formData:u,errors:A,formRef:l,handleChange:x,handleBlur:m,handleSubmit:b,handleFocus:D}},ve=({name:e,loading:t,children:o,className:l="defaultForm",fieldsConfig:c=[],onSubmit:u,...p})=>{const{formData:A,errors:s,formRef:$,handleChange:D,handleBlur:x,handleSubmit:m,handleFocus:b}=he({onSubmit:u,fieldsConfig:c});return U("form",{className:l,onSubmit:m,name:e,ref:$,onFocus:b,...p,children:[h(ee,{className:l,onFocus:b,fields:c,onChange:D,onBlur:x,errors:s,values:A,loading:t}),o]})},Le=({type:e,buttonText:t,variant:o,className:l="",enableLoader:c=!1,onClick:u,style:p,icon:A,...s})=>{const $=L(x=>{u==null||u(x)},[u]);return U(J,{icon:A,style:p,type:e,variant:o,className:M(["auth-button",l,c?"enableLoader":""]),onClick:$,...s,children:[h("span",{className:"auth-button__text",children:t}),c?h("div",{className:"auth-button__wrapper",children:h("span",{className:"auth-button__loader"})}):null]})};export{Le as B,ve as F,be as c,xe as g,me as u}; diff --git a/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js b/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js index feb6c0e4d..eafe1d4df 100644 --- a/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js +++ b/scripts/__dropins__/storefront-auth/chunks/ResetPasswordForm.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsxs as l,jsx as o}from"@dropins/tools/preact-jsx-runtime.js";import{classes as b}from"@dropins/tools/lib.js";/* empty css */import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{r as h}from"./requestPasswordResetEmail.js";import{g as F,c as w,u as P,F as _,B as p}from"./Button2.js";import{useState as x,useCallback as g}from"@dropins/tools/preact-hooks.js";import{useText as R}from"@dropins/tools/i18n.js";import{Header as v,InLineAlert as N}from"@dropins/tools/components.js";import{s as E,D as L}from"./simplifyTransformAttributesForm.js";import*as y from"@dropins/tools/preact-compat.js";const T=t=>y.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},y.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),D=({routeSignIn:t,onErrorCallback:a,setActiveComponent:m,handleSetInLineAlertProps:s})=>{const c=R({successPasswordResetEmailNotification:"Auth.Notification.successPasswordResetEmailNotification"}),[r,e]=x(!1),d=g(async u=>{u.preventDefault(),e(!0);const i=F(u.target);if(i&&i.email){const f=await h(i.email);f.success?s==null||s({type:"success",text:c.successPasswordResetEmailNotification.replace("{email}",i.email)}):(a==null||a(f),s==null||s({type:"error",text:f.message}))}e(!1)},[s,a,c.successPasswordResetEmailNotification]),n=g(()=>{if(w(m)){m("signInForm");return}w(t)&&(window.location.href=t())},[m,t]);return{isLoading:r,submitResetPassword:d,redirectToSignInPage:n}},$=({formSize:t="default",routeSignIn:a,setActiveComponent:m,onErrorCallback:s,...c})=>{const r=R({title:"Auth.ResetPasswordForm.title",buttonPrimary:"Auth.ResetPasswordForm.buttonPrimary",buttonSecondary:"Auth.ResetPasswordForm.buttonSecondary",formAriaLabel:"Auth.ResetPasswordForm.formAriaLabel"}),{inLineAlertProps:e,handleSetInLineAlertProps:d}=P(),{isLoading:n,submitResetPassword:u,redirectToSignInPage:i}=D({routeSignIn:a,setActiveComponent:m,onErrorCallback:s,handleSetInLineAlertProps:d});return l("div",{...c,className:b(["auth-reset-password-form",`auth-reset-password-form--${t}`]),"data-testid":"resetPasswordForm",children:[o(v,{title:r.title,divider:!1,className:"auth-reset-password-form__title"}),e.text?o(N,{className:"auth-reset-password-form__notification",type:e.type,variant:"secondary",heading:e.text,icon:e.icon}):null,o(_,{"aria-labelledby":r.formAriaLabel,name:"resetPassword_form",className:"auth-reset-password-form__form",onSubmit:u,loading:n,fieldsConfig:E(L),children:l("div",{className:"auth-reset-password-form__buttons",children:[o(p,{type:"button",variant:"tertiary",style:{padding:"0"},icon:o(T,{style:{transform:"rotate(90deg)"}}),buttonText:r.buttonSecondary,enableLoader:!1,onClick:i}),o(p,{type:"submit",buttonText:r.buttonPrimary,variant:"primary",enableLoader:n})]})}),o("div",{id:"requestPasswordResetEmail"})]})};export{$ as R}; +import{jsxs as l,jsx as a}from"@dropins/tools/preact-jsx-runtime.js";import{classes as R}from"@dropins/tools/lib.js";/* empty css */import"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{r as h}from"./requestPasswordResetEmail.js";import{g as _,c as w,u as F,F as P,B as p}from"./Button2.js";import{useState as x,useCallback as b}from"@dropins/tools/preact-hooks.js";import{useText as y}from"@dropins/tools/i18n.js";import{Header as N,InLineAlert as v}from"@dropins/tools/components.js";import{s as E,D as L}from"./simplifyTransformAttributesForm.js";import*as g from"@dropins/tools/preact-compat.js";const T=t=>g.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t},g.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),D=({routeSignIn:t,onErrorCallback:o,setActiveComponent:m,handleSetInLineAlertProps:s})=>{const c=y({successPasswordResetEmailNotification:"Auth.Notification.successPasswordResetEmailNotification"}),[r,e]=x(!1),d=b(async u=>{u.preventDefault(),e(!0);const i=_(u.target);if(i&&i.email){const f=await h(i.email);f.success?s==null||s({type:"success",text:c.successPasswordResetEmailNotification.replace("{email}",i.email)}):(o==null||o(f),s==null||s({type:"error",text:f.message}))}e(!1)},[s,o,c.successPasswordResetEmailNotification]),n=b(()=>{if(w(m)){m("signInForm");return}w(t)&&(window.location.href=t())},[m,t]);return{isLoading:r,submitResetPassword:d,redirectToSignInPage:n}},$=({formSize:t="default",routeSignIn:o,setActiveComponent:m,onErrorCallback:s,...c})=>{const r=y({title:"Auth.ResetPasswordForm.title",buttonPrimary:"Auth.ResetPasswordForm.buttonPrimary",buttonSecondary:"Auth.ResetPasswordForm.buttonSecondary",formAriaLabel:"Auth.ResetPasswordForm.formAriaLabel"}),{inLineAlertProps:e,handleSetInLineAlertProps:d}=F(),{isLoading:n,submitResetPassword:u,redirectToSignInPage:i}=D({routeSignIn:o,setActiveComponent:m,onErrorCallback:s,handleSetInLineAlertProps:d});return l("div",{...c,className:R(["auth-reset-password-form",`auth-reset-password-form--${t}`]),"data-testid":"resetPasswordForm",children:[a(N,{title:r.title,divider:!1,className:"auth-reset-password-form__title"}),e.text?a(v,{className:"auth-reset-password-form__notification",type:e.type,variant:"secondary",heading:e.text,icon:e.icon}):null,a(P,{"aria-labelledby":r.formAriaLabel,name:"resetPassword_form",className:"auth-reset-password-form__form",onSubmit:u,loading:n,fieldsConfig:E(L),children:l("div",{className:"auth-reset-password-form__buttons",children:[a(p,{className:"auth-reset-password-form__buttons--back",type:"button",variant:"tertiary",style:{padding:"0"},icon:a(T,{style:{transform:"rotate(90deg)"}}),buttonText:r.buttonSecondary,enableLoader:!1,onClick:i}),a(p,{type:"submit",buttonText:r.buttonPrimary,variant:"primary",enableLoader:n})]})}),a("div",{id:"requestPasswordResetEmail"})]})};export{$ as R}; diff --git a/scripts/__dropins__/storefront-auth/configs/excludedFocusClasses.d.ts b/scripts/__dropins__/storefront-auth/configs/excludedFocusClasses.d.ts new file mode 100644 index 000000000..871b8d46b --- /dev/null +++ b/scripts/__dropins__/storefront-auth/configs/excludedFocusClasses.d.ts @@ -0,0 +1,15 @@ +/** + * This file defines an array of class names that should be excluded + * from specific init Recaptcha logic. + * + * The array contains class names representing elements that should be + * ignored when certain operations, such as focusing or applying event + * handlers, are executed. + * + * By checking if an element's class matches any class in this array, + * you can easily bypass unwanted logic for those elements, ensuring + * precise and predictable behavior in your application. + * + */ +export declare const excludedFocusClasses: string[]; +//# sourceMappingURL=excludedFocusClasses.d.ts.map \ No newline at end of file diff --git a/scripts/__dropins__/storefront-auth/hooks/components/useForm.d.ts b/scripts/__dropins__/storefront-auth/hooks/components/useForm.d.ts index aafd005ac..32f15722c 100644 --- a/scripts/__dropins__/storefront-auth/hooks/components/useForm.d.ts +++ b/scripts/__dropins__/storefront-auth/hooks/components/useForm.d.ts @@ -7,6 +7,6 @@ export declare const useForm: ({ fieldsConfig, onSubmit }: useFormProps) => { handleChange: (event: Event) => void; handleBlur: (event: Event) => void; handleSubmit: (event: SubmitEvent) => void; - handleFocus: (event: any) => Promise; + handleFocus: (event: FocusEvent) => Promise; }; //# sourceMappingURL=useForm.d.ts.map \ No newline at end of file