react-component-form
Advanced tools
Comparing version 3.1.0 to 3.1.1
import * as React$1 from 'react'; | ||
import React__default from 'react'; | ||
import { SchemaOptions, Static, TObject } from '@sinclair/typebox'; | ||
import { Static, TObject } from '@sinclair/typebox'; | ||
import { ErrorObject } from 'ajv'; | ||
@@ -28,3 +28,5 @@ import * as ajv_dist_core from 'ajv/dist/core'; | ||
declare type Schema = SchemaOptions; | ||
interface Schema { | ||
[property: string]: any; | ||
} | ||
declare type Error = ErrorObject; | ||
@@ -81,3 +83,3 @@ declare type ErrorsObject<K extends Schema> = { | ||
} | ||
declare const useForm: <K extends SchemaOptions>(validationSchema: K) => UseFormResult<K>; | ||
declare const useForm: <K extends Schema>(validationSchema: K) => UseFormResult<K>; | ||
@@ -84,0 +86,0 @@ declare const ajv: ajv_dist_core.default; |
@@ -1,2 +0,2 @@ | ||
import K,{useRef as v}from"react";var S=t=>Object.fromEntries(new FormData(t)),k=t=>{let{onSubmit:r,onChange:o,children:e,...l}=t,n=v(null);return K.createElement("form",{ref:n,onSubmit:async s=>{if(s.preventDefault(),r!=null){let h=S(n.current);await r(h,n.current)}},onChange:async()=>{if(o!=null){let s=S(n.current);await o(s,n.current)}},...l},e)};import{useState as M}from"react";var A=["idle","loading","error","success"],b=(t="idle")=>{let[r,o]=M(t);return[r,o]};import{useMemo as O,useState as j}from"react";import{Type as T}from"@sinclair/typebox";import P from"ajv-formats";import R from"ajv";var x=P(new R({allErrors:!0,verbose:!0}),["date-time","time","date","email","hostname","ipv4","ipv6","uri","uri-reference","uuid","uri-template","json-pointer","relative-json-pointer","regex"]);var g=(t,r)=>{let o=[];for(let e in r.properties)r.properties[e].type==="boolean"&&o.push(e);for(let e of o)t[e]==null?t[e]=r.properties[e].default:t[e]=t[e]==="on";return t};var E=(t,r=[])=>Object.fromEntries(Object.entries(t).map(([o,e])=>typeof e=="string"&&e.length===0&&!r.includes(o)?[o,null]:[o,e]));var ee=t=>{let r=O(()=>T.Object(t),[t]),[o,e]=b(),[l,n]=j(void 0),[u,c]=j({}),s=O(()=>x.compile(r),[r]);return{handleUseForm:F=>async(a,H)=>{if(c({}),n(void 0),a=E(a,r.required),a=g(a,r),s(a)){if(c({}),F!=null){e("loading");let m=await F(a,H);if(m!=null){let{value:d,type:i,properties:f}=m;if(n(d),e(i),i==="error"){let y={};for(let p in f)y[p]=[{keyword:"message",message:f[p],instancePath:`/${p}`,schemaPath:`#/properties/${p}/message`,params:{},data:a[p]}];c(y)}}}}else{e("error");let m={};for(let d in r.properties){let i=s.errors?.filter(f=>f.instancePath===`/${d}`);m[d]=i!=null&&i.length>0?i:void 0}c(m)}},fetchState:o,setFetchState:e,message:l,setMessage:n,errors:u}};export{k as Form,x as ajv,A as fetchState,S as getFormDataObject,b as useFetchState,ee as useForm}; | ||
import K,{useRef as v}from"react";var S=t=>Object.fromEntries(new FormData(t)),k=t=>{let{onSubmit:r,onChange:o,children:e,...l}=t,n=v(null);return K.createElement("form",{ref:n,onSubmit:async s=>{if(s.preventDefault(),r!=null){let h=S(n.current);await r(h,n.current)}},onChange:async()=>{if(o!=null){let s=S(n.current);await o(s,n.current)}},...l},e)};import{useState as M}from"react";var A=["idle","loading","error","success"],b=(t="idle")=>{let[r,o]=M(t);return[r,o]};import{useMemo as O,useState as j}from"react";import{Type as T}from"@sinclair/typebox";import P from"ajv-formats";import R from"ajv";var x=P(new R({allErrors:!0,verbose:!0}),["date-time","time","date","email","hostname","ipv4","ipv6","uri","uri-reference","uuid","uri-template","json-pointer","relative-json-pointer","regex"]);var g=(t,r)=>{let o=[];for(let e in r.properties)r.properties[e].type==="boolean"&&o.push(e);for(let e of o)t[e]==null?t[e]=r.properties[e].default:t[e]=t[e]==="on";return t};var E=(t,r=[])=>Object.fromEntries(Object.entries(t).map(([o,e])=>typeof e=="string"&&e.length===0&&!r.includes(o)?[o,null]:[o,e]));var X=t=>{let r=O(()=>T.Object(t),[t]),[o,e]=b(),[l,n]=j(void 0),[u,c]=j({}),s=O(()=>x.compile(r),[r]);return{handleUseForm:y=>async(a,H)=>{if(c({}),n(void 0),a=E(a,r.required),a=g(a,r),s(a)){if(c({}),y!=null){e("loading");let m=await y(a,H);if(m!=null){let{value:d,type:i,properties:f}=m;if(n(d),e(i),i==="error"){let F={};for(let p in f)F[p]=[{keyword:"message",message:f[p],instancePath:`/${p}`,schemaPath:`#/properties/${p}/message`,params:{},data:a[p]}];c(F)}}}}else{e("error");let m={};for(let d in r.properties){let i=s.errors?.filter(f=>f.instancePath===`/${d}`);m[d]=i!=null&&i.length>0?i:void 0}c(m)}},fetchState:o,setFetchState:e,message:l,setMessage:n,errors:u}};export{k as Form,x as ajv,A as fetchState,S as getFormDataObject,b as useFetchState,X as useForm}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-component-form", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"public": true, | ||
@@ -40,3 +40,3 @@ "type": "module", | ||
"dependencies": { | ||
"@sinclair/typebox": "0.24.28", | ||
"@sinclair/typebox": "0.24.42", | ||
"ajv": "8.11.0", | ||
@@ -46,15 +46,15 @@ "ajv-formats": "2.1.1" | ||
"devDependencies": { | ||
"@commitlint/cli": "17.0.3", | ||
"@commitlint/config-conventional": "17.0.3", | ||
"@testing-library/react": "13.3.0", | ||
"@types/jest": "28.1.8", | ||
"@types/react": "18.0.17", | ||
"@commitlint/cli": "17.1.2", | ||
"@commitlint/config-conventional": "17.1.0", | ||
"@testing-library/react": "13.4.0", | ||
"@types/jest": "29.0.3", | ||
"@types/react": "18.0.20", | ||
"@types/react-dom": "18.0.6", | ||
"@typescript-eslint/eslint-plugin": "5.35.1", | ||
"@typescript-eslint/parser": "5.35.1", | ||
"@typescript-eslint/eslint-plugin": "5.38.0", | ||
"@typescript-eslint/parser": "5.38.0", | ||
"editorconfig-checker": "4.0.2", | ||
"esbuild": "0.15.5", | ||
"esbuild": "0.15.8", | ||
"esbuild-jest": "0.5.0", | ||
"eslint": "8.22.0", | ||
"eslint-config-conventions": "3.0.0", | ||
"eslint": "8.23.1", | ||
"eslint-config-conventions": "4.0.1", | ||
"eslint-config-prettier": "8.5.0", | ||
@@ -65,4 +65,4 @@ "eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-unicorn": "43.0.2", | ||
"jest": "29.0.0", | ||
"jest-environment-jsdom": "29.0.0", | ||
"jest": "29.0.3", | ||
"jest-environment-jsdom": "29.0.3", | ||
"markdownlint-cli2": "0.5.1", | ||
@@ -73,5 +73,5 @@ "prettier": "2.7.1", | ||
"semantic-release": "19.0.5", | ||
"tsup": "6.2.2", | ||
"typescript": "4.7.4" | ||
"tsup": "6.2.3", | ||
"typescript": "4.8.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27636
90
+ Added@sinclair/typebox@0.24.42(transitive)
- Removed@sinclair/typebox@0.24.28(transitive)
Updated@sinclair/typebox@0.24.42