@dropins/storefront-auth 0.0.1-alpha15 → 0.0.1-alpha16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{jsxs as _,jsx as d,Fragment as k}from"@dropins/tools/preact-jsx-runtime.js";import{useCallback as b,useRef as g,useState as v,useEffect as x}from"@dropins/tools/preact-hooks.js";import{classes as I}from"@dropins/tools/lib.js";import{Button as S,Field as M,Picker as V,Input as O,InputDate as R,Checkbox as y,TextArea as H}from"@dropins/tools/components.js";import{initReCaptcha as P}from"@dropins/tools/recaptcha.js";import{useText as q}from"@dropins/tools/i18n.js";import*as f from"@dropins/tools/preact-compat.js";import{memo as U,useCallback as N}from"@dropins/tools/preact-compat.js";const ee=r=>{if(!r)return null;const c=new FormData(r);if(c&&typeof c.entries=="function"){const u=c.entries();if(u&&typeof u[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(u)))||{}}return{}},re=r=>typeof r=="function",te=({type:r,buttonText:c,variant:u,className:l="",enableLoader:o=!1,onClick:s,style:h,icon:n,...p})=>{const $=b(T=>{s==null||s(T)},[s]);return _(S,{icon:n,style:h,type:r,variant:u,className:I(["auth-button",l,o?"enableLoader":""]),onClick:$,...p,children:[d("span",{className:"auth-button__text",children:c}),o?d("div",{className:"auth-button__loader-wrapper",children:d("span",{className:"auth-button__loader"})}):null]})},W=r=>r.reduce((c,{code:u,required:l,defaultValue:o})=>(l&&(c[u]=o),c),{}),G=({fieldsConfig:r,submitCallback:c})=>{const{requiredFieldError:u}=q({requiredFieldError:"Auth.FormText.requiredFieldError"}),l=g(null),[o,s]=v({}),[h,n]=v({});x(()=>{if(!r.length)return;const E=W(r);s(E)},[r==null?void 0:r.length]);const p=b((E,e)=>{const t=r.find(i=>i.code===E);return t!=null&&t.required&&!e?u:""},[r,u]),$=b(E=>{const{name:e,value:t,type:a,checked:i}=E==null?void 0:E.target,w=a==="checkbox"?i:t;s(D=>({...D,[e]:w}))},[]);x(()=>{P()},[]);const A=b(E=>{const{name:e,value:t,type:a,checked:i}=E==null?void 0:E.target,w=a==="checkbox"?i:t;n(D=>({...D,[e]:p(e,w)}))},[p]),T=b(E=>{E.preventDefault();let e=!0,t={},a=null;for(const[i,w]of Object.entries(o)){const D=p(i,w);D&&(t[i]=D,e=!1,a||(a=i))}if(n(t),a&&l.current){const i=l.current.elements.namedItem(a);i==null||i.focus()}c==null||c(E,e)},[o,p,c]);return{formData:o,errors:h,formRef:l,handleChange:$,handleBlur:A,handleSubmit:T}};var L=(r=>(r.BOOLEAN="BOOLEAN",r.DATE="DATE",r.DATETIME="DATETIME",r.DROPDOWN="DROPDOWN",r.FILE="FILE",r.GALLERY="GALLERY",r.HIDDEN="HIDDEN",r.IMAGE="IMAGE",r.MEDIA_IMAGE="MEDIA_IMAGE",r.MULTILINE="MULTILINE",r.MULTISELECT="MULTISELECT",r.PRICE="PRICE",r.SELECT="SELECT",r.TEXT="TEXT",r.TEXTAREA="TEXTAREA",r.UNDEFINED="UNDEFINED",r.VISUAL="VISUAL",r.WEIGHT="WEIGHT",r.EMPTY="",r))(L||{});const C=U(({loading:r,values:c,fields:u=[],errors:l,className:o="",onChange:s,onBlur:h})=>{const n=`${o}__field`,p=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:d(V,{name:e.id,floatingLabel:`${e.label} ${e.required?"*":""}`,placeholder:e.label,"aria-label":e.label,options:e.options,onBlur:h,handleSelect:s,value:t||e.defaultValue})},e.id),[o,r,n,h,s]),$=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:d(O,{type:"text",name:e.id,value:t===void 0?e.defaultValue:t,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[o,r,n,h,s]),A=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:d(R,{type:"text",name:e.id,value:t||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[o,r,n,h,s]),T=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:d(y,{name:e.id,checked:t||e.defaultValue,placeholder:e.label,label:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[o,r,n,h,s]),E=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:d(H,{type:"text",name:e.id,value:t===void 0?e.defaultValue:t,label:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[o,r,n,h,s]);return u.length?d(k,{children:u.map(e=>{const t=(l==null?void 0:l[e.id])??void 0,a=(c==null?void 0:c[e.id])??void 0;switch(e.fieldType){case L.TEXT:return e.options.length?p(e,a,t):$(e,a,t);case L.MULTILINE:return $(e,a,t);case L.SELECT:return p(e,a,t);case L.DATE:return A(e,a,t);case L.BOOLEAN:return T(e,a,t);case"TEXTAREA":return E(e,a,t);default:return null}})}):null}),ne=({name:r,isLoading:c,children:u,className:l="defaultForm",fieldsConfig:o=[],submitCallback:s})=>{const{formData:h,errors:n,formRef:p,handleChange:$,handleBlur:A,handleSubmit:T}=G({submitCallback:s,fieldsConfig:o});return _("form",{onSubmit:T,className:l,name:r,ref:p,children:[d(C,{fields:o,onChange:$,onBlur:A,errors:n,values:h,className:l,isLoading:c}),u]})},ae=({children:r,text:c,bottomLine:u=!0,className:l})=>_("div",{className:I(["auth-title",l]),"data-testid":"auth-title_id",children:[_("div",{className:"auth-title__text",children:[d("h1",{className:"auth-title__heading",children:c}),r]}),u?d("div",{className:"auth-title__hr"}):null]}),Z=r=>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",...r},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)"})))),B=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},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"})),X=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},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"})),j={success:d(B,{}),warning:d(Z,{}),error:d(X,{})},oe=()=>{const[r,c]=v({}),u=b(l=>{if(!l||!l.type){c({});return}const o=j[l.type];c({...l,icon:o})},[]);return{inLineAlertProps:r,handleSetInLineAlertProps:u}};export{te as B,ne as F,ae as T,re as c,ee as g,oe as u};
1
+ import{jsxs as x,jsx as d,Fragment as k}from"@dropins/tools/preact-jsx-runtime.js";import{useCallback as b,useRef as g,useState as _,useEffect as v}from"@dropins/tools/preact-hooks.js";import{classes as I}from"@dropins/tools/lib.js";import{Button as S,Field as M,Picker as V,Input as O,InputDate as R,Checkbox as y,TextArea as H}from"@dropins/tools/components.js";import{initReCaptcha as P}from"@dropins/tools/recaptcha.js";import{useText as q}from"@dropins/tools/i18n.js";import*as f from"@dropins/tools/preact-compat.js";import{memo as U,useCallback as N}from"@dropins/tools/preact-compat.js";const ee=r=>{if(!r)return null;const o=new FormData(r);if(o&&typeof o.entries=="function"){const u=o.entries();if(u&&typeof u[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(u)))||{}}return{}},re=r=>typeof r=="function",te=({type:r,buttonText:o,variant:u,className:l="",enableLoader:c=!1,onClick:s,style:h,icon:n,...p})=>{const $=b(T=>{s==null||s(T)},[s]);return x(S,{icon:n,style:h,type:r,variant:u,className:I(["auth-button",l,c?"enableLoader":""]),onClick:$,...p,children:[d("span",{className:"auth-button__text",children:o}),c?d("div",{className:"auth-button__loader-wrapper",children:d("span",{className:"auth-button__loader"})}):null]})},W=r=>r.reduce((o,{code:u,required:l,defaultValue:c})=>(l&&(o[u]=c),o),{}),G=({fieldsConfig:r,submitCallback:o})=>{const{requiredFieldError:u}=q({requiredFieldError:"Auth.FormText.requiredFieldError"}),l=g(null),[c,s]=_({}),[h,n]=_({});v(()=>{if(!r.length)return;const E=W(r);s(E)},[r==null?void 0:r.length]);const p=b((E,e)=>{const t=r.find(i=>i.code===E);return t!=null&&t.required&&!e?u:""},[r,u]),$=b(E=>{const{name:e,value:t,type:a,checked:i}=E==null?void 0:E.target,w=a==="checkbox"?i:t;s(D=>({...D,[e]:w}))},[]);v(()=>{P()},[]);const A=b(E=>{const{name:e,value:t,type:a,checked:i}=E==null?void 0:E.target,w=a==="checkbox"?i:t;n(D=>({...D,[e]:p(e,w)}))},[p]),T=b(E=>{E.preventDefault();let e=!0,t={},a=null;for(const[i,w]of Object.entries(c)){const D=p(i,w);D&&(t[i]=D,e=!1,a||(a=i))}if(n(t),a&&l.current){const i=l.current.elements.namedItem(a);i==null||i.focus()}o==null||o(E,e)},[c,p,o]);return{formData:c,errors:h,formRef:l,handleChange:$,handleBlur:A,handleSubmit:T}};var L=(r=>(r.BOOLEAN="BOOLEAN",r.DATE="DATE",r.DATETIME="DATETIME",r.DROPDOWN="DROPDOWN",r.FILE="FILE",r.GALLERY="GALLERY",r.HIDDEN="HIDDEN",r.IMAGE="IMAGE",r.MEDIA_IMAGE="MEDIA_IMAGE",r.MULTILINE="MULTILINE",r.MULTISELECT="MULTISELECT",r.PRICE="PRICE",r.SELECT="SELECT",r.TEXT="TEXT",r.TEXTAREA="TEXTAREA",r.UNDEFINED="UNDEFINED",r.VISUAL="VISUAL",r.WEIGHT="WEIGHT",r.EMPTY="",r))(L||{});const C=U(({loading:r,values:o,fields:u=[],errors:l,className:c="",onChange:s,onBlur:h})=>{const n=`${c}__field`,p=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:d(V,{name:e.id,floatingLabel:`${e.label} ${e.required?"*":""}`,placeholder:e.label,"aria-label":e.label,options:e.options.map(i=>({...i,text:i.label})),onBlur:h,handleSelect:s,value:t||e.defaultValue})},e.id),[c,r,n,h,s]),$=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:d(O,{type:"text",name:e.id,value:t===void 0?e.defaultValue:t,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[c,r,n,h,s]),A=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:d(R,{type:"text",name:e.id,value:t||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[c,r,n,h,s]),T=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:d(y,{name:e.id,checked:t||e.defaultValue,placeholder:e.label,label:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[c,r,n,h,s]),E=N((e,t,a)=>d(M,{error:a,className:I([n,`${n}--${e.id}`,[`${n}--${e.id}-hidden`,e.hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:r,children:d(H,{type:"text",name:e.id,value:t===void 0?e.defaultValue:t,label:`${e.label} ${e.required?"*":""}`,onBlur:h,onChange:s})},e.id),[c,r,n,h,s]);return u.length?d(k,{children:u.map(e=>{const t=(l==null?void 0:l[e.id])??void 0,a=(o==null?void 0:o[e.id])??void 0;switch(e.fieldType){case L.TEXT:return e.options.length?p(e,a,t):$(e,a,t);case L.MULTILINE:return $(e,a,t);case L.SELECT:return p(e,a,t);case L.DATE:return A(e,a,t);case L.BOOLEAN:return T(e,a,t);case"TEXTAREA":return E(e,a,t);default:return null}})}):null}),ne=({name:r,isLoading:o,children:u,className:l="defaultForm",fieldsConfig:c=[],submitCallback:s})=>{const{formData:h,errors:n,formRef:p,handleChange:$,handleBlur:A,handleSubmit:T}=G({submitCallback:s,fieldsConfig:c});return x("form",{onSubmit:T,className:l,name:r,ref:p,children:[d(C,{fields:c,onChange:$,onBlur:A,errors:n,values:h,className:l,isLoading:o}),u]})},ae=({children:r,text:o,bottomLine:u=!0,className:l})=>x("div",{className:I(["auth-title",l]),"data-testid":"auth-title_id",children:[x("div",{className:"auth-title__text",children:[d("h1",{className:"auth-title__heading",children:o}),r]}),u?d("div",{className:"auth-title__hr"}):null]}),Z=r=>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",...r},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)"})))),B=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},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"})),X=r=>f.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},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"})),j={success:d(B,{}),warning:d(Z,{}),error:d(X,{})},ce=()=>{const[r,o]=_({}),u=b(l=>{if(!l||!l.type){o({});return}const c=j[l.type];o({...l,icon:c})},[]);return{inLineAlertProps:r,handleSetInLineAlertProps:u}};export{te as B,ne as F,ae as T,re as c,ee as g,ce as u};
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-auth", "version": "0.0.1-alpha15", "@dropins/elsie": "0.28.0-beta2"}
1
+ {"name": "@dropins/storefront-auth", "version": "0.0.1-alpha16", "@dropins/elsie": "0.28.0-beta2"}