@mobilestock-native/form 0.0.5 → 0.0.7
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.
- package/index.js +1 -1
- package/package.json +7 -4
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var gr=Object.create;var z=Object.defineProperty,Fr=Object.defineProperties,Er=Object.getOwnPropertyDescriptor,Ir=Object.getOwnPropertyDescriptors,Pr=Object.getOwnPropertyNames
|
|
1
|
+
"use strict";var gr=Object.create;var z=Object.defineProperty,Fr=Object.defineProperties,Er=Object.getOwnPropertyDescriptor,Ir=Object.getOwnPropertyDescriptors,Pr=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,Rr=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var W=(r,e,o)=>e in r?z(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,F=(r,e)=>{for(var o in e||(e={}))U.call(e,o)&&W(r,o,e[o]);if($)for(var o of $(e))_.call(e,o)&&W(r,o,e[o]);return r},E=(r,e)=>Fr(r,Ir(e));var I=(r,e)=>{var o={};for(var n in r)U.call(r,n)&&e.indexOf(n)<0&&(o[n]=r[n]);if(r!=null&&$)for(var n of $(r))e.indexOf(n)<0&&_.call(r,n)&&(o[n]=r[n]);return o};var xr=(r,e)=>{for(var o in e)z(r,o,{get:e[o],enumerable:!0})},D=(r,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Pr(e))!U.call(r,s)&&s!==o&&z(r,s,{get:()=>e[s],enumerable:!(n=Er(e,s))||n.enumerable});return r};var X=(r,e,o)=>(o=r!=null?gr(Rr(r)):{},D(e||!r||!r.__esModule?z(o,"default",{value:r,enumerable:!0}):o,r)),Tr=r=>D(z({},"__esModule",{value:!0}),r);var q=(r,e,o)=>new Promise((n,s)=>{var b=m=>{try{d(o.next(m))}catch(c){s(c)}},l=m=>{try{d(o.throw(m))}catch(c){s(c)}},d=m=>m.done?n(m.value):Promise.resolve(m.value).then(b,l);d((o=o.apply(r,e)).next())});var wr={};xr(wr,{Form:()=>yr,useForm:()=>V});module.exports=Tr(wr);var tr=require("@mobilestock-native/button");var J=require("@unform/mobile"),P=require("react"),Q=require("zod"),Y=require("@mobilestock-native/container"),rr=require("@mobilestock-native/modalalert");var C=require("react/jsx-runtime"),er=(0,P.createContext)({});function V(){return(0,P.useContext)(er)}function or(s){var b=s,{children:r,onSubmit:e,schema:o}=b,n=I(b,["children","onSubmit","schema"]);let l=(0,P.useRef)(null),[d,m]=(0,P.useState)(!1),[c,S]=(0,P.useState)(void 0);function H(){var a;(a=l.current)==null||a.submitForm()}function j(){var a,t;(a=l.current)==null||a.setErrors({}),(t=l.current)==null||t.reset()}function A(a){let t={};for(let g of a){let y=g.path.filter(T=>typeof T=="string"||typeof T=="number").join(".");y&&(t[String(y)]=g.message)}return t}function k(a){if(a instanceof Q.ZodError)return A(a.issues);if(typeof a=="object"&&a!==null&&"errors"in a){let t=a.errors;if(Array.isArray(t)&&t.length>0&&"message"in t[0]&&"path"in t[0])return A(t)}return null}function N(g,y){return q(this,arguments,function*(a,{reset:t}){var T,O,h,w,M;if((T=l.current)==null||T.setErrors({}),o){let f=o.safeParse(a);if(!f.success){(O=l.current)==null||O.setErrors(A(f.error.issues));return}}try{m(!0),yield e({data:a,ref:l,reset:t})}catch(f){let G=k(f);if(G)(h=l.current)==null||h.setErrors(G);else{let u="Erro ao realizar opera\xE7\xE3o",i=500;if(typeof f=="object"&&f!==null&&"isAxiosError"in f&&f.isAxiosError){let R=f;i=((w=R.response)==null?void 0:w.status)||500;let v=(M=R.response)==null?void 0:M.data;v!=null&&v.message&&(u=v.message)}else f instanceof Error&&(u=f.message||u);S({message:u,status:i})}}finally{m(!1)}})}return(0,C.jsxs)(er.Provider,{value:{formRef:l,submitForm:H,clearForm:j,loading:d},children:[(0,C.jsx)(J.Form,E(F({ref:l,onSubmit:N},n),{children:(0,C.jsx)(Y.Container.Vertical,{gap:"2XS",children:r})})),(0,C.jsx)(rr.ModalAlert,{visible:!!c,message:c==null?void 0:c.message,type:c&&c.status>=500?"FATAL_ERROR":"ERROR_NOTICE",title:"Erro ao enviar o formul\xE1rio",onClose:()=>S(void 0)})]})}var sr=require("react/jsx-runtime");function nr(s){var b=s,{type:r="SUBMIT",isLoading:e,onPress:o}=b,n=I(b,["type","isLoading","onPress"]);let{submitForm:l,clearForm:d,loading:m}=V();function c(S){switch(r){case"SUBMIT":l();break;case"RESET":d();break;default:o==null||o(S)}}return(0,sr.jsx)(tr.Button,E(F({size:"LG"},n),{onPress:c,isLoading:r==="SUBMIT"&&m||e,disabled:m||e}))}var ir=require("@mobilestock-native/container");var ur=require("react/jsx-runtime");function ar(o){var n=o,{children:r}=n,e=I(n,["children"]);return(0,ur.jsx)(ir.Container.Horizontal,E(F({gap:"SM"},e),{children:r}))}var lr=require("@unform/core"),p=require("react"),mr=require("react-native"),B=X(require("styled-components/native")),cr=require("@mobilestock-native/button"),K=require("@mobilestock-native/container"),L=X(require("@mobilestock-native/tools")),Z=require("@mobilestock-native/typography");var x=require("react/jsx-runtime"),pr=(0,p.forwardRef)(function(A,j){var k=A,{name:e,label:o,defaultValue:n,type:s="text",autoSubmit:b=!1,format:l,onChangeText:d,autoCapitalize:m,full:c,maxLength:S}=k,H=I(k,["name","label","defaultValue","type","autoSubmit","format","onChangeText","autoCapitalize","full","maxLength"]);let{loading:N,submitForm:a}=V(),t=(0,lr.useField)(e),g=(0,p.useRef)(null),[y,T]=(0,p.useState)(!0),[O,h]=(0,p.useState)(""),w=s==="password",M=s==="tel"?15:s==="zipcode"?9:S;(0,p.useEffect)(()=>{let u=O||n||(t==null?void 0:t.defaultValue)||"";g.current.value=u,h(u),t.registerField({name:t.fieldName,ref:g.current,getValue(i){return(i==null?void 0:i.value)||""},setValue(i,R){i.value=R,h(R)},clearValue(i){i.value="",h("")}})},[t==null?void 0:t.fieldName,t==null?void 0:t.registerField]),(0,p.useImperativeHandle)(j,()=>({focus(){var u;(u=g.current)==null||u.focus()},blur(){var u;(u=g.current)==null||u.blur()}}));let f=(0,p.useCallback)(u=>{var R,v;let i=u;switch(s){case"tel":i=L.default.phoneNumberFormatter(u);break;case"email":case"url":i=u.trim();break;case"number":i=u.replace(/[^0-9.,]/g,"");break;case"zipcode":i=L.default.formatZipcode(i);break}l&&(i=l(i)),h(i),g.current.value=i,d==null||d(i),s==="tel"&&b&&i.length===15&&((R=g.current)==null||R.blur(),a()),s==="zipcode"&&b&&i.length===9&&((v=g.current)==null||v.blur(),a())},[s,l,b,d,t]),G=(0,p.useCallback)(()=>{switch(s){case"tel":return"phone-pad";case"email":return"email-address";case"url":return"url";case"number":return"numeric";default:return"default"}},[s]);return(0,x.jsxs)(hr,{full:c,$show:s!=="hidden",children:[o&&(0,x.jsx)(Z.Typography,{children:o}),(0,x.jsxs)(vr,{error:!!(t!=null&&t.error),$isPassword:w,children:[(0,x.jsx)(Sr,E(F({},H),{ref:g,value:O,autoCapitalize:s&&["email","url"].includes(s)?"none":m,keyboardType:G(),secureTextEntry:y&&w,onChangeText:f,maxLength:M,editable:!N&&H.editable})),w&&(0,x.jsx)(cr.Button,{size:"SM",onPress:()=>T(!y),icon:y?"EyeOff":"EyeOutline",variant:"TRANSPARENT"})]}),(t==null?void 0:t.error)&&(0,x.jsx)(Z.Typography,{color:"DANGER",size:"SM",children:t.error})]})}),hr=(0,B.default)(K.Container.Vertical)`
|
|
2
2
|
${({$show:r})=>!r&&B.css`
|
|
3
3
|
display: none;
|
|
4
4
|
`}
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilestock-native/form",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@unform/core": "^2.1.6",
|
|
7
|
-
"@mobilestock-native/button": "^1.0.
|
|
8
|
-
"@mobilestock-native/icons": "^0.0.6",
|
|
7
|
+
"@mobilestock-native/button": "^1.0.9",
|
|
9
8
|
"@mobilestock-native/container": "^0.0.4",
|
|
10
|
-
"@mobilestock-native/
|
|
9
|
+
"@mobilestock-native/icons": "^0.0.6",
|
|
10
|
+
"@mobilestock-native/modalalert": "^0.0.10",
|
|
11
11
|
"@mobilestock-native/tools": "^0.0.9",
|
|
12
12
|
"@mobilestock-native/typography": "^0.0.8"
|
|
13
13
|
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"axios": "^1.7.7"
|
|
16
|
+
},
|
|
14
17
|
"peerDependencies": {
|
|
15
18
|
"react": "18.2.0",
|
|
16
19
|
"react-native": "0.74.5",
|