Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hook-form

Package Overview
Dependencies
Maintainers
1
Versions
1032
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hook-form - npm Package Compare versions

Comparing version 7.12.2 to 7.43.9

dist/__tests__/controller.server.test.d.ts

2

dist/constants.d.ts
import { ValidationMode } from './types';
export declare const EVENTS: {
BLUR: string;
FOCUS_OUT: string;
CHANGE: string;

@@ -16,1 +17,2 @@ };

};
//# sourceMappingURL=constants.d.ts.map
/// <reference types="react" />
import { ControllerProps, FieldValues } from './types';
declare const Controller: <TFieldValues extends FieldValues = FieldValues, TName extends import("./types").Path<TFieldValues> = import("./types").Path<TFieldValues>>(props: ControllerProps<TFieldValues, TName>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
import { ControllerProps, FieldPath, FieldValues } from './types';
/**
* Component based on `useController` hook to work with controlled component.
*
* @remarks
* [API](https://react-hook-form.com/api/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
*
* @param props - the path name to the form field value, and validation rules.
*
* @returns provide field handler functions, field and form state.
*
* @example
* ```tsx
* function App() {
* const { control } = useForm<FormValues>({
* defaultValues: {
* test: ""
* }
* });
*
* return (
* <form>
* <Controller
* control={control}
* name="test"
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
* <>
* <input
* onChange={onChange} // send value to hook form
* onBlur={onBlur} // notify when input is touched
* value={value} // return updated value
* ref={ref} // set ref for focus management
* />
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
* <p>{fieldState.isTouched ? "touched" : ""}</p>
* </>
* )}
* />
* </form>
* );
* }
* ```
*/
declare const Controller: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: ControllerProps<TFieldValues, TName>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export { Controller };
//# sourceMappingURL=controller.d.ts.map

2

dist/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";function e(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("react")),t=e=>"checkbox"===e.type,n=e=>e instanceof Date,s=e=>null==e;const u=e=>"object"==typeof e;var c=e=>!s(e)&&!Array.isArray(e)&&u(e)&&!n(e),a=e=>e.substring(0,e.search(/.\d/))||e,i=(e,r)=>[...e].some(e=>a(r)===e),o=e=>e.filter(Boolean),l=e=>void 0===e,f=(e,r,t)=>{if(c(e)&&r){const n=o(r.split(/[,[\].]+?/)).reduce((e,r)=>s(e)?e:e[r],e);return l(n)||n===e?l(e[r])?t:e[r]:n}};const d="blur",y="change",b="onBlur",g="onChange",m="onSubmit",h="onTouched",v="all",p="max",x="min",O="maxLength",w="minLength",j="pattern",V="required",A="validate";var k=(e,r)=>{const t=Object.assign({},e);return delete t[r],t};const F=r.createContext(null);F.displayName="RHFContext";const _=()=>r.useContext(F);var C=(e,r,t,n,s=!0)=>e?new Proxy(r,{get:(e,r)=>{if(r in e)return t.current[r]!==v&&(t.current[r]=!s||v),n&&(n.current[r]=!0),e[r]}}):r,R=e=>c(e)&&!Object.keys(e).length,S=(e,r,t)=>{const n=k(e,"name");return R(n)||Object.keys(n).length>=Object.keys(r).length||Object.keys(n).find(e=>r[e]===(!t||v))},D=e=>Array.isArray(e)?e:[e],E="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;const B=E?"Proxy"in window:"undefined"!=typeof Proxy;function M(e){const{control:t,name:n}=e||{},s=_(),{formStateRef:u,subjectsRef:c,readFormStateRef:a}=t||s.control,i=r.useRef(n);i.current=n;const[o,l]=r.useState(u.current),f=r.useRef({isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1});return r.useEffect(()=>{const e=c.current.state.subscribe({next:e=>(!i.current||!e.name||D(i.current).includes(e.name))&&S(e,f.current)&&l(Object.assign(Object.assign({},u.current),e))});return()=>e.unsubscribe()},[]),C(B,o,a,f,!1)}function N({name:e,rules:n,defaultValue:s,control:u,shouldUnregister:a}){const o=_(),{defaultValuesRef:b,register:g,fieldsRef:m,unregister:h,namesRef:v,subjectsRef:p,shouldUnmount:x,inFieldArrayActionRef:O}=u||o.control,w=f(m.current,e),[j,V]=r.useState(w&&w._f&&!l(w._f.value)?w._f.value:l(f(b.current,e))?s:f(b.current,e)),{onChange:A,onBlur:k,ref:F}=g(e,Object.assign(Object.assign({},n),{value:j})),C=M({control:u||o.control,name:e});function R(e,r){const t=f(m.current,e);t&&t._f&&(t._f.mount=r)}return r.useEffect(()=>{const r=p.current.control.subscribe({next:r=>(!r.name||e===r.name)&&V(f(r.values,e))});return R(e,!0),()=>{r.unsubscribe();const t=x||a;(i(v.current.array,e)?t&&!O.current:t)?h(e):R(e,!1)}},[e]),{field:{onChange:r=>{const n=(e=>c(e)&&e.target?t(e.target)?e.target.checked:e.target.value:e)(r);V(n),A({target:{value:n,name:e},type:y})},onBlur:()=>{k({target:{name:e},type:d})},name:e,value:j,ref:e=>e&&F({focus:()=>e.focus&&e.focus(),setCustomValidity:r=>e.setCustomValidity(r),reportValidity:()=>e.reportValidity()})},formState:C,fieldState:{invalid:!!f(C.errors,e),isDirty:!!f(C.dirtyFields,e),isTouched:!!f(C.touchedFields,e),error:f(C.errors,e)}}}var T=(e,r,t,n,s)=>r?Object.assign(Object.assign({},t[e]),{types:Object.assign(Object.assign({},t[e]&&t[e].types?t[e].types:{}),{[n]:s||!0})}):{},I=e=>/^\w*$/.test(e),P=e=>o(e.replace(/["|']|\]/g,"").split(/\.|\[/));function U(e,r,t){let n=-1;const s=I(r)?[r]:P(r),u=s.length,a=u-1;for(;++n<u;){const r=s[n];let u=t;if(n!==a){const t=e[r];u=c(t)||Array.isArray(t)?t:isNaN(+s[n+1])?{}:[]}e[r]=u,e=e[r]}return e}const $=(e,r,t)=>{for(const n of t||Object.keys(e)){const t=f(e,n);if(t){const e=t._f,n=k(t,"_f");if(e&&r(e.name)){if(e.ref.focus&&l(e.ref.focus()))break;if(e.refs){e.refs[0].focus();break}}else c(n)&&$(n,r)}}},L=(e,r={})=>{for(const t in e.current){const n=e.current[t];if(n&&!s(r)){const e=n._f,s=k(n,"_f");U(r,t,e&&e.ref?e.ref.disabled||e.refs&&e.refs.every(e=>e.disabled)?void 0:e.value:Array.isArray(n)?[]:{}),s&&L({current:s},r[t])}}return r};var W=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{const t=(16*Math.random()+e)%16|0;return("x"==r?t:3&t|8).toString(16)})},q=(e=[],r)=>e.map(e=>Object.assign({[r]:e&&e[r]||W()},e)),H=e=>s(e)||!u(e);function z(e,r){if(H(e)||H(r)||n(e)||n(r))return e===r;const t=Object.keys(e),s=Object.keys(r);if(t.length!==s.length)return!1;for(const n of t){const t=e[n];if(!s.includes(n))return!1;if("ref"!==n){const e=r[n];if((c(t)||Array.isArray(t))&&(c(e)||Array.isArray(e))?!z(t,e):t!==e)return!1}}return!0}function G(e,r,t,n,u){let c=-1;for(;++c<e.length;){for(const n in e[c])Array.isArray(e[c][n])?(!t[c]&&(t[c]={}),t[c][n]=[],G(e[c][n],f(r[c]||{},n,[]),t[c][n],t[c],n)):!s(r)&&z(f(r[c]||{},n),e[c][n])?U(t[c]||{},n):t[c]=Object.assign(Object.assign({},t[c]),{[n]:!0});n&&!t.length&&delete n[u]}return t}var J=(e,r,t)=>function e(r,t){if(H(r)||H(t))return t;for(const n in t){const s=r[n],u=t[n];try{r[n]=c(s)&&c(u)||Array.isArray(s)&&Array.isArray(u)?e(s,u):u}catch(e){}}return r}(G(e,r,t.slice(0,e.length)),G(r,e,t.slice(0,e.length)));function K(e,r){return[...D(e),...D(r)]}var Q=e=>Array.isArray(e)?Array(e.length).fill(void 0):void 0;function X(e,r,t){return[...e.slice(0,r),...D(t),...e.slice(r)]}var Y=(e,r,t)=>Array.isArray(e)?(l(e[t])&&(e[t]=void 0),e.splice(t,0,e.splice(r,1)[0]),e):[];function Z(e,r){return[...D(r),...D(e)]}var ee=(e,r)=>l(r)?[]:function(e,r){let t=0;const n=[...e];for(const e of r)n.splice(e-t,1),t++;return o(n).length?n:[]}(e,D(r).sort((e,r)=>e-r)),re=(e,r,t)=>{e[r]=[e[t],e[t]=e[r]][0]},te=e=>"boolean"==typeof e;function ne(e,r){const t=I(r)?[r]:P(r),n=1==t.length?e:function(e,r){const t=r.slice(0,-1).length;let n=0;for(;n<t;)e=l(e)?n++:e[r[n++]];return e}(e,t),s=t[t.length-1];let u;n&&delete n[s];for(let r=0;r<t.slice(0,-1).length;r++){let n,s=-1;const a=t.slice(0,-(r+1)),i=a.length-1;for(r>0&&(u=e);++s<a.length;){const r=a[s];n=n?n[r]:e[r],i===s&&(c(n)&&R(n)||Array.isArray(n)&&!n.filter(e=>c(e)&&!R(e)||te(e)).length)&&(u?delete u[r]:delete e[r]),u=n}}return e}var se=e=>"file"===e.type,ue=e=>"select-multiple"===e.type,ce=e=>"radio"===e.type;const ae={value:!1,isValid:!1},ie={value:!0,isValid:!0};var oe=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:r,isValid:!!r.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!l(e[0].attributes.value)?l(e[0].value)||""===e[0].value?ie:{value:e[0].value,isValid:!0}:ie:ae}return ae},le=(e,{valueAsNumber:r,valueAsDate:t,setValueAs:n})=>l(e)?e:r?""===e?NaN:+e:t?new Date(e):n?n(e):e;const fe={isValid:!1,value:null};var de=e=>Array.isArray(e)?e.reduce((e,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:e,fe):fe;function ye(e){if(e&&e._f){const n=e._f.ref;if(n.disabled)return;return se(n)?n.files:ce(n)?de(e._f.refs).value:ue(n)?(r=n.options,[...r].filter(({selected:e})=>e).map(({value:e})=>e)):t(n)?oe(e._f.refs).value:le(l(n.value)?e._f.ref.value:n.value,e._f)}var r}var be=(e,r,t,n)=>{const s={};for(const t of e){const e=f(r,t);e&&U(s,t,e._f)}return{criteriaMode:t,names:[...e],fields:s,shouldUseNativeValidation:n}},ge=e=>"function"==typeof e,me=e=>"string"==typeof e,he=e=>me(e)||r.isValidElement(e),ve=e=>e instanceof RegExp;function pe(e,r,t="validate"){if(he(e)||Array.isArray(e)&&e.every(he)||te(e)&&!e)return{type:t,message:he(e)?e:"",ref:r}}var xe=e=>c(e)&&!ve(e)?e:{value:e,message:""},Oe=async({_f:{ref:e,refs:r,required:n,maxLength:u,minLength:a,min:i,max:o,pattern:l,validate:f,name:d,value:y,valueAsNumber:b,mount:g}},m,h)=>{if(!g)return{};const v=r?r[0]:e,k=e=>{h&&v.reportValidity&&(v.setCustomValidity(te(e)?"":e||" "),v.reportValidity())},F={},_=ce(e),C=t(e),S=_||C,D=(b||se(e))&&!e.value||""===y||Array.isArray(y)&&!y.length,E=T.bind(null,d,m,F),B=(r,t,n,s=O,u=w)=>{const c=r?t:n;F[d]=Object.assign({type:r?s:u,message:c,ref:e},E(r?s:u,c))};if(n&&(!S&&(D||s(y))||te(y)&&!y||C&&!oe(r).isValid||_&&!de(r).isValid)){const{value:e,message:r}=he(n)?{value:!!n,message:n}:xe(n);if(e&&(F[d]=Object.assign({type:V,message:r,ref:v},E(V,r)),!m))return k(r),F}if(!(D||s(i)&&s(o))){let r,t;const n=xe(o),u=xe(i);if(isNaN(y)){const s=e.valueAsDate||new Date(y);me(n.value)&&(r=s>new Date(n.value)),me(u.value)&&(t=s<new Date(u.value))}else{const c=e.valueAsNumber||parseFloat(y);s(n.value)||(r=c>n.value),s(u.value)||(t=c<u.value)}if((r||t)&&(B(!!r,n.message,u.message,p,x),!m))return k(F[d].message),F}if((u||a)&&!D&&me(y)){const e=xe(u),r=xe(a),t=!s(e.value)&&y.length>e.value,n=!s(r.value)&&y.length<r.value;if((t||n)&&(B(t,e.message,r.message),!m))return k(F[d].message),F}if(l&&!D&&me(y)){const{value:r,message:t}=xe(l);if(ve(r)&&!y.match(r)&&(F[d]=Object.assign({type:j,message:t,ref:e},E(j,t)),!m))return k(t),F}if(f)if(ge(f)){const e=pe(await f(y),v);if(e&&(F[d]=Object.assign(Object.assign({},e),E(A,e.message)),!m))return k(e.message),F}else if(c(f)){let e={};for(const r in f){if(!R(e)&&!m)break;const t=pe(await f[r](y),v,r);t&&(e=Object.assign(Object.assign({},t),E(r,t.message)),k(t.message),m&&(F[d]=e))}if(!R(e)&&(F[d]=Object.assign({ref:v},e),!m))return F}return k(!0),F},we=e=>({isOnSubmit:!e||e===m,isOnBlur:e===b,isOnChange:e===g,isOnAll:e===v,isOnTouch:e===h}),je=e=>e instanceof HTMLElement;class Ve{constructor(){this.tearDowns=[]}add(e){this.tearDowns.push(e)}unsubscribe(){for(const e of this.tearDowns)e();this.tearDowns=[]}}class Ae{constructor(e,r){this.observer=e,this.closed=!1,r.add(()=>this.closed=!0)}next(e){this.closed||this.observer.next(e)}}class ke{constructor(){this.observers=[]}next(e){for(const r of this.observers)r.next(e)}subscribe(e){const r=new Ve,t=new Ae(e,r);return this.observers.push(t),r}unsubscribe(){this.observers=[]}}const Fe="undefined"==typeof window;exports.Controller=e=>e.render(N(e)),exports.FormProvider=e=>r.createElement(F.Provider,{value:k(e,"children")},e.children),exports.appendErrors=T,exports.get=f,exports.set=U,exports.useController=N,exports.useFieldArray=({control:e,name:t,keyName:n="id",shouldUnregister:s})=>{const u=_(),c=r.useRef(""),i=r.useRef(!1),{getIsDirty:l,namesRef:d,fieldsRef:y,defaultValuesRef:b,formStateRef:g,subjectsRef:m,readFormStateRef:h,updateIsValid:v,fieldArrayDefaultValuesRef:p,unregister:x,shouldUnmount:O,inFieldArrayActionRef:w,setValues:j,register:V}=e||u.control,[A,F]=r.useState(q((f(y.current,t)&&i.current?f(L(y),t):f(p.current,a(t))?f(p.current,t):f(b.current,t))||[],n));U(p.current,t,[...A]),d.current.array.add(t);const C=e=>e.map((e={})=>k(e,n)),R=()=>{const e=f(L(y),t,[]);return q(f(p.current,t,[]).map((r,t)=>Object.assign(Object.assign({},r),e[t])),n)},S=(e,r)=>r&&!r.shouldFocus?r.focusName||`${t}.${r.focusIndex}.`:`${t}.${e}.`,E=(e=[])=>F(q(e,n)),B=e=>!o(f(e,t,[])).length&&ne(e,t),M=(e,r,n=[],s=!0)=>{if(w.current=!0,f(y.current,t)){const n=e(f(y.current,t),r.argA,r.argB);s&&U(y.current,t,n)}if(Array.isArray(f(g.current.errors,t))){const n=e(f(g.current.errors,t),r.argA,r.argB);s&&U(g.current.errors,t,n),B(g.current.errors)}if(h.current.touchedFields&&f(g.current.touchedFields,t)){const n=e(f(g.current.touchedFields,t),r.argA,r.argB);s&&U(g.current.touchedFields,t,n),B(g.current.touchedFields)}(h.current.dirtyFields||h.current.isDirty)&&(U(g.current.dirtyFields,t,J(C(n),f(b.current,t,[]),f(g.current.dirtyFields,t,[]))),n&&U(g.current.dirtyFields,t,J(C(n),f(b.current,t,[]),f(g.current.dirtyFields,t,[]))),B(g.current.dirtyFields)),m.current.state.next({dirtyFields:g.current.dirtyFields,isDirty:l(t,C(n)),errors:g.current.errors,isValid:g.current.isValid})},N=(e,r=0,n="")=>e.forEach((e,s)=>{const u=`${n||t}.${n?s:r+s}`;H(e)?V(u,{value:e}):Object.entries(e).forEach(([e,r])=>{const t=u+"."+e;Array.isArray(r)?N(r,s,t):V(t,{value:r})})});return r.useEffect(()=>{if(w.current=!1,d.current.watchAll)m.current.state.next({});else for(const e of d.current.watch)if(t.startsWith(e)){m.current.state.next({});break}m.current.watch.next({name:t,values:L(y)}),c.current&&$(y.current,e=>e.startsWith(c.current)),c.current="",m.current.array.next({name:t,values:C([...A])}),h.current.isValid&&v()},[A,t]),r.useEffect(()=>{const e=m.current.array.subscribe({next({name:e,values:r,isReset:n}){n&&(ne(y.current,e||t),e?U(p.current,e,r):p.current=r,E(f(p.current,t)))}});return!f(y.current,t)&&U(y.current,t,[]),i.current=!0,()=>{if(e.unsubscribe(),O||s)x(t),ne(p.current,t);else{const e=f(L(y),t);e&&U(p.current,t,e)}}},[]),{swap:r.useCallback((e,r)=>{const t=R();re(t,e,r),M(re,{argA:e,argB:r},t,!1),E(t)},[t]),move:r.useCallback((e,r)=>{const t=R();Y(t,e,r),E(t),M(Y,{argA:e,argB:r},t,!1)},[t]),prepend:r.useCallback((e,r)=>{const t=D(e),n=Z(R(),t);E(n),M(Z,{argA:Q(e)},n),N(t),c.current=S(0,r)},[t]),append:r.useCallback((e,r)=>{const t=D(e),n=K(R(),t),s=n.length-t.length;E(n),M(K,{argA:Q(e)},n,!1),N(t,s),c.current=S(s,r)},[t]),remove:r.useCallback(e=>{const r=ee(R(),e);E(r),M(ee,{argA:e},r)},[t]),insert:r.useCallback((e,r,t)=>{const n=D(r),s=X(R(),e,n);E(s),M(X,{argA:e,argB:Q(r)},s),N(n,e),c.current=S(e,t)},[t]),update:r.useCallback((e,r)=>{j(t+"."+e,r,{shouldValidate:!!h.current.isValid,shouldDirty:!(!h.current.dirtyFields&&!h.current.isDirty)});const n=R();n[e]=r,E(n)},[t]),fields:A}},exports.useForm=function({mode:e=m,reValidateMode:u=g,resolver:y,context:b,defaultValues:h={},shouldFocusError:p=!0,delayError:x,shouldUseNativeValidation:O,shouldUnregister:w,criteriaMode:j}={}){const[V,A]=r.useState({isDirty:!1,isValidating:!1,dirtyFields:{},isSubmitted:!1,submitCount:0,touchedFields:{},isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,errors:{}}),F=r.useRef({isDirty:!B,dirtyFields:!B,touchedFields:!B,isValidating:!B,isValid:!B,errors:!B}),_=r.useRef(y),M=r.useRef(V),N=r.useRef({}),T=r.useRef(h),I=r.useRef({}),P=r.useRef(b),W=r.useRef(!1),q=r.useRef(!1),G=r.useRef(),K=r.useRef({watch:new ke,control:new ke,array:new ke,state:new ke}),Q=r.useRef({mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1}),X=we(e),Y=j===v;_.current=y,P.current=b;const Z=e=>Q.current.watchAll||Q.current.watch.has(e)||Q.current.watch.has((e.match(/\w+/)||[])[0]),ee=(e,r)=>{U(M.current.errors,e,r),K.current.state.next({errors:M.current.errors})},re=r.useCallback(async(e,r,t,n,s,u)=>{const c=f(M.current.errors,r),a=!!F.current.isValid&&(y?s:(async()=>{const e=await de(N.current,!0);e!==M.current.isValid&&(M.current.isValid=e,K.current.state.next({isValid:e}))})());if(x&&t?(G.current=G.current||((e,r)=>{let t=0;return(...n)=>{clearTimeout(t),t=setTimeout(()=>e(...n),r)}})(ee,x),G.current(r,t)):t?U(M.current.errors,r,t):ne(M.current.errors,r),(u||(t?!z(c,t):c)||!R(n)||M.current.isValid!==a)&&!e){const e=Object.assign(Object.assign(Object.assign({},n),y?{isValid:!!a}:{}),{errors:M.current.errors,name:r});M.current=Object.assign(Object.assign({},M.current),e),K.current.state.next(u?{name:r}:e)}K.current.state.next({isValidating:!1})},[]),te=r.useCallback((e,r,n={},u,c)=>{c&&Se(e);const a=f(N.current,e);if(a){const c=a._f;if(c){const a=E&&je(c.ref)&&s(r)?"":r;if(c.value=le(r,c),ce(c.ref)?(c.refs||[]).forEach(e=>e.checked=e.value===a):se(c.ref)&&!me(a)?c.ref.files=a:ue(c.ref)?[...c.ref.options].forEach(e=>e.selected=a.includes(e.value)):t(c.ref)&&c.refs?c.refs.length>1?c.refs.forEach(e=>e.checked=Array.isArray(a)?!!a.find(r=>r===e.value):a===e.value):c.refs[0].checked=!!a:c.ref.value=a,u){const t=L(N);U(t,e,r),K.current.control.next({values:Object.assign(Object.assign({},T.current),t),name:e})}(n.shouldDirty||n.shouldTouch)&&ie(e,a,n.shouldTouch),n.shouldValidate&&he(e)}else a._f={ref:{name:e,value:r},value:r}}},[]),ae=r.useCallback((e,r)=>{const t=L(N);return e&&r&&U(t,e,r),!z(t,T.current)},[]),ie=r.useCallback((e,r,t,n=!0)=>{const s={name:e};let u=!1;if(F.current.isDirty){const e=M.current.isDirty;M.current.isDirty=ae(),s.isDirty=M.current.isDirty,u=e!==s.isDirty}if(F.current.dirtyFields&&!t){const t=f(M.current.dirtyFields,e);!z(f(T.current,e),r)?U(M.current.dirtyFields,e,!0):ne(M.current.dirtyFields,e),s.dirtyFields=M.current.dirtyFields,u=u||t!==f(M.current.dirtyFields,e)}const c=f(M.current.touchedFields,e);return t&&!c&&(U(M.current.touchedFields,e,t),s.touchedFields=M.current.touchedFields,u=u||F.current.touchedFields&&c!==t),u&&n&&K.current.state.next(s),u?s:{}},[]),oe=r.useCallback(async(e,r)=>{const t=(await Oe(f(N.current,e),Y,O))[e];return await re(r,e,t),l(t)},[Y]),fe=r.useCallback(async e=>{const{errors:r}=await _.current(L(N),P.current,be(Q.current.mount,N.current,j,O));if(e)for(const t of e){const e=f(r,t);e?U(M.current.errors,t,e):ne(M.current.errors,t)}else M.current.errors=r;return r},[j,O]),de=async(e,r,t={valid:!0})=>{for(const n in e){const s=e[n];if(s){const e=s._f,n=k(s,"_f");if(e){const n=await Oe(s,Y,O);if(r){if(n[e.name]){t.valid=!1;break}}else n[e.name]?U(M.current.errors,e.name,n[e.name]):ne(M.current.errors,e.name)}n&&await de(n,r,t)}}return t.valid},he=r.useCallback(async(e,r={})=>{const t=D(e);let n;if(K.current.state.next({isValidating:!0}),y){const r=await fe(l(e)?e:t);n=e?t.every(e=>!f(r,e)):R(r)}else e?n=(await Promise.all(t.filter(e=>f(N.current,e,{})._f).map(async e=>await oe(e,!0)))).every(Boolean):(await de(N.current),n=R(M.current.errors));return K.current.state.next(Object.assign(Object.assign({},me(e)?{name:e}:{}),{errors:M.current.errors,isValidating:!1})),r.shouldFocus&&!n&&$(N.current,e=>f(M.current.errors,e),e?t:Q.current.mount),F.current.isValid&&pe(),n},[fe,oe]),ve=(e,r,t)=>{const n=f(N.current,e);if(n){const s=l(n._f.value),u=s?l(f(I.current,e))?f(T.current,e):f(I.current,e):n._f.value;l(u)?s&&(n._f.value=ye(n)):r&&r.defaultChecked?n._f.value=ye(n):t?n._f.value=u:te(e,u)}q.current&&F.current.isValid&&pe()},pe=r.useCallback(async(e={})=>{const r=y?R((await _.current(Object.assign(Object.assign({},L(N)),e),P.current,be(Q.current.mount,N.current,j,O))).errors):await de(N.current,!0);r!==M.current.isValid&&(M.current.isValid=r,K.current.state.next({isValid:r}))},[j,O]),xe=r.useCallback((e,r,t)=>Object.entries(r).forEach(([r,s])=>{const u=`${e}.${r}`,c=f(N.current,u);!Q.current.array.has(e)&&H(s)&&(!c||c._f)||n(s)?te(u,s,t,!0,!c):xe(u,s,t)}),[he]),Ve=r.useCallback(async({type:e,target:r,target:{value:n,name:s,type:c}})=>{const i=f(N.current,s);if(i){let b=c?ye(i):void 0;b=l(b)?n:b;const g=e===d,{isOnBlur:m,isOnChange:h}=we(u),v=(o=i._f,!(i._f.mount&&o&&(o.required||o.min||o.max||o.maxLength||o.minLength||o.pattern||o.validate)||y||f(M.current.errors,s))||(({isOnBlur:e,isOnChange:r,isOnTouch:t,isTouched:n,isReValidateOnBlur:s,isReValidateOnChange:u,isBlurEvent:c,isSubmitted:a,isOnAll:i})=>!i&&(!a&&t?!(n||c):(a?s:e)?!c:!(a?u:r)||c))(Object.assign({isBlurEvent:g,isTouched:!!f(M.current.touchedFields,s),isSubmitted:M.current.isSubmitted,isReValidateOnBlur:m,isReValidateOnChange:h},X))),p=!g&&Z(s);l(b)||(i._f.value=b);const x=ie(s,i._f.value,g,!1),w=!R(x)||p;if(v)return!g&&K.current.watch.next({name:s,type:e,values:Ae()}),w&&K.current.state.next(p?{name:s}:Object.assign(Object.assign({},x),{name:s}));K.current.state.next({isValidating:!0}),(async(e,r,n,s)=>{let u,c,i=e.name;const o=f(N.current,i);if(y){const{errors:r}=await _.current(L(N),P.current,be([i],N.current,j,O));if(u=f(r,i),t(e)&&!u){const e=a(i),t=f(r,e,{});t.type&&t.message&&(u=t),(t||f(M.current.errors,e))&&(i=e)}c=R(r)}else u=(await Oe(o,Y,O))[i];!s&&K.current.watch.next({name:i,type:e.type,values:Ae()}),re(!1,i,u,r,c,n)})(r,x,p,g)}var o},[]),Ae=e=>{const r=Object.assign(Object.assign({},T.current),L(N));return l(e)?r:me(e)?f(r,e):e.map(e=>f(r,e))},_e=r.useCallback((e,r,t,n)=>{const s=Array.isArray(e),u=n||q.current?Object.assign(Object.assign({},T.current),n||L(N)):l(r)?T.current:s?r:{[e]:r};if(l(e))return t&&(Q.current.watchAll=!0),u;const c=[];for(const r of D(e))t&&Q.current.watch.add(r),c.push(f(u,r));return s?c:c[0]},[]),Ce=(e,r={})=>{for(const t of e?D(e):Q.current.mount)Q.current.mount.delete(t),Q.current.array.delete(t),f(N.current,t)&&(!r.keepError&&ne(M.current.errors,t),!r.keepValue&&ne(N.current,t),!r.keepDirty&&ne(M.current.dirtyFields,t),!r.keepTouched&&ne(M.current.touchedFields,t),!w&&!r.keepDefaultValue&&ne(T.current,t));K.current.watch.next({values:Ae()}),K.current.state.next(Object.assign(Object.assign({},M.current),r.keepDirty?{isDirty:ae()}:{})),!r.keepIsValid&&pe()},Re=(e,r,n)=>{Se(e,n);let s=f(N.current,e);const u=(e=>ce(e)||t(e))(r);r===s._f.ref||u&&o(s._f.refs||[]).find(e=>e===r)||(s={_f:u?Object.assign(Object.assign({},s._f),{refs:[...o(s._f.refs||[]).filter(e=>je(e)&&document.contains(e)),r],ref:{type:r.type,name:e}}):Object.assign(Object.assign({},s._f),{ref:r})},U(N.current,e,s),ve(e,r))},Se=r.useCallback((e,r={})=>{const t=f(N.current,e);return U(N.current,e,{_f:Object.assign(Object.assign(Object.assign({},t&&t._f?t._f:{ref:{name:e}}),{name:e,mount:!0}),r)}),Q.current.mount.add(e),!t&&ve(e,void 0,!0),Fe?{name:e}:{name:e,onChange:Ve,onBlur:Ve,ref:t=>{if(t)Re(e,t,r);else{const t=f(N.current,e,{}),n=w||r.shouldUnregister;t._f&&(t._f.mount=!1,l(t._f.value)&&(t._f.value=t._f.ref.value)),n&&(!i(Q.current.array,e)||!W.current)&&Q.current.unMount.add(e)}}}},[]),De=r.useCallback((e,r)=>async t=>{t&&(t.preventDefault&&t.preventDefault(),t.persist&&t.persist());let n=!0,s=L(N);K.current.state.next({isSubmitting:!0});try{if(y){const{errors:e,values:r}=await _.current(s,P.current,be(Q.current.mount,N.current,j,O));M.current.errors=e,s=r}else await de(N.current);R(M.current.errors)&&Object.keys(M.current.errors).every(e=>f(s,e))?(K.current.state.next({errors:{},isSubmitting:!0}),await e(s,t)):(r&&await r(M.current.errors,t),p&&$(N.current,e=>f(M.current.errors,e),Q.current.mount))}catch(e){throw n=!1,e}finally{M.current.isSubmitted=!0,K.current.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:R(M.current.errors)&&n,submitCount:M.current.submitCount+1,errors:M.current.errors})}},[p,Y,j,O]),Ee=(e,r="")=>{for(const t in e){const n=e[t],s=r+(r?".":"")+t,u=f(N.current,s);u&&u._f||(c(n)||Array.isArray(n)?Ee(n,s):u||Se(s,{value:n}))}};return r.useEffect(()=>{const e=K.current.state.subscribe({next(e){S(e,F.current,!0)&&(M.current=Object.assign(Object.assign({},M.current),e),A(M.current))}}),r=K.current.array.subscribe({next(e){if(e.values&&e.name&&F.current.isValid){const r=L(N);U(r,e.name,e.values),pe(r)}}});return()=>{e.unsubscribe(),r.unsubscribe()}},[]),r.useEffect(()=>{const e=[],r=e=>!je(e)||!document.contains(e);q.current||(q.current=!0,F.current.isValid&&pe(),!w&&Ee(T.current));for(const t of Q.current.unMount){const n=f(N.current,t);n&&(n._f.refs?n._f.refs.every(r):r(n._f.ref))&&e.push(t)}e.length&&Ce(e),Q.current.unMount=new Set}),{control:r.useMemo(()=>({register:Se,inFieldArrayActionRef:W,getIsDirty:ae,subjectsRef:K,watchInternal:_e,fieldsRef:N,updateIsValid:pe,namesRef:Q,readFormStateRef:F,formStateRef:M,defaultValuesRef:T,fieldArrayDefaultValuesRef:I,setValues:xe,unregister:Ce,shouldUnmount:w}),[]),formState:C(B,V,F),trigger:he,register:Se,handleSubmit:De,watch:r.useCallback((e,r)=>ge(e)?K.current.watch.subscribe({next:t=>e(_e(void 0,r),t)}):_e(e,r,!0),[]),setValue:r.useCallback((e,r,t={})=>{const n=f(N.current,e),u=Q.current.array.has(e);u&&(K.current.array.next({values:r,name:e,isReset:!0}),(F.current.isDirty||F.current.dirtyFields)&&t.shouldDirty&&(U(M.current.dirtyFields,e,J(r,f(T.current,e,[]),f(M.current.dirtyFields,e,[]))),K.current.state.next({name:e,dirtyFields:M.current.dirtyFields,isDirty:ae(e,r)})),!r.length&&U(N.current,e,[])&&U(I.current,e,[])),(n&&!n._f||u)&&!s(r)?xe(e,r,u?{}:t):te(e,r,t,!0,!n),Z(e)&&K.current.state.next({}),K.current.watch.next({name:e,values:Ae()})},[xe]),getValues:r.useCallback(Ae,[]),reset:r.useCallback((e,r={})=>{const t=e||T.current;if(E&&!r.keepValues)for(const e of Q.current.mount){const r=f(N.current,e);if(r&&r._f){const e=Array.isArray(r._f.refs)?r._f.refs[0]:r._f.ref;try{je(e)&&e.closest("form").reset();break}catch(e){}}}r.keepDefaultValues||(T.current=Object.assign({},t),I.current=Object.assign({},t)),r.keepValues||(N.current={},K.current.control.next({values:r.keepDefaultValues?T.current:Object.assign({},t)}),K.current.watch.next({values:Object.assign({},t)}),K.current.array.next({values:Object.assign({},t),isReset:!0})),Q.current={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1},K.current.state.next({submitCount:r.keepSubmitCount?M.current.submitCount:0,isDirty:r.keepDirty?M.current.isDirty:!!r.keepDefaultValues&&z(e,T.current),isSubmitted:!!r.keepIsSubmitted&&M.current.isSubmitted,dirtyFields:r.keepDirty?M.current.dirtyFields:{},touchedFields:r.keepTouched?M.current.touchedFields:{},errors:r.keepErrors?M.current.errors:{},isSubmitting:!1,isSubmitSuccessful:!1}),q.current=!!r.keepIsValid},[]),clearErrors:r.useCallback(e=>{e?D(e).forEach(e=>ne(M.current.errors,e)):M.current.errors={},K.current.state.next({errors:M.current.errors})},[]),unregister:r.useCallback(Ce,[]),setError:r.useCallback((e,r,t)=>{const n=((f(N.current,e)||{_f:{}})._f||{}).ref;U(M.current.errors,e,Object.assign(Object.assign({},r),{ref:n})),K.current.state.next({name:e,errors:M.current.errors,isValid:!1}),t&&t.shouldFocus&&n&&n.focus&&n.focus()},[]),setFocus:r.useCallback(e=>f(N.current,e)._f.ref.focus(),[])}},exports.useFormContext=_,exports.useFormState=M,exports.useWatch=function(e){const{control:t,name:n,defaultValue:s}=e||{},u=_(),c=r.useRef(n);c.current=n;const{watchInternal:a,subjectsRef:i}=t||u.control,[o,f]=r.useState(l(s)?a(n):s);return r.useEffect(()=>{a(n);const e=i.current.watch.subscribe({next:({name:e,values:r})=>(!c.current||!e||D(c.current).some(r=>e&&r&&(r.startsWith(e)||e.startsWith(r))))&&f(a(c.current,s,!1,r))});return()=>e.unsubscribe()},[]),o};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const n=e=>"object"==typeof e;var i=e=>!a(e)&&!Array.isArray(e)&&n(e)&&!s(e),u=e=>i(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,o=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>{const t=e.constructor&&e.constructor.prototype;return i(t)&&t.hasOwnProperty("isPrototypeOf")},c="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function d(e){let t;const r=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else{if(c&&(e instanceof Blob||e instanceof FileList)||!r&&!i(e))return e;if(t=r?[]:{},Array.isArray(e)||l(e))for(const r in e)t[r]=d(e[r]);else t=e}return t}var f=e=>Array.isArray(e)?e.filter(Boolean):[],m=e=>void 0===e,y=(e,t,r)=>{if(!t||!i(e))return r;const s=f(t.split(/[,[\].]+?/)).reduce(((e,t)=>a(e)?e:e[t]),e);return m(s)||s===e?m(e[t])?r:e[t]:s};const p={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},g={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},_="max",h="min",v="maxLength",b="minLength",x="pattern",A="required",V="validate",F=t.default.createContext(null),S=()=>t.default.useContext(F);var w=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const n in e)Object.defineProperty(a,n,{get:()=>{const a=n;return t._proxyFormState[a]!==g.all&&(t._proxyFormState[a]=!s||g.all),r&&(r[a]=!0),e[a]}});return a},k=e=>i(e)&&!Object.keys(e).length,D=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return k(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||g.all)))},C=e=>Array.isArray(e)?e:[e],O=(e,t,r)=>r&&t?e===t:!e||!t||e===t||C(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function j(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect((()=>{const t=!e.disabled&&r.current.subject&&r.current.subject.subscribe({next:r.current.next});return()=>{t&&t.unsubscribe()}}),[e.disabled])}function E(e){const r=S(),{control:s=r.control,disabled:a,name:n,exact:i}=e||{},[u,o]=t.default.useState(s._formState),l=t.default.useRef(!0),c=t.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=t.default.useRef(n);return d.current=n,j({disabled:a,next:e=>l.current&&O(d.current,e.name,i)&&D(e,c.current,s._updateFormState)&&o({...s._formState,...e}),subject:s._subjects.state}),t.default.useEffect((()=>(l.current=!0,c.current.isValid&&s._updateValid(!0),()=>{l.current=!1})),[s]),w(u,s,c.current,!1)}var U=e=>"string"==typeof e,B=(e,t,r,s,a)=>U(e)?(s&&t.watch.add(e),y(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),y(r,e)))):(s&&(t.watchAll=!0),r);function T(e){const r=S(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=t.default.useRef(a);o.current=a,j({disabled:i,subject:s._subjects.values,next:e=>{O(o.current,e.name,u)&&c(d(B(o.current,s._names,e.values||s._formValues,!1,n)))}});const[l,c]=t.default.useState(s._getWatch(a,n));return t.default.useEffect((()=>s._removeUnmounted())),l}var L=e=>/^\w*$/.test(e),N=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/));function M(e,t,r){let s=-1;const a=L(t)?[t]:N(t),n=a.length,u=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==u){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}function R(e){const r=S(),{name:s,control:a=r.control,shouldUnregister:n}=e,i=o(a._names.array,s),l=T({control:a,name:s,defaultValue:y(a._formValues,s,y(a._defaultValues,s,e.defaultValue)),exact:!0}),c=E({control:a,name:s}),f=t.default.useRef(a.register(s,{...e.rules,value:l}));return t.default.useEffect((()=>{const e=a._options.shouldUnregister||n,t=(e,t)=>{const r=y(a._fields,e);r&&(r._f.mount=t)};if(t(s,!0),e){const e=d(y(a._options.defaultValues,s));M(a._defaultValues,s,e),m(y(a._formValues,s))&&M(a._formValues,s,e)}return()=>{(i?e&&!a._state.action:e)?a.unregister(s):t(s,!1)}}),[s,a,i,n]),{field:{name:s,value:l,onChange:t.default.useCallback((e=>f.current.onChange({target:{value:u(e),name:s},type:p.CHANGE})),[s]),onBlur:t.default.useCallback((()=>f.current.onBlur({target:{value:y(a._formValues,s),name:s},type:p.BLUR})),[s,a]),ref:e=>{const t=y(a._fields,s);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:c,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!y(c.errors,s)},isDirty:{enumerable:!0,get:()=>!!y(c.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!y(c.touchedFields,s)},error:{enumerable:!0,get:()=>y(c.errors,s)}})}}var q=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{};const P=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=y(e,s);if(r){const{_f:e,...s}=r;if(e&&t(e.name)){if(e.ref.focus){e.ref.focus();break}if(e.refs&&e.refs[0].focus){e.refs[0].focus();break}}else i(s)&&P(s,t)}}};var W=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},$=(e,t,r={})=>r.shouldFocus||m(r.shouldFocus)?r.focusName||`${e}.${m(r.focusIndex)?t:r.focusIndex}.`:"",H=e=>({isOnSubmit:!e||e===g.onSubmit,isOnBlur:e===g.onBlur,isOnChange:e===g.onChange,isOnAll:e===g.all,isOnTouch:e===g.onTouched}),I=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length))))),G=(e,t,r)=>{const s=f(y(e,r));return M(s,"root",t[r]),M(e,r,s),e},z=e=>"boolean"==typeof e,J=e=>"file"===e.type,K=e=>"function"==typeof e,Q=e=>{if(!c)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},X=e=>U(e),Y=e=>"radio"===e.type,Z=e=>e instanceof RegExp;const ee={value:!1,isValid:!1},te={value:!0,isValid:!0};var re=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!m(e[0].attributes.value)?m(e[0].value)||""===e[0].value?te:{value:e[0].value,isValid:!0}:te:ee}return ee};const se={isValid:!1,value:null};var ae=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),se):se;function ne(e,t,r="validate"){if(X(e)||Array.isArray(e)&&e.every(X)||z(e)&&!e)return{type:r,message:X(e)?e:"",ref:t}}var ie=e=>i(e)&&!Z(e)?e:{value:e,message:""},ue=async(e,t,s,n,u)=>{const{ref:o,refs:l,required:c,maxLength:d,minLength:f,min:p,max:g,pattern:F,validate:S,name:w,valueAsNumber:D,mount:C,disabled:O}=e._f,j=y(t,w);if(!C||O)return{};const E=l?l[0]:o,B=e=>{n&&E.reportValidity&&(E.setCustomValidity(z(e)?"":e||""),E.reportValidity())},T={},L=Y(o),N=r(o),M=L||N,R=(D||J(o))&&m(o.value)&&m(j)||Q(o)&&""===o.value||""===j||Array.isArray(j)&&!j.length,P=q.bind(null,w,s,T),W=(e,t,r,s=v,a=b)=>{const n=e?t:r;T[w]={type:e?s:a,message:n,ref:o,...P(e?s:a,n)}};if(u?!Array.isArray(j)||!j.length:c&&(!M&&(R||a(j))||z(j)&&!j||N&&!re(l).isValid||L&&!ae(l).isValid)){const{value:e,message:t}=X(c)?{value:!!c,message:c}:ie(c);if(e&&(T[w]={type:A,message:t,ref:E,...P(A,t)},!s))return B(t),T}if(!(R||a(p)&&a(g))){let e,t;const r=ie(g),n=ie(p);if(a(j)||isNaN(j)){const s=o.valueAsDate||new Date(j),a=e=>new Date((new Date).toDateString()+" "+e),i="time"==o.type,u="week"==o.type;U(r.value)&&j&&(e=i?a(j)>a(r.value):u?j>r.value:s>new Date(r.value)),U(n.value)&&j&&(t=i?a(j)<a(n.value):u?j<n.value:s<new Date(n.value))}else{const s=o.valueAsNumber||(j?+j:j);a(r.value)||(e=s>r.value),a(n.value)||(t=s<n.value)}if((e||t)&&(W(!!e,r.message,n.message,_,h),!s))return B(T[w].message),T}if((d||f)&&!R&&(U(j)||u&&Array.isArray(j))){const e=ie(d),t=ie(f),r=!a(e.value)&&j.length>+e.value,n=!a(t.value)&&j.length<+t.value;if((r||n)&&(W(r,e.message,t.message),!s))return B(T[w].message),T}if(F&&!R&&U(j)){const{value:e,message:t}=ie(F);if(Z(e)&&!j.match(e)&&(T[w]={type:x,message:t,ref:o,...P(x,t)},!s))return B(t),T}if(S)if(K(S)){const e=ne(await S(j,t),E);if(e&&(T[w]={...e,...P(V,e.message)},!s))return B(e.message),T}else if(i(S)){let e={};for(const r in S){if(!k(e)&&!s)break;const a=ne(await S[r](j,t),E,r);a&&(e={...a,...P(r,a.message)},B(a.message),s&&(T[w]=e))}if(!k(e)&&(T[w]={ref:E,...e},!s))return T}return B(!0),T};function oe(e,t){return[...e,...C(t)]}var le=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ce(e,t,r){return[...e.slice(0,t),...C(r),...e.slice(t)]}var de=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function fe(e,t){return[...C(t),...C(e)]}var me=(e,t)=>m(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return f(s).length?s:[]}(e,C(t).sort(((e,t)=>e-t))),ye=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function pe(e,t){const r=Array.isArray(t)?t:L(t)?[t]:N(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=m(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(i(s)&&k(s)||Array.isArray(s)&&function(e){for(const t in e)if(!m(e[t]))return!1;return!0}(s))&&pe(e,r.slice(0,-1)),e}var ge=(e,t,r)=>(e[t]=r,e);function _e(){let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var he=e=>a(e)||!n(e);function ve(e,t){if(he(e)||he(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r){const r=e[n];if(!a.includes(n))return!1;if("ref"!==n){const e=t[n];if(s(r)&&s(e)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!ve(r,e):r!==e)return!1}}return!0}var be=e=>"select-multiple"===e.type,xe=e=>Y(e)||r(e),Ae=e=>Q(e)&&e.isConnected,Ve=e=>{for(const t in e)if(K(e[t]))return!0;return!1};function Fe(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!Ve(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Fe(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function Se(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!Ve(e[s])?m(t)||he(r[s])?r[s]=Array.isArray(e[s])?Fe(e[s],[]):{...Fe(e[s])}:Se(e[s],a(t)?{}:t[s],r[s]):r[s]=!ve(e[s],t[s]);return r}var we=(e,t)=>Se(e,t,Fe(t)),ke=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&U(e)?new Date(e):s?s(e):e;function De(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return J(t)?t.files:Y(t)?ae(e.refs).value:be(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?re(e.refs).value:ke(m(t.value)?e.ref.value:t.value,e)}var Ce=(e,t,r,s)=>{const a={};for(const r of e){const e=y(t,r);e&&M(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Oe=e=>m(e)?e:Z(e)?e.source:i(e)?Z(e.value)?e.value.source:e.value:e,je=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Ee(e,t,r){const s=y(e,r);if(s||L(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=y(t,s),i=y(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Ue=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Be=(e,t)=>!f(y(e,t)).length&&pe(e,t);const Te={mode:g.onSubmit,reValidateMode:g.onChange,shouldFocusError:!0};function Le(e={},t){let n,l={...Te,...e},_={submitCount:0,isDirty:!1,isLoading:K(l.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},h={},v=(i(l.defaultValues)||i(l.values))&&d(l.defaultValues||l.values)||{},b=l.shouldUnregister?{}:d(v),x={action:!1,mount:!1,watch:!1},A={mount:new Set,unMount:new Set,array:new Set,watch:new Set},V=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},S={values:_e(),array:_e(),state:_e()},w=e.resetOptions&&e.resetOptions.keepDirtyValues,D=H(l.mode),O=H(l.reValidateMode),j=l.criteriaMode===g.all,E=async e=>{if(F.isValid||e){const e=l.resolver?k((await q()).errors):await W(h,!0);e!==_.isValid&&S.state.next({isValid:e})}},T=e=>F.isValidating&&S.state.next({isValidating:e}),L=(e,t,r,s)=>{const a=y(h,e);if(a){const n=y(b,e,m(r)?y(v,e):r);m(n)||s&&s.defaultChecked||t?M(b,e,t?n:De(a._f)):Y(e,n),x.mount&&E()}},N=(e,t,r,s,a)=>{let n=!1,i=!1;const u={name:e};if(!r||s){F.isDirty&&(i=_.isDirty,_.isDirty=u.isDirty=$(),n=i!==u.isDirty);const r=ve(y(v,e),t);i=y(_.dirtyFields,e),r?pe(_.dirtyFields,e):M(_.dirtyFields,e,!0),u.dirtyFields=_.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=y(_.touchedFields,e);t||(M(_.touchedFields,e,r),u.touchedFields=_.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(u),n?u:{}},R=(t,r,s,a)=>{const i=y(_.errors,t),u=F.isValid&&z(r)&&_.isValid!==r;var o;if(e.delayError&&s?(o=()=>((e,t)=>{M(_.errors,e,t),S.state.next({errors:_.errors})})(t,s),n=e=>{clearTimeout(V),V=setTimeout(o,e)},n(e.delayError)):(clearTimeout(V),n=null,s?M(_.errors,t,s):pe(_.errors,t)),(s?!ve(i,s):i)||!k(a)||u){const e={...a,...u&&z(r)?{isValid:r}:{},errors:_.errors,name:t};_={..._,...e},S.state.next(e)}T(!1)},q=async e=>l.resolver(b,l.context,Ce(e||A.mount,h,l.criteriaMode,l.shouldUseNativeValidation)),W=async(e,t,r={valid:!0})=>{for(const s in e){const a=e[s];if(a){const{_f:e,...s}=a;if(e){const s=A.array.has(e.name),n=await ue(a,b,j,l.shouldUseNativeValidation&&!t,s);if(n[e.name]&&(r.valid=!1,t))break;!t&&(y(n,e.name)?s?G(_.errors,n,e.name):M(_.errors,e.name,n[e.name]):pe(_.errors,e.name))}s&&await W(s,t,r)}}return r.valid},$=(e,t)=>(e&&t&&M(b,e,t),!ve(se(),v)),X=(e,t,r)=>B(e,A,{...x.mount?b:m(t)?v:U(e)?{[e]:t}:t},r,t),Y=(e,t,s={})=>{const n=y(h,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&M(b,e,ke(t,s)),i=Q(s.ref)&&a(t)?"":t,be(s.ref)?[...s.ref.options].forEach((e=>e.selected=i.includes(e.value))):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(i)?!!i.find((t=>t===e.value)):i===e.value))):s.refs[0]&&(s.refs[0].checked=!!i):s.refs.forEach((e=>e.checked=e.value===i)):J(s.ref)?s.ref.value="":(s.ref.value=i,s.ref.type||S.values.next({name:e,values:{...b}})))}(s.shouldDirty||s.shouldTouch)&&N(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&re(e)},Z=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,u=y(h,i);!A.array.has(e)&&he(n)&&(!u||u._f)||s(n)?Y(i,n,r):Z(i,n,r)}},ee=(e,r,s={})=>{const n=y(h,e),i=A.array.has(e),u=d(r);M(b,e,u),i?(S.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:we(v,b),isDirty:$(e,u)})):!n||n._f||a(u)?Y(e,u,s):Z(e,u,s),I(e,A)&&S.state.next({..._}),S.values.next({name:e,values:{...b}}),!x.mount&&t()},te=async e=>{const t=e.target;let r=t.name,s=!0;const a=y(h,r);if(a){let i,o;const c=t.type?De(a._f):u(e),d=e.type===p.BLUR||e.type===p.FOCUS_OUT,f=!je(a._f)&&!l.resolver&&!y(_.errors,r)&&!a._f.deps||Ue(d,y(_.touchedFields,r),_.isSubmitted,O,D),m=I(r,A,d);M(b,r,c),d?(a._f.onBlur&&a._f.onBlur(e),n&&n(0)):a._f.onChange&&a._f.onChange(e);const g=N(r,c,d,!1),v=!k(g)||m;if(!d&&S.values.next({name:r,type:e.type,values:{...b}}),f)return F.isValid&&E(),v&&S.state.next({name:r,...m?{}:g});if(!d&&m&&S.state.next({..._}),T(!0),l.resolver){const{errors:e}=await q([r]),t=Ee(_.errors,h,r),s=Ee(e,h,t.name||r);i=s.error,r=s.name,o=k(e)}else i=(await ue(a,b,j,l.shouldUseNativeValidation))[r],s=isNaN(c)||c===y(b,r,c),s&&(i?o=!1:F.isValid&&(o=await W(h,!0)));s&&(a._f.deps&&re(a._f.deps),R(r,o,i,g))}},re=async(e,t={})=>{let r,s;const a=C(e);if(T(!0),l.resolver){const t=await(async e=>{const{errors:t}=await q();if(e)for(const r of e){const e=y(t,r);e?M(_.errors,r,e):pe(_.errors,r)}else _.errors=t;return t})(m(e)?e:a);r=k(t),s=e?!a.some((e=>y(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=y(h,e);return await W(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||_.isValid)&&E()):s=r=await W(h);return S.state.next({...!U(e)||F.isValid&&r!==_.isValid?{}:{name:e},...l.resolver||!e?{isValid:r}:{},errors:_.errors,isValidating:!1}),t.shouldFocus&&!s&&P(h,(e=>e&&y(_.errors,e)),e?a:A.mount),s},se=e=>{const t={...v,...x.mount?b:{}};return m(e)?t:U(e)?y(t,e):e.map((e=>y(t,e)))},ae=(e,t)=>({invalid:!!y((t||_).errors,e),isDirty:!!y((t||_).dirtyFields,e),isTouched:!!y((t||_).touchedFields,e),error:y((t||_).errors,e)}),ne=(e,t={})=>{for(const r of e?C(e):A.mount)A.mount.delete(r),A.array.delete(r),t.keepValue||(pe(h,r),pe(b,r)),!t.keepError&&pe(_.errors,r),!t.keepDirty&&pe(_.dirtyFields,r),!t.keepTouched&&pe(_.touchedFields,r),!l.shouldUnregister&&!t.keepDefaultValue&&pe(v,r);S.values.next({values:{...b}}),S.state.next({..._,...t.keepDirty?{isDirty:$()}:{}}),!t.keepIsValid&&E()},ie=(e,t={})=>{let r=y(h,e);const s=z(t.disabled);return M(h,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),A.mount.add(e),r?s&&M(b,e,t.disabled?void 0:y(b,e,De(r._f))):L(e,!0,t.value),{...s?{disabled:t.disabled}:{},...l.shouldUseNativeValidation?{required:!!t.required,min:Oe(t.min),max:Oe(t.max),minLength:Oe(t.minLength),maxLength:Oe(t.maxLength),pattern:Oe(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:s=>{if(s){ie(e,t),r=y(h,e);const a=m(s.value)&&s.querySelectorAll&&s.querySelectorAll("input,select,textarea")[0]||s,n=xe(a),i=r._f.refs||[];if(n?i.find((e=>e===a)):a===r._f.ref)return;M(h,e,{_f:{...r._f,...n?{refs:[...i.filter(Ae),a,...Array.isArray(y(v,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),L(e,!1,void 0,a)}else r=y(h,e,{}),r._f&&(r._f.mount=!1),(l.shouldUnregister||t.shouldUnregister)&&(!o(A.array,e)||!x.action)&&A.unMount.add(e)}}},oe=()=>l.shouldFocusError&&P(h,(e=>e&&y(_.errors,e)),A.mount),le=(r,s={})=>{const a=r||v,n=d(a),i=r&&!k(r)?n:v;if(s.keepDefaultValues||(v=a),!s.keepValues){if(s.keepDirtyValues||w)for(const e of A.mount)y(_.dirtyFields,e)?M(i,e,y(b,e)):ee(e,y(i,e));else{if(c&&m(r))for(const e of A.mount){const t=y(h,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Q(e)){const t=e.closest("form");if(t){t.reset();break}}}}h={}}b=e.shouldUnregister?s.keepDefaultValues?d(v):{}:n,S.array.next({values:{...i}}),S.values.next({values:{...i}})}A={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&t(),x.mount=!F.isValid||!!s.keepIsValid,x.watch=!!e.shouldUnregister,S.state.next({submitCount:s.keepSubmitCount?_.submitCount:0,isDirty:s.keepDirty?_.isDirty:!(!s.keepDefaultValues||ve(r,v)),isSubmitted:!!s.keepIsSubmitted&&_.isSubmitted,dirtyFields:s.keepDirtyValues?_.dirtyFields:s.keepDefaultValues&&r?we(v,r):{},touchedFields:s.keepTouched?_.touchedFields:{},errors:s.keepErrors?_.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},ce=(e,t)=>le(K(e)?e(b):e,t);return{control:{register:ie,unregister:ne,getFieldState:ae,_executeSchema:q,_getWatch:X,_getDirty:$,_updateValid:E,_removeUnmounted:()=>{for(const e of A.unMount){const t=y(h,e);t&&(t._f.refs?t._f.refs.every((e=>!Ae(e))):!Ae(t._f.ref))&&ne(e)}A.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(x.action=!0,n&&Array.isArray(y(h,e))){const t=r(y(h,e),s.argA,s.argB);a&&M(h,e,t)}if(n&&Array.isArray(y(_.errors,e))){const t=r(y(_.errors,e),s.argA,s.argB);a&&M(_.errors,e,t),Be(_.errors,e)}if(F.touchedFields&&n&&Array.isArray(y(_.touchedFields,e))){const t=r(y(_.touchedFields,e),s.argA,s.argB);a&&M(_.touchedFields,e,t)}F.dirtyFields&&(_.dirtyFields=we(v,b)),S.state.next({name:e,isDirty:$(e,t),dirtyFields:_.dirtyFields,errors:_.errors,isValid:_.isValid})}else M(b,e,t)},_getFieldArray:t=>f(y(x.mount?b:v,t,e.shouldUnregister?y(v,t,[]):[])),_reset:le,_resetDefaultValues:()=>K(l.defaultValues)&&l.defaultValues().then((e=>{ce(e,l.resetOptions),S.state.next({isLoading:!1})})),_updateFormState:e=>{_={..._,...e}},_subjects:S,_proxyFormState:F,get _fields(){return h},get _formValues(){return b},get _state(){return x},set _state(e){x=e},get _defaultValues(){return v},get _names(){return A},set _names(e){A=e},get _formState(){return _},set _formState(e){_=e},get _options(){return l},set _options(e){l={...l,...e}}},trigger:re,register:ie,handleSubmit:(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let s=d(b);if(S.state.next({isSubmitting:!0}),l.resolver){const{errors:e,values:t}=await q();_.errors=e,s=t}else await W(h);pe(_.errors,"root"),k(_.errors)?(S.state.next({errors:{}}),await e(s,r)):(t&&await t({..._.errors},r),oe(),setTimeout(oe)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:k(_.errors),submitCount:_.submitCount+1,errors:_.errors})},watch:(e,t)=>K(e)?S.values.subscribe({next:r=>e(X(void 0,t),r)}):X(e,t,!0),setValue:ee,getValues:se,reset:ce,resetField:(e,t={})=>{y(h,e)&&(m(t.defaultValue)?ee(e,y(v,e)):(ee(e,t.defaultValue),M(v,e,t.defaultValue)),t.keepTouched||pe(_.touchedFields,e),t.keepDirty||(pe(_.dirtyFields,e),_.isDirty=t.defaultValue?$(e,y(v,e)):$()),t.keepError||(pe(_.errors,e),F.isValid&&E()),S.state.next({..._}))},clearErrors:e=>{e&&C(e).forEach((e=>pe(_.errors,e))),S.state.next({errors:e?_.errors:{}})},unregister:ne,setError:(e,t,r)=>{const s=(y(h,e,{_f:{}})._f||{}).ref;M(_.errors,e,{...t,ref:s}),S.state.next({name:e,errors:_.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},setFocus:(e,t={})=>{const r=y(h,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ae}}exports.Controller=e=>e.render(R(e)),exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(F.Provider,{value:s},r)},exports.appendErrors=q,exports.get=y,exports.set=M,exports.useController=R,exports.useFieldArray=function(e){const r=S(),{control:s=r.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map(W)),c=t.default.useRef(u),f=t.default.useRef(a),m=t.default.useRef(!1);f.current=a,c.current=u,s._names.array.add(a),e.rules&&s.register(a,e.rules),j({next:({values:e,name:t})=>{if(t===f.current||!t){const t=y(e,f.current);Array.isArray(t)&&(o(t),l.current=t.map(W))}},subject:s._subjects.array});const p=t.default.useCallback((e=>{m.current=!0,s._updateFieldArray(a,e)}),[s,a]);return t.default.useEffect((()=>{if(s._state.action=!1,I(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!H(s._options.mode).isOnSubmit||s._formState.isSubmitted))if(s._options.resolver)s._executeSchema([a]).then((e=>{const t=y(e.errors,a),r=y(s._formState.errors,a);(r?!t&&r.type:t&&t.type)&&(t?M(s._formState.errors,a,t):pe(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=y(s._fields,a);e&&e._f&&ue(e,s._formValues,s._options.criteriaMode===g.all,s._options.shouldUseNativeValidation,!0).then((e=>!k(e)&&s._subjects.state.next({errors:G(s._formState.errors,e,a)})))}s._subjects.values.next({name:a,values:{...s._formValues}}),s._names.focus&&P(s._fields,(e=>!!e&&e.startsWith(s._names.focus||""))),s._names.focus="",s._updateValid()}),[u,a,s]),t.default.useEffect((()=>(!y(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||i)&&s.unregister(a)})),[a,s,n,i]),{swap:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);ye(r,e,t),ye(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,ye,{argA:e,argB:t},!1)}),[p,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);de(r,e,t),de(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,de,{argA:e,argB:t},!1)}),[p,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=fe(s._getFieldArray(a),r);s._names.focus=$(a,0,t),l.current=fe(l.current,r.map(W)),p(n),o(n),s._updateFieldArray(a,n,fe,{argA:le(e)})}),[p,a,s]),append:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=oe(s._getFieldArray(a),r);s._names.focus=$(a,n.length-1,t),l.current=oe(l.current,r.map(W)),p(n),o(n),s._updateFieldArray(a,n,oe,{argA:le(e)})}),[p,a,s]),remove:t.default.useCallback((e=>{const t=me(s._getFieldArray(a),e);l.current=me(l.current,e),p(t),o(t),s._updateFieldArray(a,t,me,{argA:e})}),[p,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=C(d(t)),i=ce(s._getFieldArray(a),e,n);s._names.focus=$(a,e,r),l.current=ce(l.current,e,n.map(W)),p(i),o(i),s._updateFieldArray(a,i,ce,{argA:e,argB:le(t)})}),[p,a,s]),update:t.default.useCallback(((e,t)=>{const r=d(t),n=ge(s._getFieldArray(a),e,r);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:W())),p(n),o([...n]),s._updateFieldArray(a,n,ge,{argA:e,argB:r},!0,!1)}),[p,a,s]),replace:t.default.useCallback((e=>{const t=C(d(e));l.current=t.map(W),p([...t]),o([...t]),s._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[p,a,s]),fields:t.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||W()})))),[u,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),[s,a]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:K(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:K(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Le(e,(()=>a((e=>({...e}))))),formState:s});const n=r.current.control;return n._options=e,j({subject:n._subjects.state,next:e=>{D(e,n._proxyFormState,n._updateFormState,!0)&&a({...n._formState})}}),t.default.useEffect((()=>{e.values&&!ve(e.values,n._defaultValues)?n._reset(e.values,n._options.resetOptions):n._resetDefaultValues()}),[e.values,n]),t.default.useEffect((()=>{n._state.mount||(n._updateValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()})),r.current.formState=w(s,n),r.current},exports.useFormContext=S,exports.useFormState=E,exports.useWatch=T;
//# sourceMappingURL=index.cjs.js.map

@@ -11,1 +11,2 @@ export * from './controller';

export * from './utils';
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookForm={},e.React)}(this,(function(e,r){"use strict";function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=t(r),s=e=>"checkbox"===e.type,u=e=>e instanceof Date,c=e=>null==e;const a=e=>"object"==typeof e;var i=e=>!c(e)&&!Array.isArray(e)&&a(e)&&!u(e),o=e=>e.substring(0,e.search(/.\d/))||e,l=(e,r)=>[...e].some(e=>o(r)===e),f=e=>e.filter(Boolean),d=e=>void 0===e,y=(e,r,t)=>{if(i(e)&&r){const n=f(r.split(/[,[\].]+?/)).reduce((e,r)=>c(e)?e:e[r],e);return d(n)||n===e?d(e[r])?t:e[r]:n}};const b="blur",g="change",m="onBlur",h="onChange",v="onSubmit",p="onTouched",x="all",O="max",w="min",j="maxLength",V="minLength",A="pattern",k="required",F="validate";var _=(e,r)=>{const t=Object.assign({},e);return delete t[r],t};const C=n.createContext(null);C.displayName="RHFContext";const R=()=>n.useContext(C);var S=(e,r,t,n,s=!0)=>e?new Proxy(r,{get:(e,r)=>{if(r in e)return t.current[r]!==x&&(t.current[r]=!s||x),n&&(n.current[r]=!0),e[r]}}):r,D=e=>i(e)&&!Object.keys(e).length,E=(e,r,t)=>{const n=_(e,"name");return D(n)||Object.keys(n).length>=Object.keys(r).length||Object.keys(n).find(e=>r[e]===(!t||x))},B=e=>Array.isArray(e)?e:[e],T="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;const M=T?"Proxy"in window:"undefined"!=typeof Proxy;function N(e){const{control:r,name:t}=e||{},s=R(),{formStateRef:u,subjectsRef:c,readFormStateRef:a}=r||s.control,i=n.useRef(t);i.current=t;const[o,l]=n.useState(u.current),f=n.useRef({isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1});return n.useEffect(()=>{const e=c.current.state.subscribe({next:e=>(!i.current||!e.name||B(i.current).includes(e.name))&&E(e,f.current)&&l(Object.assign(Object.assign({},u.current),e))});return()=>e.unsubscribe()},[]),S(M,o,a,f,!1)}function I({name:e,rules:r,defaultValue:t,control:u,shouldUnregister:c}){const a=R(),{defaultValuesRef:o,register:f,fieldsRef:m,unregister:h,namesRef:v,subjectsRef:p,shouldUnmount:x,inFieldArrayActionRef:O}=u||a.control,w=y(m.current,e),[j,V]=n.useState(w&&w._f&&!d(w._f.value)?w._f.value:d(y(o.current,e))?t:y(o.current,e)),{onChange:A,onBlur:k,ref:F}=f(e,Object.assign(Object.assign({},r),{value:j})),_=N({control:u||a.control,name:e});function C(e,r){const t=y(m.current,e);t&&t._f&&(t._f.mount=r)}return n.useEffect(()=>{const r=p.current.control.subscribe({next:r=>(!r.name||e===r.name)&&V(y(r.values,e))});return C(e,!0),()=>{r.unsubscribe();const t=x||c;(l(v.current.array,e)?t&&!O.current:t)?h(e):C(e,!1)}},[e]),{field:{onChange:r=>{const t=(e=>i(e)&&e.target?s(e.target)?e.target.checked:e.target.value:e)(r);V(t),A({target:{value:t,name:e},type:g})},onBlur:()=>{k({target:{name:e},type:b})},name:e,value:j,ref:e=>e&&F({focus:()=>e.focus&&e.focus(),setCustomValidity:r=>e.setCustomValidity(r),reportValidity:()=>e.reportValidity()})},formState:_,fieldState:{invalid:!!y(_.errors,e),isDirty:!!y(_.dirtyFields,e),isTouched:!!y(_.touchedFields,e),error:y(_.errors,e)}}}var P=(e,r,t,n,s)=>r?Object.assign(Object.assign({},t[e]),{types:Object.assign(Object.assign({},t[e]&&t[e].types?t[e].types:{}),{[n]:s||!0})}):{},U=e=>/^\w*$/.test(e),$=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/));function L(e,r,t){let n=-1;const s=U(r)?[r]:$(r),u=s.length,c=u-1;for(;++n<u;){const r=s[n];let u=t;if(n!==c){const t=e[r];u=i(t)||Array.isArray(t)?t:isNaN(+s[n+1])?{}:[]}e[r]=u,e=e[r]}return e}const W=(e,r,t)=>{for(const n of t||Object.keys(e)){const t=y(e,n);if(t){const e=t._f,n=_(t,"_f");if(e&&r(e.name)){if(e.ref.focus&&d(e.ref.focus()))break;if(e.refs){e.refs[0].focus();break}}else i(n)&&W(n,r)}}},q=(e,r={})=>{for(const t in e.current){const n=e.current[t];if(n&&!c(r)){const e=n._f,s=_(n,"_f");L(r,t,e&&e.ref?e.ref.disabled||e.refs&&e.refs.every(e=>e.disabled)?void 0:e.value:Array.isArray(n)?[]:{}),s&&q({current:s},r[t])}}return r};var H=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{const t=(16*Math.random()+e)%16|0;return("x"==r?t:3&t|8).toString(16)})},z=(e=[],r)=>e.map(e=>Object.assign({[r]:e&&e[r]||H()},e)),G=e=>c(e)||!a(e);function J(e,r){if(G(e)||G(r)||u(e)||u(r))return e===r;const t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(const s of t){const t=e[s];if(!n.includes(s))return!1;if("ref"!==s){const e=r[s];if((i(t)||Array.isArray(t))&&(i(e)||Array.isArray(e))?!J(t,e):t!==e)return!1}}return!0}function K(e,r,t,n,s){let u=-1;for(;++u<e.length;){for(const n in e[u])Array.isArray(e[u][n])?(!t[u]&&(t[u]={}),t[u][n]=[],K(e[u][n],y(r[u]||{},n,[]),t[u][n],t[u],n)):!c(r)&&J(y(r[u]||{},n),e[u][n])?L(t[u]||{},n):t[u]=Object.assign(Object.assign({},t[u]),{[n]:!0});n&&!t.length&&delete n[s]}return t}var Q=(e,r,t)=>function e(r,t){if(G(r)||G(t))return t;for(const n in t){const s=r[n],u=t[n];try{r[n]=i(s)&&i(u)||Array.isArray(s)&&Array.isArray(u)?e(s,u):u}catch(e){}}return r}(K(e,r,t.slice(0,e.length)),K(r,e,t.slice(0,e.length)));function X(e,r){return[...B(e),...B(r)]}var Y=e=>Array.isArray(e)?Array(e.length).fill(void 0):void 0;function Z(e,r,t){return[...e.slice(0,r),...B(t),...e.slice(r)]}var ee=(e,r,t)=>Array.isArray(e)?(d(e[t])&&(e[t]=void 0),e.splice(t,0,e.splice(r,1)[0]),e):[];function re(e,r){return[...B(r),...B(e)]}var te=(e,r)=>d(r)?[]:function(e,r){let t=0;const n=[...e];for(const e of r)n.splice(e-t,1),t++;return f(n).length?n:[]}(e,B(r).sort((e,r)=>e-r)),ne=(e,r,t)=>{e[r]=[e[t],e[t]=e[r]][0]},se=e=>"boolean"==typeof e;function ue(e,r){const t=U(r)?[r]:$(r),n=1==t.length?e:function(e,r){const t=r.slice(0,-1).length;let n=0;for(;n<t;)e=d(e)?n++:e[r[n++]];return e}(e,t),s=t[t.length-1];let u;n&&delete n[s];for(let r=0;r<t.slice(0,-1).length;r++){let n,s=-1;const c=t.slice(0,-(r+1)),a=c.length-1;for(r>0&&(u=e);++s<c.length;){const r=c[s];n=n?n[r]:e[r],a===s&&(i(n)&&D(n)||Array.isArray(n)&&!n.filter(e=>i(e)&&!D(e)||se(e)).length)&&(u?delete u[r]:delete e[r]),u=n}}return e}var ce=e=>"file"===e.type,ae=e=>"select-multiple"===e.type,ie=e=>"radio"===e.type;const oe={value:!1,isValid:!1},le={value:!0,isValid:!0};var fe=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:r,isValid:!!r.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!d(e[0].attributes.value)?d(e[0].value)||""===e[0].value?le:{value:e[0].value,isValid:!0}:le:oe}return oe},de=(e,{valueAsNumber:r,valueAsDate:t,setValueAs:n})=>d(e)?e:r?""===e?NaN:+e:t?new Date(e):n?n(e):e;const ye={isValid:!1,value:null};var be=e=>Array.isArray(e)?e.reduce((e,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:e,ye):ye;function ge(e){if(e&&e._f){const t=e._f.ref;if(t.disabled)return;return ce(t)?t.files:ie(t)?be(e._f.refs).value:ae(t)?(r=t.options,[...r].filter(({selected:e})=>e).map(({value:e})=>e)):s(t)?fe(e._f.refs).value:de(d(t.value)?e._f.ref.value:t.value,e._f)}var r}var me=(e,r,t,n)=>{const s={};for(const t of e){const e=y(r,t);e&&L(s,t,e._f)}return{criteriaMode:t,names:[...e],fields:s,shouldUseNativeValidation:n}},he=e=>"function"==typeof e,ve=e=>"string"==typeof e,pe=e=>ve(e)||n.isValidElement(e),xe=e=>e instanceof RegExp;function Oe(e,r,t="validate"){if(pe(e)||Array.isArray(e)&&e.every(pe)||se(e)&&!e)return{type:t,message:pe(e)?e:"",ref:r}}var we=e=>i(e)&&!xe(e)?e:{value:e,message:""},je=async({_f:{ref:e,refs:r,required:t,maxLength:n,minLength:u,min:a,max:o,pattern:l,validate:f,name:d,value:y,valueAsNumber:b,mount:g}},m,h)=>{if(!g)return{};const v=r?r[0]:e,p=e=>{h&&v.reportValidity&&(v.setCustomValidity(se(e)?"":e||" "),v.reportValidity())},x={},_=ie(e),C=s(e),R=_||C,S=(b||ce(e))&&!e.value||""===y||Array.isArray(y)&&!y.length,E=P.bind(null,d,m,x),B=(r,t,n,s=j,u=V)=>{const c=r?t:n;x[d]=Object.assign({type:r?s:u,message:c,ref:e},E(r?s:u,c))};if(t&&(!R&&(S||c(y))||se(y)&&!y||C&&!fe(r).isValid||_&&!be(r).isValid)){const{value:e,message:r}=pe(t)?{value:!!t,message:t}:we(t);if(e&&(x[d]=Object.assign({type:k,message:r,ref:v},E(k,r)),!m))return p(r),x}if(!(S||c(a)&&c(o))){let r,t;const n=we(o),s=we(a);if(isNaN(y)){const u=e.valueAsDate||new Date(y);ve(n.value)&&(r=u>new Date(n.value)),ve(s.value)&&(t=u<new Date(s.value))}else{const u=e.valueAsNumber||parseFloat(y);c(n.value)||(r=u>n.value),c(s.value)||(t=u<s.value)}if((r||t)&&(B(!!r,n.message,s.message,O,w),!m))return p(x[d].message),x}if((n||u)&&!S&&ve(y)){const e=we(n),r=we(u),t=!c(e.value)&&y.length>e.value,s=!c(r.value)&&y.length<r.value;if((t||s)&&(B(t,e.message,r.message),!m))return p(x[d].message),x}if(l&&!S&&ve(y)){const{value:r,message:t}=we(l);if(xe(r)&&!y.match(r)&&(x[d]=Object.assign({type:A,message:t,ref:e},E(A,t)),!m))return p(t),x}if(f)if(he(f)){const e=Oe(await f(y),v);if(e&&(x[d]=Object.assign(Object.assign({},e),E(F,e.message)),!m))return p(e.message),x}else if(i(f)){let e={};for(const r in f){if(!D(e)&&!m)break;const t=Oe(await f[r](y),v,r);t&&(e=Object.assign(Object.assign({},t),E(r,t.message)),p(t.message),m&&(x[d]=e))}if(!D(e)&&(x[d]=Object.assign({ref:v},e),!m))return x}return p(!0),x},Ve=e=>({isOnSubmit:!e||e===v,isOnBlur:e===m,isOnChange:e===h,isOnAll:e===x,isOnTouch:e===p}),Ae=e=>e instanceof HTMLElement;class ke{constructor(){this.tearDowns=[]}add(e){this.tearDowns.push(e)}unsubscribe(){for(const e of this.tearDowns)e();this.tearDowns=[]}}class Fe{constructor(e,r){this.observer=e,this.closed=!1,r.add(()=>this.closed=!0)}next(e){this.closed||this.observer.next(e)}}class _e{constructor(){this.observers=[]}next(e){for(const r of this.observers)r.next(e)}subscribe(e){const r=new ke,t=new Fe(e,r);return this.observers.push(t),r}unsubscribe(){this.observers=[]}}const Ce="undefined"==typeof window;e.Controller=e=>e.render(I(e)),e.FormProvider=e=>n.createElement(C.Provider,{value:_(e,"children")},e.children),e.appendErrors=P,e.get=y,e.set=L,e.useController=I,e.useFieldArray=({control:e,name:r,keyName:t="id",shouldUnregister:s})=>{const u=R(),c=n.useRef(""),a=n.useRef(!1),{getIsDirty:i,namesRef:l,fieldsRef:d,defaultValuesRef:b,formStateRef:g,subjectsRef:m,readFormStateRef:h,updateIsValid:v,fieldArrayDefaultValuesRef:p,unregister:x,shouldUnmount:O,inFieldArrayActionRef:w,setValues:j,register:V}=e||u.control,[A,k]=n.useState(z((y(d.current,r)&&a.current?y(q(d),r):y(p.current,o(r))?y(p.current,r):y(b.current,r))||[],t));L(p.current,r,[...A]),l.current.array.add(r);const F=e=>e.map((e={})=>_(e,t)),C=()=>{const e=y(q(d),r,[]);return z(y(p.current,r,[]).map((r,t)=>Object.assign(Object.assign({},r),e[t])),t)},S=(e,t)=>t&&!t.shouldFocus?t.focusName||`${r}.${t.focusIndex}.`:`${r}.${e}.`,D=(e=[])=>k(z(e,t)),E=e=>!f(y(e,r,[])).length&&ue(e,r),T=(e,t,n=[],s=!0)=>{if(w.current=!0,y(d.current,r)){const n=e(y(d.current,r),t.argA,t.argB);s&&L(d.current,r,n)}if(Array.isArray(y(g.current.errors,r))){const n=e(y(g.current.errors,r),t.argA,t.argB);s&&L(g.current.errors,r,n),E(g.current.errors)}if(h.current.touchedFields&&y(g.current.touchedFields,r)){const n=e(y(g.current.touchedFields,r),t.argA,t.argB);s&&L(g.current.touchedFields,r,n),E(g.current.touchedFields)}(h.current.dirtyFields||h.current.isDirty)&&(L(g.current.dirtyFields,r,Q(F(n),y(b.current,r,[]),y(g.current.dirtyFields,r,[]))),n&&L(g.current.dirtyFields,r,Q(F(n),y(b.current,r,[]),y(g.current.dirtyFields,r,[]))),E(g.current.dirtyFields)),m.current.state.next({dirtyFields:g.current.dirtyFields,isDirty:i(r,F(n)),errors:g.current.errors,isValid:g.current.isValid})},M=(e,t=0,n="")=>e.forEach((e,s)=>{const u=`${n||r}.${n?s:t+s}`;G(e)?V(u,{value:e}):Object.entries(e).forEach(([e,r])=>{const t=u+"."+e;Array.isArray(r)?M(r,s,t):V(t,{value:r})})});return n.useEffect(()=>{if(w.current=!1,l.current.watchAll)m.current.state.next({});else for(const e of l.current.watch)if(r.startsWith(e)){m.current.state.next({});break}m.current.watch.next({name:r,values:q(d)}),c.current&&W(d.current,e=>e.startsWith(c.current)),c.current="",m.current.array.next({name:r,values:F([...A])}),h.current.isValid&&v()},[A,r]),n.useEffect(()=>{const e=m.current.array.subscribe({next({name:e,values:t,isReset:n}){n&&(ue(d.current,e||r),e?L(p.current,e,t):p.current=t,D(y(p.current,r)))}});return!y(d.current,r)&&L(d.current,r,[]),a.current=!0,()=>{if(e.unsubscribe(),O||s)x(r),ue(p.current,r);else{const e=y(q(d),r);e&&L(p.current,r,e)}}},[]),{swap:n.useCallback((e,r)=>{const t=C();ne(t,e,r),T(ne,{argA:e,argB:r},t,!1),D(t)},[r]),move:n.useCallback((e,r)=>{const t=C();ee(t,e,r),D(t),T(ee,{argA:e,argB:r},t,!1)},[r]),prepend:n.useCallback((e,r)=>{const t=B(e),n=re(C(),t);D(n),T(re,{argA:Y(e)},n),M(t),c.current=S(0,r)},[r]),append:n.useCallback((e,r)=>{const t=B(e),n=X(C(),t),s=n.length-t.length;D(n),T(X,{argA:Y(e)},n,!1),M(t,s),c.current=S(s,r)},[r]),remove:n.useCallback(e=>{const r=te(C(),e);D(r),T(te,{argA:e},r)},[r]),insert:n.useCallback((e,r,t)=>{const n=B(r),s=Z(C(),e,n);D(s),T(Z,{argA:e,argB:Y(r)},s),M(n,e),c.current=S(e,t)},[r]),update:n.useCallback((e,t)=>{j(r+"."+e,t,{shouldValidate:!!h.current.isValid,shouldDirty:!(!h.current.dirtyFields&&!h.current.isDirty)});const n=C();n[e]=t,D(n)},[r]),fields:A}},e.useForm=function({mode:e=v,reValidateMode:r=h,resolver:t,context:a,defaultValues:g={},shouldFocusError:m=!0,delayError:p,shouldUseNativeValidation:O,shouldUnregister:w,criteriaMode:j}={}){const[V,A]=n.useState({isDirty:!1,isValidating:!1,dirtyFields:{},isSubmitted:!1,submitCount:0,touchedFields:{},isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,errors:{}}),k=n.useRef({isDirty:!M,dirtyFields:!M,touchedFields:!M,isValidating:!M,isValid:!M,errors:!M}),F=n.useRef(t),C=n.useRef(V),R=n.useRef({}),N=n.useRef(g),I=n.useRef({}),P=n.useRef(a),U=n.useRef(!1),$=n.useRef(!1),H=n.useRef(),z=n.useRef({watch:new _e,control:new _e,array:new _e,state:new _e}),K=n.useRef({mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1}),X=Ve(e),Y=j===x;F.current=t,P.current=a;const Z=e=>K.current.watchAll||K.current.watch.has(e)||K.current.watch.has((e.match(/\w+/)||[])[0]),ee=(e,r)=>{L(C.current.errors,e,r),z.current.state.next({errors:C.current.errors})},re=n.useCallback(async(e,r,n,s,u,c)=>{const a=y(C.current.errors,r),i=!!k.current.isValid&&(t?u:(async()=>{const e=await fe(R.current,!0);e!==C.current.isValid&&(C.current.isValid=e,z.current.state.next({isValid:e}))})());if(p&&n?(H.current=H.current||((e,r)=>{let t=0;return(...n)=>{clearTimeout(t),t=setTimeout(()=>e(...n),r)}})(ee,p),H.current(r,n)):n?L(C.current.errors,r,n):ue(C.current.errors,r),(c||(n?!J(a,n):a)||!D(s)||C.current.isValid!==i)&&!e){const e=Object.assign(Object.assign(Object.assign({},s),t?{isValid:!!i}:{}),{errors:C.current.errors,name:r});C.current=Object.assign(Object.assign({},C.current),e),z.current.state.next(c?{name:r}:e)}z.current.state.next({isValidating:!1})},[]),te=n.useCallback((e,r,t={},n,u)=>{u&&Se(e);const a=y(R.current,e);if(a){const u=a._f;if(u){const a=T&&Ae(u.ref)&&c(r)?"":r;if(u.value=de(r,u),ie(u.ref)?(u.refs||[]).forEach(e=>e.checked=e.value===a):ce(u.ref)&&!ve(a)?u.ref.files=a:ae(u.ref)?[...u.ref.options].forEach(e=>e.selected=a.includes(e.value)):s(u.ref)&&u.refs?u.refs.length>1?u.refs.forEach(e=>e.checked=Array.isArray(a)?!!a.find(r=>r===e.value):a===e.value):u.refs[0].checked=!!a:u.ref.value=a,n){const t=q(R);L(t,e,r),z.current.control.next({values:Object.assign(Object.assign({},N.current),t),name:e})}(t.shouldDirty||t.shouldTouch)&&se(e,a,t.shouldTouch),t.shouldValidate&&ye(e)}else a._f={ref:{name:e,value:r},value:r}}},[]),ne=n.useCallback((e,r)=>{const t=q(R);return e&&r&&L(t,e,r),!J(t,N.current)},[]),se=n.useCallback((e,r,t,n=!0)=>{const s={name:e};let u=!1;if(k.current.isDirty){const e=C.current.isDirty;C.current.isDirty=ne(),s.isDirty=C.current.isDirty,u=e!==s.isDirty}if(k.current.dirtyFields&&!t){const t=y(C.current.dirtyFields,e);!J(y(N.current,e),r)?L(C.current.dirtyFields,e,!0):ue(C.current.dirtyFields,e),s.dirtyFields=C.current.dirtyFields,u=u||t!==y(C.current.dirtyFields,e)}const c=y(C.current.touchedFields,e);return t&&!c&&(L(C.current.touchedFields,e,t),s.touchedFields=C.current.touchedFields,u=u||k.current.touchedFields&&c!==t),u&&n&&z.current.state.next(s),u?s:{}},[]),oe=n.useCallback(async(e,r)=>{const t=(await je(y(R.current,e),Y,O))[e];return await re(r,e,t),d(t)},[Y]),le=n.useCallback(async e=>{const{errors:r}=await F.current(q(R),P.current,me(K.current.mount,R.current,j,O));if(e)for(const t of e){const e=y(r,t);e?L(C.current.errors,t,e):ue(C.current.errors,t)}else C.current.errors=r;return r},[j,O]),fe=async(e,r,t={valid:!0})=>{for(const n in e){const s=e[n];if(s){const e=s._f,n=_(s,"_f");if(e){const n=await je(s,Y,O);if(r){if(n[e.name]){t.valid=!1;break}}else n[e.name]?L(C.current.errors,e.name,n[e.name]):ue(C.current.errors,e.name)}n&&await fe(n,r,t)}}return t.valid},ye=n.useCallback(async(e,r={})=>{const n=B(e);let s;if(z.current.state.next({isValidating:!0}),t){const r=await le(d(e)?e:n);s=e?n.every(e=>!y(r,e)):D(r)}else e?s=(await Promise.all(n.filter(e=>y(R.current,e,{})._f).map(async e=>await oe(e,!0)))).every(Boolean):(await fe(R.current),s=D(C.current.errors));return z.current.state.next(Object.assign(Object.assign({},ve(e)?{name:e}:{}),{errors:C.current.errors,isValidating:!1})),r.shouldFocus&&!s&&W(R.current,e=>y(C.current.errors,e),e?n:K.current.mount),k.current.isValid&&pe(),s},[le,oe]),be=(e,r,t)=>{const n=y(R.current,e);if(n){const s=d(n._f.value),u=s?d(y(I.current,e))?y(N.current,e):y(I.current,e):n._f.value;d(u)?s&&(n._f.value=ge(n)):r&&r.defaultChecked?n._f.value=ge(n):t?n._f.value=u:te(e,u)}$.current&&k.current.isValid&&pe()},pe=n.useCallback(async(e={})=>{const r=t?D((await F.current(Object.assign(Object.assign({},q(R)),e),P.current,me(K.current.mount,R.current,j,O))).errors):await fe(R.current,!0);r!==C.current.isValid&&(C.current.isValid=r,z.current.state.next({isValid:r}))},[j,O]),xe=n.useCallback((e,r,t)=>Object.entries(r).forEach(([r,n])=>{const s=`${e}.${r}`,c=y(R.current,s);!K.current.array.has(e)&&G(n)&&(!c||c._f)||u(n)?te(s,n,t,!0,!c):xe(s,n,t)}),[ye]),Oe=n.useCallback(async({type:e,target:n,target:{value:u,name:c,type:a}})=>{const i=y(R.current,c);if(i){let f=a?ge(i):void 0;f=d(f)?u:f;const g=e===b,{isOnBlur:m,isOnChange:h}=Ve(r),v=(l=i._f,!(i._f.mount&&l&&(l.required||l.min||l.max||l.maxLength||l.minLength||l.pattern||l.validate)||t||y(C.current.errors,c))||(({isOnBlur:e,isOnChange:r,isOnTouch:t,isTouched:n,isReValidateOnBlur:s,isReValidateOnChange:u,isBlurEvent:c,isSubmitted:a,isOnAll:i})=>!i&&(!a&&t?!(n||c):(a?s:e)?!c:!(a?u:r)||c))(Object.assign({isBlurEvent:g,isTouched:!!y(C.current.touchedFields,c),isSubmitted:C.current.isSubmitted,isReValidateOnBlur:m,isReValidateOnChange:h},X))),p=!g&&Z(c);d(f)||(i._f.value=f);const x=se(c,i._f.value,g,!1),w=!D(x)||p;if(v)return!g&&z.current.watch.next({name:c,type:e,values:we()}),w&&z.current.state.next(p?{name:c}:Object.assign(Object.assign({},x),{name:c}));z.current.state.next({isValidating:!0}),(async(e,r,n,u)=>{let c,a,i=e.name;const l=y(R.current,i);if(t){const{errors:r}=await F.current(q(R),P.current,me([i],R.current,j,O));if(c=y(r,i),s(e)&&!c){const e=o(i),t=y(r,e,{});t.type&&t.message&&(c=t),(t||y(C.current.errors,e))&&(i=e)}a=D(r)}else c=(await je(l,Y,O))[i];!u&&z.current.watch.next({name:i,type:e.type,values:we()}),re(!1,i,c,r,a,n)})(n,x,p,g)}var l},[]),we=e=>{const r=Object.assign(Object.assign({},N.current),q(R));return d(e)?r:ve(e)?y(r,e):e.map(e=>y(r,e))},ke=n.useCallback((e,r,t,n)=>{const s=Array.isArray(e),u=n||$.current?Object.assign(Object.assign({},N.current),n||q(R)):d(r)?N.current:s?r:{[e]:r};if(d(e))return t&&(K.current.watchAll=!0),u;const c=[];for(const r of B(e))t&&K.current.watch.add(r),c.push(y(u,r));return s?c:c[0]},[]),Fe=(e,r={})=>{for(const t of e?B(e):K.current.mount)K.current.mount.delete(t),K.current.array.delete(t),y(R.current,t)&&(!r.keepError&&ue(C.current.errors,t),!r.keepValue&&ue(R.current,t),!r.keepDirty&&ue(C.current.dirtyFields,t),!r.keepTouched&&ue(C.current.touchedFields,t),!w&&!r.keepDefaultValue&&ue(N.current,t));z.current.watch.next({values:we()}),z.current.state.next(Object.assign(Object.assign({},C.current),r.keepDirty?{isDirty:ne()}:{})),!r.keepIsValid&&pe()},Re=(e,r,t)=>{Se(e,t);let n=y(R.current,e);const u=(e=>ie(e)||s(e))(r);r===n._f.ref||u&&f(n._f.refs||[]).find(e=>e===r)||(n={_f:u?Object.assign(Object.assign({},n._f),{refs:[...f(n._f.refs||[]).filter(e=>Ae(e)&&document.contains(e)),r],ref:{type:r.type,name:e}}):Object.assign(Object.assign({},n._f),{ref:r})},L(R.current,e,n),be(e,r))},Se=n.useCallback((e,r={})=>{const t=y(R.current,e);return L(R.current,e,{_f:Object.assign(Object.assign(Object.assign({},t&&t._f?t._f:{ref:{name:e}}),{name:e,mount:!0}),r)}),K.current.mount.add(e),!t&&be(e,void 0,!0),Ce?{name:e}:{name:e,onChange:Oe,onBlur:Oe,ref:t=>{if(t)Re(e,t,r);else{const t=y(R.current,e,{}),n=w||r.shouldUnregister;t._f&&(t._f.mount=!1,d(t._f.value)&&(t._f.value=t._f.ref.value)),n&&(!l(K.current.array,e)||!U.current)&&K.current.unMount.add(e)}}}},[]),De=n.useCallback((e,r)=>async n=>{n&&(n.preventDefault&&n.preventDefault(),n.persist&&n.persist());let s=!0,u=q(R);z.current.state.next({isSubmitting:!0});try{if(t){const{errors:e,values:r}=await F.current(u,P.current,me(K.current.mount,R.current,j,O));C.current.errors=e,u=r}else await fe(R.current);D(C.current.errors)&&Object.keys(C.current.errors).every(e=>y(u,e))?(z.current.state.next({errors:{},isSubmitting:!0}),await e(u,n)):(r&&await r(C.current.errors,n),m&&W(R.current,e=>y(C.current.errors,e),K.current.mount))}catch(e){throw s=!1,e}finally{C.current.isSubmitted=!0,z.current.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:D(C.current.errors)&&s,submitCount:C.current.submitCount+1,errors:C.current.errors})}},[m,Y,j,O]),Ee=(e,r="")=>{for(const t in e){const n=e[t],s=r+(r?".":"")+t,u=y(R.current,s);u&&u._f||(i(n)||Array.isArray(n)?Ee(n,s):u||Se(s,{value:n}))}};return n.useEffect(()=>{const e=z.current.state.subscribe({next(e){E(e,k.current,!0)&&(C.current=Object.assign(Object.assign({},C.current),e),A(C.current))}}),r=z.current.array.subscribe({next(e){if(e.values&&e.name&&k.current.isValid){const r=q(R);L(r,e.name,e.values),pe(r)}}});return()=>{e.unsubscribe(),r.unsubscribe()}},[]),n.useEffect(()=>{const e=[],r=e=>!Ae(e)||!document.contains(e);$.current||($.current=!0,k.current.isValid&&pe(),!w&&Ee(N.current));for(const t of K.current.unMount){const n=y(R.current,t);n&&(n._f.refs?n._f.refs.every(r):r(n._f.ref))&&e.push(t)}e.length&&Fe(e),K.current.unMount=new Set}),{control:n.useMemo(()=>({register:Se,inFieldArrayActionRef:U,getIsDirty:ne,subjectsRef:z,watchInternal:ke,fieldsRef:R,updateIsValid:pe,namesRef:K,readFormStateRef:k,formStateRef:C,defaultValuesRef:N,fieldArrayDefaultValuesRef:I,setValues:xe,unregister:Fe,shouldUnmount:w}),[]),formState:S(M,V,k),trigger:ye,register:Se,handleSubmit:De,watch:n.useCallback((e,r)=>he(e)?z.current.watch.subscribe({next:t=>e(ke(void 0,r),t)}):ke(e,r,!0),[]),setValue:n.useCallback((e,r,t={})=>{const n=y(R.current,e),s=K.current.array.has(e);s&&(z.current.array.next({values:r,name:e,isReset:!0}),(k.current.isDirty||k.current.dirtyFields)&&t.shouldDirty&&(L(C.current.dirtyFields,e,Q(r,y(N.current,e,[]),y(C.current.dirtyFields,e,[]))),z.current.state.next({name:e,dirtyFields:C.current.dirtyFields,isDirty:ne(e,r)})),!r.length&&L(R.current,e,[])&&L(I.current,e,[])),(n&&!n._f||s)&&!c(r)?xe(e,r,s?{}:t):te(e,r,t,!0,!n),Z(e)&&z.current.state.next({}),z.current.watch.next({name:e,values:we()})},[xe]),getValues:n.useCallback(we,[]),reset:n.useCallback((e,r={})=>{const t=e||N.current;if(T&&!r.keepValues)for(const e of K.current.mount){const r=y(R.current,e);if(r&&r._f){const e=Array.isArray(r._f.refs)?r._f.refs[0]:r._f.ref;try{Ae(e)&&e.closest("form").reset();break}catch(e){}}}r.keepDefaultValues||(N.current=Object.assign({},t),I.current=Object.assign({},t)),r.keepValues||(R.current={},z.current.control.next({values:r.keepDefaultValues?N.current:Object.assign({},t)}),z.current.watch.next({values:Object.assign({},t)}),z.current.array.next({values:Object.assign({},t),isReset:!0})),K.current={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1},z.current.state.next({submitCount:r.keepSubmitCount?C.current.submitCount:0,isDirty:r.keepDirty?C.current.isDirty:!!r.keepDefaultValues&&J(e,N.current),isSubmitted:!!r.keepIsSubmitted&&C.current.isSubmitted,dirtyFields:r.keepDirty?C.current.dirtyFields:{},touchedFields:r.keepTouched?C.current.touchedFields:{},errors:r.keepErrors?C.current.errors:{},isSubmitting:!1,isSubmitSuccessful:!1}),$.current=!!r.keepIsValid},[]),clearErrors:n.useCallback(e=>{e?B(e).forEach(e=>ue(C.current.errors,e)):C.current.errors={},z.current.state.next({errors:C.current.errors})},[]),unregister:n.useCallback(Fe,[]),setError:n.useCallback((e,r,t)=>{const n=((y(R.current,e)||{_f:{}})._f||{}).ref;L(C.current.errors,e,Object.assign(Object.assign({},r),{ref:n})),z.current.state.next({name:e,errors:C.current.errors,isValid:!1}),t&&t.shouldFocus&&n&&n.focus&&n.focus()},[]),setFocus:n.useCallback(e=>y(R.current,e)._f.ref.focus(),[])}},e.useFormContext=R,e.useFormState=N,e.useWatch=function(e){const{control:r,name:t,defaultValue:s}=e||{},u=R(),c=n.useRef(t);c.current=t;const{watchInternal:a,subjectsRef:i}=r||u.control,[o,l]=n.useState(d(s)?a(t):s);return n.useEffect(()=>{a(t);const e=i.current.watch.subscribe({next:({name:e,values:r})=>(!c.current||!e||B(c.current).some(r=>e&&r&&(r.startsWith(e)||e.startsWith(r))))&&l(a(c.current,s,!1,r))});return()=>e.unsubscribe()},[]),o},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookForm={},e.React)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(t),a=e=>"checkbox"===e.type,n=e=>e instanceof Date,i=e=>null==e;const u=e=>"object"==typeof e;var o=e=>!i(e)&&!Array.isArray(e)&&u(e)&&!n(e),l=e=>o(e)&&e.target?a(e.target)?e.target.checked:e.target.value:e,c=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),d=e=>{const t=e.constructor&&e.constructor.prototype;return o(t)&&t.hasOwnProperty("isPrototypeOf")},f="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function m(e){let t;const r=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else{if(f&&(e instanceof Blob||e instanceof FileList)||!r&&!o(e))return e;if(t=r?[]:{},Array.isArray(e)||d(e))for(const r in e)t[r]=m(e[r]);else t=e}return t}var y=e=>Array.isArray(e)?e.filter(Boolean):[],p=e=>void 0===e,g=(e,t,r)=>{if(!t||!o(e))return r;const s=y(t.split(/[,[\].]+?/)).reduce(((e,t)=>i(e)?e:e[t]),e);return p(s)||s===e?p(e[t])?r:e[t]:s};const _={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},h={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},v="max",b="min",A="maxLength",V="minLength",x="pattern",F="required",S="validate",w=s.default.createContext(null),k=()=>s.default.useContext(w);var D=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const n in e)Object.defineProperty(a,n,{get:()=>{const a=n;return t._proxyFormState[a]!==h.all&&(t._proxyFormState[a]=!s||h.all),r&&(r[a]=!0),e[a]}});return a},C=e=>o(e)&&!Object.keys(e).length,O=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return C(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||h.all)))},j=e=>Array.isArray(e)?e:[e],E=(e,t,r)=>r&&t?e===t:!e||!t||e===t||j(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function U(e){const t=s.default.useRef(e);t.current=e,s.default.useEffect((()=>{const r=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}}),[e.disabled])}function T(e){const t=k(),{control:r=t.control,disabled:a,name:n,exact:i}=e||{},[u,o]=s.default.useState(r._formState),l=s.default.useRef(!0),c=s.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=s.default.useRef(n);return d.current=n,U({disabled:a,next:e=>l.current&&E(d.current,e.name,i)&&O(e,c.current,r._updateFormState)&&o({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>(l.current=!0,c.current.isValid&&r._updateValid(!0),()=>{l.current=!1})),[r]),D(u,r,c.current,!1)}var B=e=>"string"==typeof e,L=(e,t,r,s,a)=>B(e)?(s&&t.watch.add(e),g(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),g(r,e)))):(s&&(t.watchAll=!0),r);function N(e){const t=k(),{control:r=t.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=s.default.useRef(a);o.current=a,U({disabled:i,subject:r._subjects.values,next:e=>{E(o.current,e.name,u)&&c(m(L(o.current,r._names,e.values||r._formValues,!1,n)))}});const[l,c]=s.default.useState(r._getWatch(a,n));return s.default.useEffect((()=>r._removeUnmounted())),l}var M=e=>/^\w*$/.test(e),R=e=>y(e.replace(/["|']|\]/g,"").split(/\.|\[/));function q(e,t,r){let s=-1;const a=M(t)?[t]:R(t),n=a.length,i=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==i){const r=e[t];n=o(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}function P(e){const t=k(),{name:r,control:a=t.control,shouldUnregister:n}=e,i=c(a._names.array,r),u=N({control:a,name:r,defaultValue:g(a._formValues,r,g(a._defaultValues,r,e.defaultValue)),exact:!0}),o=T({control:a,name:r}),d=s.default.useRef(a.register(r,{...e.rules,value:u}));return s.default.useEffect((()=>{const e=a._options.shouldUnregister||n,t=(e,t)=>{const r=g(a._fields,e);r&&(r._f.mount=t)};if(t(r,!0),e){const e=m(g(a._options.defaultValues,r));q(a._defaultValues,r,e),p(g(a._formValues,r))&&q(a._formValues,r,e)}return()=>{(i?e&&!a._state.action:e)?a.unregister(r):t(r,!1)}}),[r,a,i,n]),{field:{name:r,value:u,onChange:s.default.useCallback((e=>d.current.onChange({target:{value:l(e),name:r},type:_.CHANGE})),[r]),onBlur:s.default.useCallback((()=>d.current.onBlur({target:{value:g(a._formValues,r),name:r},type:_.BLUR})),[r,a]),ref:e=>{const t=g(a._fields,r);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:o,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!g(o.errors,r)},isDirty:{enumerable:!0,get:()=>!!g(o.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!g(o.touchedFields,r)},error:{enumerable:!0,get:()=>g(o.errors,r)}})}}var W=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{};const H=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=g(e,s);if(r){const{_f:e,...s}=r;if(e&&t(e.name)){if(e.ref.focus){e.ref.focus();break}if(e.refs&&e.refs[0].focus){e.refs[0].focus();break}}else o(s)&&H(s,t)}}};var $=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},I=(e,t,r={})=>r.shouldFocus||p(r.shouldFocus)?r.focusName||`${e}.${p(r.focusIndex)?t:r.focusIndex}.`:"",G=e=>({isOnSubmit:!e||e===h.onSubmit,isOnBlur:e===h.onBlur,isOnChange:e===h.onChange,isOnAll:e===h.all,isOnTouch:e===h.onTouched}),z=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length))))),J=(e,t,r)=>{const s=y(g(e,r));return q(s,"root",t[r]),q(e,r,s),e},K=e=>"boolean"==typeof e,Q=e=>"file"===e.type,X=e=>"function"==typeof e,Y=e=>{if(!f)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Z=e=>B(e),ee=e=>"radio"===e.type,te=e=>e instanceof RegExp;const re={value:!1,isValid:!1},se={value:!0,isValid:!0};var ae=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!p(e[0].attributes.value)?p(e[0].value)||""===e[0].value?se:{value:e[0].value,isValid:!0}:se:re}return re};const ne={isValid:!1,value:null};var ie=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ne):ne;function ue(e,t,r="validate"){if(Z(e)||Array.isArray(e)&&e.every(Z)||K(e)&&!e)return{type:r,message:Z(e)?e:"",ref:t}}var oe=e=>o(e)&&!te(e)?e:{value:e,message:""},le=async(e,t,r,s,n)=>{const{ref:u,refs:l,required:c,maxLength:d,minLength:f,min:m,max:y,pattern:_,validate:h,name:w,valueAsNumber:k,mount:D,disabled:O}=e._f,j=g(t,w);if(!D||O)return{};const E=l?l[0]:u,U=e=>{s&&E.reportValidity&&(E.setCustomValidity(K(e)?"":e||""),E.reportValidity())},T={},L=ee(u),N=a(u),M=L||N,R=(k||Q(u))&&p(u.value)&&p(j)||Y(u)&&""===u.value||""===j||Array.isArray(j)&&!j.length,q=W.bind(null,w,r,T),P=(e,t,r,s=A,a=V)=>{const n=e?t:r;T[w]={type:e?s:a,message:n,ref:u,...q(e?s:a,n)}};if(n?!Array.isArray(j)||!j.length:c&&(!M&&(R||i(j))||K(j)&&!j||N&&!ae(l).isValid||L&&!ie(l).isValid)){const{value:e,message:t}=Z(c)?{value:!!c,message:c}:oe(c);if(e&&(T[w]={type:F,message:t,ref:E,...q(F,t)},!r))return U(t),T}if(!(R||i(m)&&i(y))){let e,t;const s=oe(y),a=oe(m);if(i(j)||isNaN(j)){const r=u.valueAsDate||new Date(j),n=e=>new Date((new Date).toDateString()+" "+e),i="time"==u.type,o="week"==u.type;B(s.value)&&j&&(e=i?n(j)>n(s.value):o?j>s.value:r>new Date(s.value)),B(a.value)&&j&&(t=i?n(j)<n(a.value):o?j<a.value:r<new Date(a.value))}else{const r=u.valueAsNumber||(j?+j:j);i(s.value)||(e=r>s.value),i(a.value)||(t=r<a.value)}if((e||t)&&(P(!!e,s.message,a.message,v,b),!r))return U(T[w].message),T}if((d||f)&&!R&&(B(j)||n&&Array.isArray(j))){const e=oe(d),t=oe(f),s=!i(e.value)&&j.length>+e.value,a=!i(t.value)&&j.length<+t.value;if((s||a)&&(P(s,e.message,t.message),!r))return U(T[w].message),T}if(_&&!R&&B(j)){const{value:e,message:t}=oe(_);if(te(e)&&!j.match(e)&&(T[w]={type:x,message:t,ref:u,...q(x,t)},!r))return U(t),T}if(h)if(X(h)){const e=ue(await h(j,t),E);if(e&&(T[w]={...e,...q(S,e.message)},!r))return U(e.message),T}else if(o(h)){let e={};for(const s in h){if(!C(e)&&!r)break;const a=ue(await h[s](j,t),E,s);a&&(e={...a,...q(s,a.message)},U(a.message),r&&(T[w]=e))}if(!C(e)&&(T[w]={ref:E,...e},!r))return T}return U(!0),T};function ce(e,t){return[...e,...j(t)]}var de=e=>Array.isArray(e)?e.map((()=>{})):void 0;function fe(e,t,r){return[...e.slice(0,t),...j(r),...e.slice(t)]}var me=(e,t,r)=>Array.isArray(e)?(p(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function ye(e,t){return[...j(t),...j(e)]}var pe=(e,t)=>p(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return y(s).length?s:[]}(e,j(t).sort(((e,t)=>e-t))),ge=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function _e(e,t){const r=Array.isArray(t)?t:M(t)?[t]:R(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=p(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(o(s)&&C(s)||Array.isArray(s)&&function(e){for(const t in e)if(!p(e[t]))return!1;return!0}(s))&&_e(e,r.slice(0,-1)),e}var he=(e,t,r)=>(e[t]=r,e);function ve(){let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var be=e=>i(e)||!u(e);function Ae(e,t){if(be(e)||be(t))return e===t;if(n(e)&&n(t))return e.getTime()===t.getTime();const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const a of r){const r=e[a];if(!s.includes(a))return!1;if("ref"!==a){const e=t[a];if(n(r)&&n(e)||o(r)&&o(e)||Array.isArray(r)&&Array.isArray(e)?!Ae(r,e):r!==e)return!1}}return!0}var Ve=e=>"select-multiple"===e.type,xe=e=>ee(e)||a(e),Fe=e=>Y(e)&&e.isConnected,Se=e=>{for(const t in e)if(X(e[t]))return!0;return!1};function we(e,t={}){const r=Array.isArray(e);if(o(e)||r)for(const r in e)Array.isArray(e[r])||o(e[r])&&!Se(e[r])?(t[r]=Array.isArray(e[r])?[]:{},we(e[r],t[r])):i(e[r])||(t[r]=!0);return t}function ke(e,t,r){const s=Array.isArray(e);if(o(e)||s)for(const s in e)Array.isArray(e[s])||o(e[s])&&!Se(e[s])?p(t)||be(r[s])?r[s]=Array.isArray(e[s])?we(e[s],[]):{...we(e[s])}:ke(e[s],i(t)?{}:t[s],r[s]):r[s]=!Ae(e[s],t[s]);return r}var De=(e,t)=>ke(e,t,we(t)),Ce=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>p(e)?e:t?""===e?NaN:e?+e:e:r&&B(e)?new Date(e):s?s(e):e;function Oe(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return Q(t)?t.files:ee(t)?ie(e.refs).value:Ve(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ae(e.refs).value:Ce(p(t.value)?e.ref.value:t.value,e)}var je=(e,t,r,s)=>{const a={};for(const r of e){const e=g(t,r);e&&q(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Ee=e=>p(e)?e:te(e)?e.source:o(e)?te(e.value)?e.value.source:e.value:e,Ue=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Te(e,t,r){const s=g(e,r);if(s||M(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=g(t,s),i=g(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Be=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Le=(e,t)=>!y(g(e,t)).length&&_e(e,t);const Ne={mode:h.onSubmit,reValidateMode:h.onChange,shouldFocusError:!0};function Me(e={},t){let r,s={...Ne,...e},u={submitCount:0,isDirty:!1,isLoading:X(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},d={},v=(o(s.defaultValues)||o(s.values))&&m(s.defaultValues||s.values)||{},b=s.shouldUnregister?{}:m(v),A={action:!1,mount:!1,watch:!1},V={mount:new Set,unMount:new Set,array:new Set,watch:new Set},x=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},S={values:ve(),array:ve(),state:ve()},w=e.resetOptions&&e.resetOptions.keepDirtyValues,k=G(s.mode),D=G(s.reValidateMode),O=s.criteriaMode===h.all,E=async e=>{if(F.isValid||e){const e=s.resolver?C((await R()).errors):await P(d,!0);e!==u.isValid&&S.state.next({isValid:e})}},U=e=>F.isValidating&&S.state.next({isValidating:e}),T=(e,t,r,s)=>{const a=g(d,e);if(a){const n=g(b,e,p(r)?g(v,e):r);p(n)||s&&s.defaultChecked||t?q(b,e,t?n:Oe(a._f)):I(e,n),A.mount&&E()}},N=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e};if(!r||s){F.isDirty&&(i=u.isDirty,u.isDirty=o.isDirty=W(),n=i!==o.isDirty);const r=Ae(g(v,e),t);i=g(u.dirtyFields,e),r?_e(u.dirtyFields,e):q(u.dirtyFields,e,!0),o.dirtyFields=u.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=g(u.touchedFields,e);t||(q(u.touchedFields,e,r),o.touchedFields=u.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(o),n?o:{}},M=(t,s,a,n)=>{const i=g(u.errors,t),o=F.isValid&&K(s)&&u.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{q(u.errors,e,t),S.state.next({errors:u.errors})})(t,a),r=e=>{clearTimeout(x),x=setTimeout(l,e)},r(e.delayError)):(clearTimeout(x),r=null,a?q(u.errors,t,a):_e(u.errors,t)),(a?!Ae(i,a):i)||!C(n)||o){const e={...n,...o&&K(s)?{isValid:s}:{},errors:u.errors,name:t};u={...u,...e},S.state.next(e)}U(!1)},R=async e=>s.resolver(b,s.context,je(e||V.mount,d,s.criteriaMode,s.shouldUseNativeValidation)),P=async(e,t,r={valid:!0})=>{for(const a in e){const n=e[a];if(n){const{_f:e,...a}=n;if(e){const a=V.array.has(e.name),i=await le(n,b,O,s.shouldUseNativeValidation&&!t,a);if(i[e.name]&&(r.valid=!1,t))break;!t&&(g(i,e.name)?a?J(u.errors,i,e.name):q(u.errors,e.name,i[e.name]):_e(u.errors,e.name))}a&&await P(a,t,r)}}return r.valid},W=(e,t)=>(e&&t&&q(b,e,t),!Ae(se(),v)),$=(e,t,r)=>L(e,V,{...A.mount?b:p(t)?v:B(e)?{[e]:t}:t},r,t),I=(e,t,r={})=>{const s=g(d,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&q(b,e,Ce(t,r)),n=Y(r.ref)&&i(t)?"":t,Ve(r.ref)?[...r.ref.options].forEach((e=>e.selected=n.includes(e.value))):r.refs?a(r.ref)?r.refs.length>1?r.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(n)?!!n.find((t=>t===e.value)):n===e.value))):r.refs[0]&&(r.refs[0].checked=!!n):r.refs.forEach((e=>e.checked=e.value===n)):Q(r.ref)?r.ref.value="":(r.ref.value=n,r.ref.type||S.values.next({name:e,values:{...b}})))}(r.shouldDirty||r.shouldTouch)&&N(e,n,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&re(e)},Z=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,u=g(d,i);!V.array.has(e)&&be(a)&&(!u||u._f)||n(a)?I(i,a,r):Z(i,a,r)}},ee=(e,r,s={})=>{const a=g(d,e),n=V.array.has(e),o=m(r);q(b,e,o),n?(S.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:De(v,b),isDirty:W(e,o)})):!a||a._f||i(o)?I(e,o,s):Z(e,o,s),z(e,V)&&S.state.next({...u}),S.values.next({name:e,values:{...b}}),!A.mount&&t()},te=async e=>{const t=e.target;let a=t.name,n=!0;const i=g(d,a);if(i){let o,c;const f=t.type?Oe(i._f):l(e),m=e.type===_.BLUR||e.type===_.FOCUS_OUT,y=!Ue(i._f)&&!s.resolver&&!g(u.errors,a)&&!i._f.deps||Be(m,g(u.touchedFields,a),u.isSubmitted,D,k),p=z(a,V,m);q(b,a,f),m?(i._f.onBlur&&i._f.onBlur(e),r&&r(0)):i._f.onChange&&i._f.onChange(e);const h=N(a,f,m,!1),v=!C(h)||p;if(!m&&S.values.next({name:a,type:e.type,values:{...b}}),y)return F.isValid&&E(),v&&S.state.next({name:a,...p?{}:h});if(!m&&p&&S.state.next({...u}),U(!0),s.resolver){const{errors:e}=await R([a]),t=Te(u.errors,d,a),r=Te(e,d,t.name||a);o=r.error,a=r.name,c=C(e)}else o=(await le(i,b,O,s.shouldUseNativeValidation))[a],n=isNaN(f)||f===g(b,a,f),n&&(o?c=!1:F.isValid&&(c=await P(d,!0)));n&&(i._f.deps&&re(i._f.deps),M(a,c,o,h))}},re=async(e,t={})=>{let r,a;const n=j(e);if(U(!0),s.resolver){const t=await(async e=>{const{errors:t}=await R();if(e)for(const r of e){const e=g(t,r);e?q(u.errors,r,e):_e(u.errors,r)}else u.errors=t;return t})(p(e)?e:n);r=C(t),a=e?!n.some((e=>g(t,e))):r}else e?(a=(await Promise.all(n.map((async e=>{const t=g(d,e);return await P(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&E()):a=r=await P(d);return S.state.next({...!B(e)||F.isValid&&r!==u.isValid?{}:{name:e},...s.resolver||!e?{isValid:r}:{},errors:u.errors,isValidating:!1}),t.shouldFocus&&!a&&H(d,(e=>e&&g(u.errors,e)),e?n:V.mount),a},se=e=>{const t={...v,...A.mount?b:{}};return p(e)?t:B(e)?g(t,e):e.map((e=>g(t,e)))},ae=(e,t)=>({invalid:!!g((t||u).errors,e),isDirty:!!g((t||u).dirtyFields,e),isTouched:!!g((t||u).touchedFields,e),error:g((t||u).errors,e)}),ne=(e,t={})=>{for(const r of e?j(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(_e(d,r),_e(b,r)),!t.keepError&&_e(u.errors,r),!t.keepDirty&&_e(u.dirtyFields,r),!t.keepTouched&&_e(u.touchedFields,r),!s.shouldUnregister&&!t.keepDefaultValue&&_e(v,r);S.values.next({values:{...b}}),S.state.next({...u,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&E()},ie=(e,t={})=>{let r=g(d,e);const a=K(t.disabled);return q(d,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?a&&q(b,e,t.disabled?void 0:g(b,e,Oe(r._f))):T(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.shouldUseNativeValidation?{required:!!t.required,min:Ee(t.min),max:Ee(t.max),minLength:Ee(t.minLength),maxLength:Ee(t.maxLength),pattern:Ee(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:a=>{if(a){ie(e,t),r=g(d,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=xe(s),i=r._f.refs||[];if(n?i.find((e=>e===s)):s===r._f.ref)return;q(d,e,{_f:{...r._f,...n?{refs:[...i.filter(Fe),s,...Array.isArray(g(v,e))?[{}]:[]],ref:{type:s.type,name:e}}:{ref:s}}}),T(e,!1,void 0,s)}else r=g(d,e,{}),r._f&&(r._f.mount=!1),(s.shouldUnregister||t.shouldUnregister)&&(!c(V.array,e)||!A.action)&&V.unMount.add(e)}}},ue=()=>s.shouldFocusError&&H(d,(e=>e&&g(u.errors,e)),V.mount),oe=(r,s={})=>{const a=r||v,n=m(a),i=r&&!C(r)?n:v;if(s.keepDefaultValues||(v=a),!s.keepValues){if(s.keepDirtyValues||w)for(const e of V.mount)g(u.dirtyFields,e)?q(i,e,g(b,e)):ee(e,g(i,e));else{if(f&&p(r))for(const e of V.mount){const t=g(d,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Y(e)){const t=e.closest("form");if(t){t.reset();break}}}}d={}}b=e.shouldUnregister?s.keepDefaultValues?m(v):{}:n,S.array.next({values:{...i}}),S.values.next({values:{...i}})}V={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!A.mount&&t(),A.mount=!F.isValid||!!s.keepIsValid,A.watch=!!e.shouldUnregister,S.state.next({submitCount:s.keepSubmitCount?u.submitCount:0,isDirty:s.keepDirty?u.isDirty:!(!s.keepDefaultValues||Ae(r,v)),isSubmitted:!!s.keepIsSubmitted&&u.isSubmitted,dirtyFields:s.keepDirtyValues?u.dirtyFields:s.keepDefaultValues&&r?De(v,r):{},touchedFields:s.keepTouched?u.touchedFields:{},errors:s.keepErrors?u.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},ce=(e,t)=>oe(X(e)?e(b):e,t);return{control:{register:ie,unregister:ne,getFieldState:ae,_executeSchema:R,_getWatch:$,_getDirty:W,_updateValid:E,_removeUnmounted:()=>{for(const e of V.unMount){const t=g(d,e);t&&(t._f.refs?t._f.refs.every((e=>!Fe(e))):!Fe(t._f.ref))&&ne(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(A.action=!0,n&&Array.isArray(g(d,e))){const t=r(g(d,e),s.argA,s.argB);a&&q(d,e,t)}if(n&&Array.isArray(g(u.errors,e))){const t=r(g(u.errors,e),s.argA,s.argB);a&&q(u.errors,e,t),Le(u.errors,e)}if(F.touchedFields&&n&&Array.isArray(g(u.touchedFields,e))){const t=r(g(u.touchedFields,e),s.argA,s.argB);a&&q(u.touchedFields,e,t)}F.dirtyFields&&(u.dirtyFields=De(v,b)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else q(b,e,t)},_getFieldArray:t=>y(g(A.mount?b:v,t,e.shouldUnregister?g(v,t,[]):[])),_reset:oe,_resetDefaultValues:()=>X(s.defaultValues)&&s.defaultValues().then((e=>{ce(e,s.resetOptions),S.state.next({isLoading:!1})})),_updateFormState:e=>{u={...u,...e}},_subjects:S,_proxyFormState:F,get _fields(){return d},get _formValues(){return b},get _state(){return A},set _state(e){A=e},get _defaultValues(){return v},get _names(){return V},set _names(e){V=e},get _formState(){return u},set _formState(e){u=e},get _options(){return s},set _options(e){s={...s,...e}}},trigger:re,register:ie,handleSubmit:(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=m(b);if(S.state.next({isSubmitting:!0}),s.resolver){const{errors:e,values:t}=await R();u.errors=e,a=t}else await P(d);_e(u.errors,"root"),C(u.errors)?(S.state.next({errors:{}}),await e(a,r)):(t&&await t({...u.errors},r),ue(),setTimeout(ue)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:C(u.errors),submitCount:u.submitCount+1,errors:u.errors})},watch:(e,t)=>X(e)?S.values.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:ee,getValues:se,reset:ce,resetField:(e,t={})=>{g(d,e)&&(p(t.defaultValue)?ee(e,g(v,e)):(ee(e,t.defaultValue),q(v,e,t.defaultValue)),t.keepTouched||_e(u.touchedFields,e),t.keepDirty||(_e(u.dirtyFields,e),u.isDirty=t.defaultValue?W(e,g(v,e)):W()),t.keepError||(_e(u.errors,e),F.isValid&&E()),S.state.next({...u}))},clearErrors:e=>{e&&j(e).forEach((e=>_e(u.errors,e))),S.state.next({errors:e?u.errors:{}})},unregister:ne,setError:(e,t,r)=>{const s=(g(d,e,{_f:{}})._f||{}).ref;q(u.errors,e,{...t,ref:s}),S.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},setFocus:(e,t={})=>{const r=g(d,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ae}}e.Controller=e=>e.render(P(e)),e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(w.Provider,{value:r},t)},e.appendErrors=W,e.get=g,e.set=q,e.useController=P,e.useFieldArray=function(e){const t=k(),{control:r=t.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map($)),c=s.default.useRef(u),d=s.default.useRef(a),f=s.default.useRef(!1);d.current=a,c.current=u,r._names.array.add(a),e.rules&&r.register(a,e.rules),U({next:({values:e,name:t})=>{if(t===d.current||!t){const t=g(e,d.current);Array.isArray(t)&&(o(t),l.current=t.map($))}},subject:r._subjects.array});const y=s.default.useCallback((e=>{f.current=!0,r._updateFieldArray(a,e)}),[r,a]);return s.default.useEffect((()=>{if(r._state.action=!1,z(a,r._names)&&r._subjects.state.next({...r._formState}),f.current&&(!G(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=g(e.errors,a),s=g(r._formState.errors,a);(s?!t&&s.type:t&&t.type)&&(t?q(r._formState.errors,a,t):_e(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=g(r._fields,a);e&&e._f&&le(e,r._formValues,r._options.criteriaMode===h.all,r._options.shouldUseNativeValidation,!0).then((e=>!C(e)&&r._subjects.state.next({errors:J(r._formState.errors,e,a)})))}r._subjects.values.next({name:a,values:{...r._formValues}}),r._names.focus&&H(r._fields,(e=>!!e&&e.startsWith(r._names.focus||""))),r._names.focus="",r._updateValid()}),[u,a,r]),s.default.useEffect((()=>(!g(r._formValues,a)&&r._updateFieldArray(a),()=>{(r._options.shouldUnregister||i)&&r.unregister(a)})),[a,r,n,i]),{swap:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);ge(s,e,t),ge(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,ge,{argA:e,argB:t},!1)}),[y,a,r]),move:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);me(s,e,t),me(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,me,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=ye(r._getFieldArray(a),s);r._names.focus=I(a,0,t),l.current=ye(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,ye,{argA:de(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=ce(r._getFieldArray(a),s);r._names.focus=I(a,n.length-1,t),l.current=ce(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,ce,{argA:de(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=pe(r._getFieldArray(a),e);l.current=pe(l.current,e),y(t),o(t),r._updateFieldArray(a,t,pe,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=j(m(t)),i=fe(r._getFieldArray(a),e,n);r._names.focus=I(a,e,s),l.current=fe(l.current,e,n.map($)),y(i),o(i),r._updateFieldArray(a,i,fe,{argA:e,argB:de(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=m(t),n=he(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:$())),y(n),o([...n]),r._updateFieldArray(a,n,he,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=j(m(e));l.current=t.map($),y([...t]),o([...t]),r._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,r]),fields:s.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||$()})))),[u,n])}},e.useForm=function(e={}){const t=s.default.useRef(),[r,a]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:X(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:X(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Me(e,(()=>a((e=>({...e}))))),formState:r});const n=t.current.control;return n._options=e,U({subject:n._subjects.state,next:e=>{O(e,n._proxyFormState,n._updateFormState,!0)&&a({...n._formState})}}),s.default.useEffect((()=>{e.values&&!Ae(e.values,n._defaultValues)?n._reset(e.values,n._options.resetOptions):n._resetDefaultValues()}),[e.values,n]),s.default.useEffect((()=>{n._state.mount||(n._updateValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()})),t.current.formState=D(r,n),t.current},e.useFormContext=k,e.useFormState=T,e.useWatch=N,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
import { InternalFieldErrors, InternalFieldName, ValidateResult } from '../types';
declare const _default: (name: InternalFieldName, validateAllFieldCriteria: boolean, errors: InternalFieldErrors, type: string, message: ValidateResult) => {};
export default _default;
//# sourceMappingURL=appendErrors.d.ts.map

@@ -1,3 +0,4 @@

import { FieldRefs } from '../types';
declare const focusFieldBy: (fields: FieldRefs, callback: (name: string) => boolean, fieldsNames?: Set<string> | string[] | undefined) => void;
import { FieldRefs, InternalFieldName } from '../types';
declare const focusFieldBy: (fields: FieldRefs, callback: (name?: string) => boolean, fieldsNames?: Set<InternalFieldName> | InternalFieldName[]) => void;
export default focusFieldBy;
//# sourceMappingURL=focusFieldBy.d.ts.map
declare const _default: () => string;
export default _default;
//# sourceMappingURL=generateId.d.ts.map

@@ -1,6 +0,7 @@

declare type CheckboxFieldResult = {
type CheckboxFieldResult = {
isValid: boolean;
value: string | string[] | boolean | undefined;
};
declare const _default: (options?: HTMLInputElement[] | undefined) => CheckboxFieldResult;
declare const _default: (options?: HTMLInputElement[]) => CheckboxFieldResult;
export default _default;
//# sourceMappingURL=getCheckboxValue.d.ts.map
import { Field } from '../types';
export default function getFieldValue(field?: Field): any;
export default function getFieldValue(_f: Field['_f']): any;
//# sourceMappingURL=getFieldValue.d.ts.map

@@ -1,3 +0,4 @@

import { Field } from '../types';
declare const _default: (value: any, { valueAsNumber, valueAsDate, setValueAs }: Field['_f']) => any;
import { Field, NativeFieldValue } from '../types';
declare const _default: <T extends NativeFieldValue>(value: T, { valueAsNumber, valueAsDate, setValueAs }: Field['_f']) => any;
export default _default;
//# sourceMappingURL=getFieldValueAs.d.ts.map
declare const _default: (name: string) => string;
export default _default;
//# sourceMappingURL=getNodeParentName.d.ts.map

@@ -1,4 +0,4 @@

import * as React from 'react';
import { FormState, ReadFormState } from '../types';
declare const _default: <TFieldValues>(isProxyEnabled: boolean, formState: FormState<TFieldValues>, readFormStateRef: React.MutableRefObject<ReadFormState>, localReadFormStateRef?: React.MutableRefObject<ReadFormState> | undefined, isRoot?: boolean) => FormState<TFieldValues>;
import { Control, FieldValues, FormState, ReadFormState } from '../types';
declare const _default: <TFieldValues extends FieldValues, TContext = any>(formState: FormState<TFieldValues>, control: Control<TFieldValues, TContext>, localProxyFormState?: ReadFormState, isRoot?: boolean) => FormState<TFieldValues>;
export default _default;
//# sourceMappingURL=getProxyFormState.d.ts.map

@@ -1,6 +0,7 @@

declare type RadioFieldResult = {
type RadioFieldResult = {
isValid: boolean;
value: number | string | null;
};
declare const _default: (options?: HTMLInputElement[] | undefined) => RadioFieldResult;
declare const _default: (options?: HTMLInputElement[]) => RadioFieldResult;
export default _default;
//# sourceMappingURL=getRadioValue.d.ts.map

@@ -1,3 +0,3 @@

import { CriteriaMode, FieldName, FieldRefs, InternalFieldName } from '../types';
declare const _default: <TFieldValues>(fieldsNames: Set<InternalFieldName> | InternalFieldName[], fieldsRefs: FieldRefs, criteriaMode?: CriteriaMode | undefined, shouldUseNativeValidation?: boolean | undefined) => {
import { CriteriaMode, FieldName, FieldRefs, FieldValues, InternalFieldName } from '../types';
declare const _default: <TFieldValues extends FieldValues>(fieldsNames: Set<InternalFieldName> | InternalFieldName[], _fields: FieldRefs, criteriaMode?: CriteriaMode, shouldUseNativeValidation?: boolean | undefined) => {
criteriaMode: CriteriaMode | undefined;

@@ -8,21 +8,8 @@ names: FieldName<TFieldValues>[];

name: string;
value?: any;
refs?: HTMLInputElement[] | undefined;
mount?: boolean | undefined;
} & Partial<{
required: string | import("../types").ValidationRule<boolean>;
min: import("../types").ValidationRule<string | number>;
max: import("../types").ValidationRule<string | number>;
maxLength: import("../types").ValidationRule<string | number>;
minLength: import("../types").ValidationRule<string | number>;
pattern: import("../types").ValidationRule<RegExp>;
validate: import("../types").Validate<any> | Record<string, import("../types").Validate<any>>;
valueAsNumber: boolean;
valueAsDate: boolean;
value: any;
setValueAs: (value: any) => any;
shouldUnregister?: boolean | undefined;
}>>;
} & import("../types").RegisterOptions>;
shouldUseNativeValidation: boolean | undefined;
};
export default _default;
//# sourceMappingURL=getResolverOptions.d.ts.map
import { FieldError, Ref, ValidateResult } from '../types';
export default function getValidateError(result: ValidateResult, ref: Ref, type?: string): FieldError | void;
//# sourceMappingURL=getValidateError.d.ts.map
import { ValidationRule } from '../types';
declare const _default: (validationData?: ValidationRule<import("../types").ValidationValue> | undefined) => {
declare const _default: (validationData?: ValidationRule) => {
value: string | number | boolean | RegExp | undefined;

@@ -7,1 +7,2 @@ message: string;

export default _default;
//# sourceMappingURL=getValueAndMessage.d.ts.map

@@ -1,15 +0,4 @@

declare const _default: <T extends Partial<{
required: string | import("../types").ValidationRule<boolean>;
min: import("../types").ValidationRule<string | number>;
max: import("../types").ValidationRule<string | number>;
maxLength: import("../types").ValidationRule<string | number>;
minLength: import("../types").ValidationRule<string | number>;
pattern: import("../types").ValidationRule<RegExp>;
validate: import("../types").Validate<any> | Record<string, import("../types").Validate<any>>;
valueAsNumber: boolean;
valueAsDate: boolean;
value: any;
setValueAs: (value: any) => any;
shouldUnregister?: boolean | undefined;
}>>(options?: T | undefined, mounted?: boolean | undefined) => boolean | import("../types").ValidationValueMessage<boolean> | import("../types").ValidationRule<string | number> | import("../types").ValidationRule<RegExp> | import("../types").Validate<any> | Record<string, import("../types").Validate<any>> | undefined;
import { Field } from '../types';
declare const _default: (options: Field['_f']) => string | number | boolean | import("../types").ValidationValueMessage<boolean> | import("../types").ValidationValueMessage<string | number> | import("../types").ValidationRule<RegExp> | import("../types").Validate<any, import("../types").FieldValues> | Record<string, import("../types").Validate<any, import("../types").FieldValues>> | undefined;
export default _default;
//# sourceMappingURL=hasValidation.d.ts.map
import appendErrors from './appendErrors';
export { appendErrors };
//# sourceMappingURL=index.d.ts.map
import { InternalFieldName } from '../types';
declare const _default: (names: Set<InternalFieldName>, name: InternalFieldName) => boolean;
export default _default;
//# sourceMappingURL=isNameInFieldArray.d.ts.map

@@ -1,3 +0,6 @@

import { ReadFormState } from '../types';
declare const _default: <T extends Record<string, any>, K extends ReadFormState>(formStateData: T, readFormStateRef: K, isRoot?: boolean | undefined) => string | true | undefined;
import { Control, FieldValues, FormState, InternalFieldName, ReadFormState } from '../types';
declare const _default: <T extends FieldValues, K extends ReadFormState>(formStateData: Partial<FormState<T>> & {
name?: string | undefined;
}, _proxyFormState: K, updateFormState: (formState: Partial<FormState<T>>) => void, isRoot?: boolean) => string | true | undefined;
export default _default;
//# sourceMappingURL=shouldRenderFormState.d.ts.map

@@ -1,12 +0,12 @@

declare const _default: ({ isOnBlur, isOnChange, isOnTouch, isTouched, isReValidateOnBlur, isReValidateOnChange, isBlurEvent, isSubmitted, isOnAll, }: {
isOnAll?: boolean | undefined;
isOnBlur?: boolean | undefined;
isOnChange?: boolean | undefined;
isReValidateOnBlur?: boolean | undefined;
isReValidateOnChange?: boolean | undefined;
isBlurEvent?: boolean | undefined;
isSubmitted?: boolean | undefined;
isOnTouch?: boolean | undefined;
isTouched?: boolean | undefined;
}) => boolean | undefined;
declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode: {
isOnBlur: boolean;
isOnChange: boolean;
}, mode: Partial<{
isOnSubmit: boolean;
isOnBlur: boolean;
isOnChange: boolean;
isOnTouch: boolean;
isOnAll: boolean;
}>) => boolean;
export default _default;
//# sourceMappingURL=skipValidation.d.ts.map

@@ -1,3 +0,4 @@

import { Field, InternalFieldErrors } from '../types';
declare const _default: ({ _f: { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, value: inputValue, valueAsNumber, mount, }, }: Field, validateAllFieldCriteria: boolean, shouldUseNativeValidation?: boolean | undefined) => Promise<InternalFieldErrors>;
import { Field, FieldValues, InternalFieldErrors } from '../types';
declare const _default: <T extends FieldValues>(field: Field, formValues: T, validateAllFieldCriteria: boolean, shouldUseNativeValidation?: boolean, isFieldArray?: boolean) => Promise<InternalFieldErrors>;
export default _default;
//# sourceMappingURL=validateField.d.ts.map

@@ -1,5 +0,5 @@

import * as React from 'react';
import React from 'react';
import { RegisterOptions } from './validator';
import { Control, FieldError, FieldPath, FieldPathValue, FieldValues, RefCallBack, UnpackNestedValue, UseFormStateReturn } from './';
export declare type ControllerFieldState = {
import { Control, FieldError, FieldPath, FieldPathValue, FieldValues, Noop, RefCallBack, UseFormStateReturn } from './';
export type ControllerFieldState = {
invalid: boolean;

@@ -10,17 +10,17 @@ isTouched: boolean;

};
export declare type ControllerRenderProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
export type ControllerRenderProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
onChange: (...event: any[]) => void;
onBlur: () => void;
value: UnpackNestedValue<FieldPathValue<TFieldValues, TName>>;
onBlur: Noop;
value: FieldPathValue<TFieldValues, TName>;
name: TName;
ref: RefCallBack;
};
export declare type UseControllerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
export type UseControllerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
name: TName;
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs'>;
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
shouldUnregister?: boolean;
defaultValue?: UnpackNestedValue<FieldPathValue<TFieldValues, TName>>;
defaultValue?: FieldPathValue<TFieldValues, TName>;
control?: Control<TFieldValues>;
};
export declare type UseControllerReturn<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
export type UseControllerReturn<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
field: ControllerRenderProps<TFieldValues, TName>;

@@ -30,3 +30,24 @@ formState: UseFormStateReturn<TFieldValues>;

};
export declare type ControllerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
/**
* Render function to provide the control for the field.
*
* @returns all the event handler, and relevant field and form state.
*
* @example
* ```tsx
* const { field, fieldState, formState } = useController();
*
* <Controller
* render={({ field, formState, fieldState }) => ({
* <input
* onChange={field.onChange}
* onBlur={field.onBlur}
* name={field.name}
* ref={field.ref} // optional for focus management
* />
* })}
* />
* ```
*/
export type ControllerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
render: ({ field, fieldState, formState, }: {

@@ -38,1 +59,2 @@ field: ControllerRenderProps<TFieldValues, TName>;

} & UseControllerProps<TFieldValues, TName>;
//# sourceMappingURL=controller.d.ts.map
import { FieldValues, InternalFieldName, Ref } from './fields';
import { DeepMap, LiteralUnion } from './utils';
import { BrowserNativeObject, IsAny, LiteralUnion, Merge } from './utils';
import { RegisterOptions, ValidateResult } from './validator';
export declare type Message = string;
export declare type MultipleFieldErrors = {
export type Message = string;
export type MultipleFieldErrors = {
[K in keyof RegisterOptions]?: ValidateResult;

@@ -10,4 +10,5 @@ } & {

};
export declare type FieldError = {
export type FieldError = {
type: LiteralUnion<keyof RegisterOptions, string>;
root?: FieldError;
ref?: Ref;

@@ -17,3 +18,3 @@ types?: MultipleFieldErrors;

};
export declare type ErrorOption = {
export type ErrorOption = {
message?: Message;

@@ -23,3 +24,16 @@ type?: LiteralUnion<keyof RegisterOptions, string>;

};
export declare type FieldErrors<TFieldValues extends FieldValues = FieldValues> = DeepMap<TFieldValues, FieldError>;
export declare type InternalFieldErrors = Partial<Record<InternalFieldName, FieldError>>;
export type DeepRequired<T> = T extends BrowserNativeObject | Blob ? T : {
[K in keyof T]-?: NonNullable<DeepRequired<T[K]>>;
};
export type FieldErrorsImpl<T extends FieldValues = FieldValues> = {
[K in keyof T]?: T[K] extends BrowserNativeObject | Blob ? FieldError : K extends 'root' | `root.${string}` ? GlobalError : T[K] extends object ? Merge<FieldError, FieldErrorsImpl<T[K]>> : FieldError;
};
export type GlobalError = Partial<{
type: string | number;
message: string;
}>;
export type FieldErrors<T extends FieldValues = FieldValues> = Partial<FieldValues extends IsAny<FieldValues> ? any : FieldErrorsImpl<DeepRequired<T>>> & {
root?: Record<string, GlobalError> & GlobalError;
};
export type InternalFieldErrors = Partial<Record<InternalFieldName, FieldError>>;
//# sourceMappingURL=errors.d.ts.map

@@ -1,1 +0,2 @@

export declare type EventType = 'focus' | 'blur' | 'change' | 'changeText' | 'valueChange' | 'contentSizeChange' | 'endEditing' | 'keyPress' | 'submitEditing' | 'layout' | 'selectionChange' | 'longPress' | 'press' | 'pressIn' | 'pressOut' | 'momentumScrollBegin' | 'momentumScrollEnd' | 'scroll' | 'scrollBeginDrag' | 'scrollEndDrag' | 'load' | 'error' | 'progress' | 'custom';
export type EventType = 'focus' | 'blur' | 'change' | 'changeText' | 'valueChange' | 'contentSizeChange' | 'endEditing' | 'keyPress' | 'submitEditing' | 'layout' | 'selectionChange' | 'longPress' | 'press' | 'pressIn' | 'pressOut' | 'momentumScrollBegin' | 'momentumScrollEnd' | 'scroll' | 'scrollBeginDrag' | 'scrollEndDrag' | 'load' | 'error' | 'progress' | 'custom';
//# sourceMappingURL=events.d.ts.map
import { FieldValues } from './fields';
import { Control } from './form';
import { FieldArrayPath, FieldArrayPathValue } from './utils';
export declare type FieldArrayName = string;
export declare type FieldArrayDefaultValues = Partial<Record<FieldArrayName, any>>;
export declare type UseFieldArrayProps<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = {
import { FieldArrayPath, FieldArrayPathValue } from './path';
import { RegisterOptions, Validate } from './validator';
export type UseFieldArrayProps<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = {
name: TFieldArrayName;
keyName?: TKeyName;
control?: Control<TFieldValues>;
rules?: {
validate?: Validate<FieldArray<TFieldValues, TFieldArrayName>[], TFieldValues> | Record<string, Validate<FieldArray<TFieldValues, TFieldArrayName>[], TFieldValues>>;
} & Pick<RegisterOptions<TFieldValues>, 'maxLength' | 'minLength' | 'required'>;
shouldUnregister?: boolean;
};
export declare type FieldArrayWithId<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = FieldArray<TFieldValues, TFieldArrayName> & Record<TKeyName, string>;
export declare type FieldArray<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = FieldArrayPathValue<TFieldValues, TFieldArrayName> extends ReadonlyArray<infer U> ? U : never;
export declare type FieldArrayMethodProps = {
/**
* `useFieldArray` returned `fields` with unique id
*/
export type FieldArrayWithId<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = FieldArray<TFieldValues, TFieldArrayName> & Record<TKeyName, string>;
export type FieldArray<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = FieldArrayPathValue<TFieldValues, TFieldArrayName> extends ReadonlyArray<infer U> | null | undefined ? U : never;
/**
* `useFieldArray` focus option, ability to toggle focus on and off with `shouldFocus` and setting focus by either field index or name.
*/
export type FieldArrayMethodProps = {
shouldFocus?: boolean;

@@ -19,11 +27,170 @@ focusIndex?: number;

};
export declare type UseFieldArrayReturn<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = {
swap: (indexA: number, indexB: number) => void;
move: (indexA: number, indexB: number) => void;
prepend: (value: Partial<FieldArray<TFieldValues, TFieldArrayName>> | Partial<FieldArray<TFieldValues, TFieldArrayName>>[], options?: FieldArrayMethodProps) => void;
append: (value: Partial<FieldArray<TFieldValues, TFieldArrayName>> | Partial<FieldArray<TFieldValues, TFieldArrayName>>[], options?: FieldArrayMethodProps) => void;
remove: (index?: number | number[]) => void;
insert: (index: number, value: Partial<FieldArray<TFieldValues, TFieldArrayName>> | Partial<FieldArray<TFieldValues, TFieldArrayName>>[], options?: FieldArrayMethodProps) => void;
update: (index: number, value: Partial<FieldArray<TFieldValues, TFieldArrayName>>) => void;
/**
* Swap field array by supplying from and to index
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param indexA - from index
* @param indexB - to index
*
* @example
* ```tsx
* <button type="button" onClick={() => swap(0, 1)}>swap</button>
* ```
*/
export type UseFieldArraySwap = (indexA: number, indexB: number) => void;
/**
* Move field array by supplying from and to index
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param indexA - from index
* @param indexB - to index
*
* @example
* ```tsx
* <button type="button" onClick={() => move(0, 1)}>swap</button>
* ```
*/
export type UseFieldArrayMove = (indexA: number, indexB: number) => void;
/**
* Prepend field/fields to the start of the fields and optionally focus. The input value will be registered during this action.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param value - prepend items or items
* @param options - focus options
*
* @example
* ```tsx
* <button type="button" onClick={() => prepend({ name: "data" })}>Prepend</button>
* <button type="button" onClick={() => prepend({ name: "data" }, { shouldFocus: false })}>Prepend</button>
* <button
* type="button"
* onClick={() => prepend([{ name: "data" }, { name: "data" }])}
* >
* Prepend
* </button>
* ```
*/
export type UseFieldArrayPrepend<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = (value: FieldArray<TFieldValues, TFieldArrayName> | FieldArray<TFieldValues, TFieldArrayName>[], options?: FieldArrayMethodProps) => void;
/**
* Append field/fields to the end of your fields and focus. The input value will be registered during this action.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param value - append items or items.
* @param options - focus options
*
* @example
* ```tsx
* <button type="button" onClick={() => append({ name: "data" })}>Append</button>
* <button type="button" onClick={() => append({ name: "data" }, { shouldFocus: false })}>Append</button>
* <button
* type="button"
* onClick={() => append([{ name: "data" }, { name: "data" }])}
* >
* Append
* </button>
* ```
*/
export type UseFieldArrayAppend<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = (value: FieldArray<TFieldValues, TFieldArrayName> | FieldArray<TFieldValues, TFieldArrayName>[], options?: FieldArrayMethodProps) => void;
/**
* Remove field/fields at particular position.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param index - index to remove at, or remove all when no index provided.
*
* @example
* ```tsx
* <button type="button" onClick={() => remove(0)}>Remove</button>
* <button
* type="button"
* onClick={() => remove()}
* >
* Remove all
* </button>
* ```
*/
export type UseFieldArrayRemove = (index?: number | number[]) => void;
/**
* Insert field/fields at particular position and focus.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param index - insert position
* @param value - insert field or fields
* @param options - focus options
*
* @example
* ```tsx
* <button type="button" onClick={() => insert(1, { name: "data" })}>Insert</button>
* <button type="button" onClick={() => insert(1, { name: "data" }, { shouldFocus: false })}>Insert</button>
* <button
* type="button"
* onClick={() => insert(1, [{ name: "data" }, { name: "data" }])}
* >
* Insert
* </button>
* ```
*/
export type UseFieldArrayInsert<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = (index: number, value: FieldArray<TFieldValues, TFieldArrayName> | FieldArray<TFieldValues, TFieldArrayName>[], options?: FieldArrayMethodProps) => void;
/**
* Update field/fields at particular position.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param index - insert position
* @param value - insert field or fields
*
* @example
* ```tsx
* <button type="button" onClick={() => update(1, { name: "data" })}>Update</button>
* <button
* type="button"
* onClick={() => update(1, [{ name: "data" }, { name: "data" }])}
* >
* Update
* </button>
* ```
*/
export type UseFieldArrayUpdate<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = (index: number, value: FieldArray<TFieldValues, TFieldArrayName>) => void;
/**
* Replace the entire field array values.
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d)
*
* @param value - the entire field values.
*
* @example
* ```tsx
* <button
* type="button"
* onClick={() => replace([{ name: "data" }, { name: "data" }])}
* >
* Replace
* </button>
* ```
*/
export type UseFieldArrayReplace<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>> = (value: FieldArray<TFieldValues, TFieldArrayName> | FieldArray<TFieldValues, TFieldArrayName>[]) => void;
export type UseFieldArrayReturn<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'> = {
swap: UseFieldArraySwap;
move: UseFieldArrayMove;
prepend: UseFieldArrayPrepend<TFieldValues, TFieldArrayName>;
append: UseFieldArrayAppend<TFieldValues, TFieldArrayName>;
remove: UseFieldArrayRemove;
insert: UseFieldArrayInsert<TFieldValues, TFieldArrayName>;
update: UseFieldArrayUpdate<TFieldValues, TFieldArrayName>;
replace: UseFieldArrayReplace<TFieldValues, TFieldArrayName>;
fields: FieldArrayWithId<TFieldValues, TFieldArrayName, TKeyName>[];
};
//# sourceMappingURL=fieldArray.d.ts.map

@@ -1,6 +0,6 @@

import { IsFlatObject } from './utils';
import { IsFlatObject, Noop } from './utils';
import { RegisterOptions } from './validator';
export declare type InternalFieldName = string;
export declare type FieldName<TFieldValues extends FieldValues> = IsFlatObject<TFieldValues> extends true ? Extract<keyof TFieldValues, string> : string;
export declare type CustomElement<TFieldValues extends FieldValues> = {
export type InternalFieldName = string;
export type FieldName<TFieldValues extends FieldValues> = IsFlatObject<TFieldValues> extends true ? Extract<keyof TFieldValues, string> : string;
export type CustomElement<TFieldValues extends FieldValues> = {
name: FieldName<TFieldValues>;

@@ -13,13 +13,13 @@ type?: string;

files?: FileList | null;
focus?: () => void;
focus?: Noop;
};
export declare type FieldValue<TFieldValues extends FieldValues> = TFieldValues[InternalFieldName];
export declare type FieldValues = Record<string, any>;
export declare type FieldElement<TFieldValues extends FieldValues = FieldValues> = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | CustomElement<TFieldValues>;
export declare type Ref = FieldElement;
export declare type Field = {
export type FieldValue<TFieldValues extends FieldValues> = TFieldValues[InternalFieldName];
export type FieldValues = Record<string, any>;
export type NativeFieldValue = string | number | boolean | null | undefined | unknown[];
export type FieldElement<TFieldValues extends FieldValues = FieldValues> = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | CustomElement<TFieldValues>;
export type Ref = FieldElement;
export type Field = {
_f: {
ref: Ref;
name: InternalFieldName;
value?: any;
refs?: HTMLInputElement[];

@@ -29,2 +29,3 @@ mount?: boolean;

};
export declare type FieldRefs = Partial<Record<InternalFieldName, Field>>;
export type FieldRefs = Partial<Record<InternalFieldName, Field>>;
//# sourceMappingURL=fields.d.ts.map

@@ -1,20 +0,27 @@

import * as React from 'react';
import { SubjectType, Subscription } from '../utils/Subject';
import { ErrorOption, FieldErrors } from './errors';
import React from 'react';
import { Subject, Subscription } from '../utils/createSubject';
import { ErrorOption, FieldError, FieldErrors } from './errors';
import { EventType } from './events';
import { FieldArrayDefaultValues } from './fieldArray';
import { FieldArray } from './fieldArray';
import { FieldRefs, FieldValue, FieldValues, InternalFieldName } from './fields';
import { FieldArrayPath, FieldPath, FieldPathValue, FieldPathValues } from './path';
import { Resolver } from './resolvers';
import { DeepMap, DeepPartial, FieldPath, FieldPathValue, FieldPathValues, PathValue } from './utils';
import { DeepMap, DeepPartial, Noop } from './utils';
import { RegisterOptions } from './validator';
declare const $NestedValue: unique symbol;
export declare type NestedValue<TValue extends unknown[] | Record<string, unknown> | Map<unknown, unknown> = unknown[] | Record<string, unknown>> = {
/**
* @deprecated to be removed in the next major version
*/
export type NestedValue<TValue extends object = object> = {
[$NestedValue]: never;
} & TValue;
export declare type UnpackNestedValue<T> = T extends NestedValue<infer U> ? U : T extends Date | FileList ? T : T extends Record<string, unknown> ? {
/**
* @deprecated to be removed in the next major version
*/
export type UnpackNestedValue<T> = T extends NestedValue<infer U> ? U : T extends Date | FileList | File | Blob ? T : T extends object ? {
[K in keyof T]: UnpackNestedValue<T[K]>;
} : T;
export declare type DefaultValues<TFieldValues> = UnpackNestedValue<DeepPartial<TFieldValues>>;
export declare type InternalNameSet = Set<InternalFieldName>;
export declare type ValidationMode = {
export type DefaultValues<TFieldValues> = DeepPartial<TFieldValues>;
export type InternalNameSet = Set<InternalFieldName>;
export type ValidationMode = {
onBlur: 'onBlur';

@@ -26,7 +33,7 @@ onChange: 'onChange';

};
export declare type Mode = keyof ValidationMode;
export declare type CriteriaMode = 'firstError' | 'all';
export declare type SubmitHandler<TFieldValues extends FieldValues> = (data: UnpackNestedValue<TFieldValues>, event?: React.BaseSyntheticEvent) => any | Promise<any>;
export declare type SubmitErrorHandler<TFieldValues extends FieldValues> = (errors: FieldErrors<TFieldValues>, event?: React.BaseSyntheticEvent) => any | Promise<any>;
export declare type SetValueConfig = Partial<{
export type Mode = keyof ValidationMode;
export type CriteriaMode = 'firstError' | 'all';
export type SubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>;
export type SubmitErrorHandler<TFieldValues extends FieldValues> = (errors: FieldErrors<TFieldValues>, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>;
export type SetValueConfig = Partial<{
shouldValidate: boolean;

@@ -36,14 +43,17 @@ shouldDirty: boolean;

}>;
export declare type TriggerConfig = Partial<{
export type TriggerConfig = Partial<{
shouldFocus: boolean;
}>;
export declare type ChangeHandler = (event: {
export type ChangeHandler = (event: {
target: any;
type?: any;
}) => Promise<void | boolean>;
export declare type ValidateHandler = <TFieldValues>(event: any, fieldState: Partial<Pick<FormState<TFieldValues>, 'dirtyFields' | 'isDirty' | 'touchedFields'>>, isWatched: boolean, isBlurEvent: boolean) => Promise<void | boolean>;
export declare type UseFormProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = Partial<{
export type DelayCallback = (wait: number) => void;
type AsyncDefaultValues<TFieldValues> = (payload?: unknown) => Promise<TFieldValues>;
export type UseFormProps<TFieldValues extends FieldValues = FieldValues, TContext = any> = Partial<{
mode: Mode;
reValidateMode: Exclude<Mode, 'onTouched' | 'all'>;
defaultValues: DefaultValues<TFieldValues>;
defaultValues: DefaultValues<TFieldValues> | AsyncDefaultValues<TFieldValues>;
values: TFieldValues;
resetOptions: Parameters<UseFormReset<TFieldValues>>[1];
resolver: Resolver<TFieldValues, TContext>;

@@ -57,4 +67,4 @@ context: TContext;

}>;
export declare type FieldNamesMarkedBoolean<TFieldValues extends FieldValues> = DeepMap<TFieldValues, true>;
export declare type FormStateProxy<TFieldValues extends FieldValues = FieldValues> = {
export type FieldNamesMarkedBoolean<TFieldValues extends FieldValues> = DeepMap<DeepPartial<TFieldValues>, boolean>;
export type FormStateProxy<TFieldValues extends FieldValues = FieldValues> = {
isDirty: boolean;

@@ -67,18 +77,21 @@ isValidating: boolean;

};
export declare type ReadFormState = {
export type ReadFormState = {
[K in keyof FormStateProxy]: boolean | 'all';
};
export declare type FormState<TFieldValues> = {
export type FormState<TFieldValues extends FieldValues> = {
isDirty: boolean;
dirtyFields: FieldNamesMarkedBoolean<TFieldValues>;
isLoading: boolean;
isSubmitted: boolean;
isSubmitSuccessful: boolean;
submitCount: number;
touchedFields: FieldNamesMarkedBoolean<TFieldValues>;
isSubmitting: boolean;
isValidating: boolean;
isValid: boolean;
submitCount: number;
defaultValues?: undefined | Readonly<DeepPartial<TFieldValues>>;
dirtyFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>;
touchedFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>;
errors: FieldErrors<TFieldValues>;
};
export declare type KeepStateOptions = Partial<{
export type KeepStateOptions = Partial<{
keepDirtyValues: boolean;
keepErrors: boolean;

@@ -93,30 +106,350 @@ keepDirty: boolean;

}>;
export declare type SetFieldValue<TFieldValues> = FieldValue<TFieldValues>;
export declare type RefCallBack = (instance: any) => void;
export declare type UseFormRegisterReturn = {
export type SetFieldValue<TFieldValues extends FieldValues> = FieldValue<TFieldValues>;
export type RefCallBack = (instance: any) => void;
export type UseFormRegisterReturn<TFieldName extends InternalFieldName = InternalFieldName> = {
onChange: ChangeHandler;
onBlur: ChangeHandler;
ref: RefCallBack;
name: InternalFieldName;
name: TFieldName;
min?: string | number;
max?: string | number;
maxLength?: number;
minLength?: number;
pattern?: string;
required?: boolean;
disabled?: boolean;
};
export declare type UseFormRegister<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: RegisterOptions<TFieldValues, TFieldName>) => UseFormRegisterReturn;
export declare type UseFormSetFocus<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName) => void;
export declare type UseFormGetValues<TFieldValues extends FieldValues> = {
(): UnpackNestedValue<TFieldValues>;
/**
* Register field into hook form with or without the actual DOM ref. You can invoke register anywhere in the component including at `useEffect`.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/register) • [Demo](https://codesandbox.io/s/react-hook-form-register-ts-ip2j3) • [Video](https://www.youtube.com/watch?v=JFIpCoajYkA)
*
* @param name - the path name to the form field value, name is required and unique
* @param options - register options include validation, disabled, unregister, value as and dependent validation
*
* @returns onChange, onBlur, name, ref, and native contribute attribute if browser validation is enabled.
*
* @example
* ```tsx
* // Register HTML native input
* <input {...register("input")} />
* <select {...register("select")} />
*
* // Register options
* <textarea {...register("textarea", { required: "This is required.", maxLength: 20 })} />
* <input type="number" {...register("name2", { valueAsNumber: true })} />
* <input {...register("name3", { deps: ["name2"] })} />
*
* // Register custom field at useEffect
* useEffect(() => {
* register("name4");
* register("name5", { value: '"hiddenValue" });
* }, [register])
*
* // Register without ref
* const { onChange, onBlur, name } = register("name6")
* <input onChange={onChange} onBlur={onBlur} name={name} />
* ```
*/
export type UseFormRegister<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: RegisterOptions<TFieldValues, TFieldName>) => UseFormRegisterReturn<TFieldName>;
export type SetFocusOptions = Partial<{
shouldSelect: boolean;
}>;
/**
* Set focus on a registered field. You can start to invoke this method after all fields are mounted to the DOM.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/setfocus) • [Demo](https://codesandbox.io/s/setfocus-rolus)
*
* @param name - the path name to the form field value.
* @param options - input focus behavior options
*
* @example
* ```tsx
* useEffect(() => {
* setFocus("name");
* }, [setFocus])
* // shouldSelect allows to select input's content on focus
* <button onClick={() => setFocus("name", { shouldSelect: true })}>Focus</button>
* ```
*/
export type UseFormSetFocus<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: SetFocusOptions) => void;
export type UseFormGetValues<TFieldValues extends FieldValues> = {
/**
* Get the entire form values when no argument is supplied to this function.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
*
* @returns form values
*
* @example
* ```tsx
* <button onClick={() => getValues()}>getValues</button>
*
* <input {...register("name", {
* validate: (value, formValues) => formValues.otherField === value;
* })} />
* ```
*/
(): TFieldValues;
/**
* Get a single field value.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
*
* @param name - the path name to the form field value.
*
* @returns the single field value
*
* @example
* ```tsx
* <button onClick={() => getValues("name")}>getValues</button>
*
* <input {...register("name", {
* validate: () => getValues('otherField') === "test";
* })} />
* ```
*/
<TFieldName extends FieldPath<TFieldValues>>(name: TFieldName): FieldPathValue<TFieldValues, TFieldName>;
/**
* Get an array of field values.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/getvalues) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg)
*
* @param names - an array of field names
*
* @returns An array of field values
*
* @example
* ```tsx
* <button onClick={() => getValues(["name", "name1"])}>getValues</button>
*
* <input {...register("name", {
* validate: () => getValues(["fieldA", "fieldB"]).includes("test");
* })} />
* ```
*/
<TFieldNames extends FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames]): [...FieldPathValues<TFieldValues, TFieldNames>];
};
export declare type UseFormWatch<TFieldValues extends FieldValues> = {
(): UnpackNestedValue<TFieldValues>;
/**
* This method will return individual field states. It will be useful when you are trying to retrieve the nested value field state in a typesafe approach.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/getfieldstate) • [Demo](https://codesandbox.io/s/getfieldstate-jvekk)
*
* @param name - the path name to the form field value.
*
* @returns invalid, isDirty, isTouched and error object
*
* @example
* ```tsx
* // those formState has to be subscribed
* const { formState: { dirtyFields, errors, touchedFields } } = formState();
* getFieldState('name')
* // Get field state when form state is not subscribed yet
* getFieldState('name', formState)
*
* // It's ok to combine with useFormState
* const formState = useFormState();
* getFieldState('name')
* getFieldState('name', formState)
* ```
*/
export type UseFormGetFieldState<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, formState?: FormState<TFieldValues>) => {
invalid: boolean;
isDirty: boolean;
isTouched: boolean;
error?: FieldError;
};
export type UseFormWatch<TFieldValues extends FieldValues> = {
/**
* Watch and subscribe to the entire form update/change based on onChange and re-render at the useForm.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
*
* @returns return the entire form values
*
* @example
* ```tsx
* const formValues = watch();
* ```
*/
(): TFieldValues;
/**
* Watch and subscribe to an array of fields used outside of render.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
*
* @param names - an array of field names
* @param defaultValue - defaultValues for the entire form
*
* @returns return an array of field values
*
* @example
* ```tsx
* const [name, name1] = watch(["name", "name1"]);
* ```
*/
<TFieldNames extends readonly FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames], defaultValue?: DeepPartial<TFieldValues>): FieldPathValues<TFieldValues, TFieldNames>;
/**
* Watch and subscribe to a single field used outside of render.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
*
* @param name - the path name to the form field value.
* @param defaultValue - defaultValues for the entire form
*
* @returns return the single field value
*
* @example
* ```tsx
* const name = watch("name");
* ```
*/
<TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, defaultValue?: FieldPathValue<TFieldValues, TFieldName>): FieldPathValue<TFieldValues, TFieldName>;
<TFieldNames extends readonly FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames], defaultValue?: UnpackNestedValue<DeepPartial<TFieldValues>>): FieldPathValues<TFieldValues, TFieldNames>;
(callback: WatchObserver<TFieldValues>, defaultValues?: UnpackNestedValue<DeepPartial<TFieldValues>>): Subscription;
/**
* Subscribe to field update/change without trigger re-render
*
* @remarks
* [API](https://react-hook-form.com/api/useform/watch) • [Demo](https://codesandbox.io/s/react-hook-form-watch-v7-ts-8et1d) • [Video](https://www.youtube.com/watch?v=3qLd69WMqKk)
*
* @param callback - call back function to subscribe all fields change and return unsubscribe function
* @param defaultValues - defaultValues for the entire form
*
* @returns unsubscribe function
*
* @example
* ```tsx
* useEffect(() => {
* const { unsubscribe } = watch((value) => {
* console.log(value);
* });
* return () => unsubscribe();
* }, [watch])
* ```
*/
(callback: WatchObserver<TFieldValues>, defaultValues?: DeepPartial<TFieldValues>): Subscription;
};
export declare type UseFormTrigger<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: TriggerConfig) => Promise<boolean>;
export declare type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[]) => void;
export declare type UseFormSetValue<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, value: UnpackNestedValue<FieldPathValue<TFieldValues, TFieldName>>, options?: SetValueConfig) => void;
export declare type UseFormSetError<TFieldValues extends FieldValues> = (name: FieldPath<TFieldValues>, error: ErrorOption, options?: {
/**
* Trigger field or form validation
*
* @remarks
* [API](https://react-hook-form.com/api/useform/trigger) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-triggervalidation-forked-xs7hl) • [Video](https://www.youtube.com/watch?v=-bcyJCDjksE)
*
* @param name - provide empty argument will trigger the entire form validation, an array of field names will validate an arrange of fields, and a single field name will only trigger that field's validation.
* @param options - should focus on the error field
*
* @returns validation result
*
* @example
* ```tsx
* useEffect(() => {
* trigger();
* }, [trigger])
*
* <button onClick={async () => {
* const result = await trigger(); // result will be a boolean value
* }}>
* trigger
* </button>
* ```
*/
export type UseFormTrigger<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: TriggerConfig) => Promise<boolean>;
/**
* Clear the entire form errors.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/clearerrors) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx)
*
* @param name - the path name to the form field value.
*
* @example
* Clear all errors
* ```tsx
* clearErrors(); // clear the entire form error
* clearErrors(["name", "name1"]) // clear an array of fields' error
* clearErrors("name2"); // clear a single field error
* ```
*/
export type UseFormClearErrors<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[] | `root.${string}` | 'root') => void;
/**
* Set a single field value, or a group of fields value.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/setvalue) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-setvalue-8z9hx) • [Video](https://www.youtube.com/watch?v=qpv51sCH3fI)
*
* @param name - the path name to the form field value.
* @param value - field value
* @param options - should validate or update form state
*
* @example
* ```tsx
* // Update a single field
* setValue('name', 'value', {
* shouldValidate: true, // trigger validation
* shouldTouch: true, // update touched fields form state
* shouldDirty: true, // update dirty and dirty fields form state
* });
*
* // Update a group fields
* setValue('root', {
* a: 'test', // setValue('root.a', 'data')
* b: 'test1', // setValue('root.b', 'data')
* });
*
* // Update a nested object field
* setValue('select', { label: 'test', value: 'Test' });
* ```
*/
export type UseFormSetValue<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, value: FieldPathValue<TFieldValues, TFieldName>, options?: SetValueConfig) => void;
/**
* Set an error for the field. When set an error which is not associated to a field then manual `clearErrors` invoke is required.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/seterror) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-seterror-nfxxu) • [Video](https://www.youtube.com/watch?v=raMqvE0YyIY)
*
* @param name - the path name to the form field value.
* @param error - an error object which contains type and optional message
* @param options - whether or not to focus on the field
*
* @example
* ```tsx
* // when the error is not associated with any fields, `clearError` will need to invoke to clear the error
* const onSubmit = () => setError("serverError", { type: "server", message: "Error occurred"})
*
* <button onClick={() => setError("name", { type: "min" })} />
*
* // focus on the input after setting the error
* <button onClick={() => setError("name", { type: "max" }, { shouldFocus: true })} />
* ```
*/
export type UseFormSetError<TFieldValues extends FieldValues> = (name: FieldPath<TFieldValues> | `root.${string}` | 'root', error: ErrorOption, options?: {
shouldFocus: boolean;
}) => void;
export declare type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: Omit<KeepStateOptions, 'keepIsSubmitted' | 'keepSubmitCount' | 'keepValues' | 'keepDefaultValues' | 'keepErrors'> & {
/**
* Unregister a field reference and remove its value.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/unregister) • [Demo](https://codesandbox.io/s/react-hook-form-unregister-4k2ey) • [Video](https://www.youtube.com/watch?v=TM99g_NW5Gk&feature=emb_imp_woyt)
*
* @param name - the path name to the form field value.
* @param options - keep form state options
*
* @example
* ```tsx
* register("name", { required: true })
*
* <button onClick={() => unregister("name")} />
* // there are various keep options to retain formState
* <button onClick={() => unregister("name", { keepErrors: true })} />
* ```
*/
export type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[], options?: Omit<KeepStateOptions, 'keepIsSubmitted' | 'keepSubmitCount' | 'keepValues' | 'keepDefaultValues' | 'keepErrors'> & {
keepValue?: boolean;

@@ -126,27 +459,97 @@ keepDefaultValue?: boolean;

}) => void;
export declare type UseFormHandleSubmit<TFieldValues extends FieldValues> = <TSubmitFieldValues extends FieldValues = TFieldValues>(onValid: SubmitHandler<TSubmitFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>;
export declare type UseFormReset<TFieldValues extends FieldValues> = (values?: DefaultValues<TFieldValues>, keepStateOptions?: KeepStateOptions) => void;
export declare type WatchInternal<TFieldValues> = (fieldNames?: InternalFieldName | InternalFieldName[], defaultValue?: UnpackNestedValue<DeepPartial<TFieldValues>>, isGlobal?: boolean, formValues?: unknown) => FieldPathValue<FieldValues, InternalFieldName> | FieldPathValues<FieldValues, InternalFieldName[]>;
export declare type GetIsDirty = <TName extends InternalFieldName, TData>(name?: TName, data?: TData) => boolean;
export declare type FormStateSubjectRef<TFieldValues> = SubjectType<Partial<FormState<TFieldValues>> & {
/**
* Validate the entire form. Handle submit and error callback.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/handlesubmit) • [Demo](https://codesandbox.io/s/react-hook-form-handlesubmit-ts-v7-lcrtu) • [Video](https://www.youtube.com/watch?v=KzcPKB9SOEk)
*
* @param onValid - callback function invoked after form pass validation
* @param onInvalid - callback function invoked when form failed validation
*
* @returns callback - return callback function
*
* @example
* ```tsx
* const onSubmit = (data) => console.log(data);
* const onError = (error) => console.log(error);
*
* <form onSubmit={handleSubmit(onSubmit, onError)} />
* ```
*/
export type UseFormHandleSubmit<TFieldValues extends FieldValues> = (onValid: SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>;
/**
* Reset a field state and reference.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/resetfield) • [Demo](https://codesandbox.io/s/priceless-firefly-d0kuv) • [Video](https://www.youtube.com/watch?v=IdLFcNaEFEo)
*
* @param name - the path name to the form field value.
* @param options - keep form state options
*
* @example
* ```tsx
* <input {...register("firstName", { required: true })} />
* <button type="button" onClick={() => resetField("firstName"))}>Reset</button>
* ```
*/
export type UseFormResetField<TFieldValues extends FieldValues> = <TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: Partial<{
keepDirty: boolean;
keepTouched: boolean;
keepError: boolean;
defaultValue: FieldPathValue<TFieldValues, TFieldName>;
}>) => void;
type ResetAction<TFieldValues> = (formValues: TFieldValues) => TFieldValues;
/**
* Reset at the entire form state.
*
* @remarks
* [API](https://react-hook-form.com/api/useform/reset) • [Demo](https://codesandbox.io/s/react-hook-form-reset-v7-ts-pu901) • [Video](https://www.youtube.com/watch?v=qmCLBjyPwVk)
*
* @param values - the entire form values to be reset
* @param keepStateOptions - keep form state options
*
* @example
* ```tsx
* useEffect(() => {
* // reset the entire form after component mount or form defaultValues is ready
* reset({
* fieldA: "test"
* fieldB: "test"
* });
* }, [reset])
*
* // reset by combine with existing form values
* reset({
* ...getValues(),
* fieldB: "test"
*});
*
* // reset and keep form state
* reset({
* ...getValues(),
*}, {
* keepErrors: true,
* keepDirty: true
*});
* ```
*/
export type UseFormReset<TFieldValues extends FieldValues> = (values?: DefaultValues<TFieldValues> | TFieldValues | ResetAction<TFieldValues>, keepStateOptions?: KeepStateOptions) => void;
export type WatchInternal<TFieldValues> = (fieldNames?: InternalFieldName | InternalFieldName[], defaultValue?: DeepPartial<TFieldValues>, isMounted?: boolean, isGlobal?: boolean) => FieldPathValue<FieldValues, InternalFieldName> | FieldPathValues<FieldValues, InternalFieldName[]>;
export type GetIsDirty = <TName extends InternalFieldName, TData>(name?: TName, data?: TData) => boolean;
export type FormStateSubjectRef<TFieldValues extends FieldValues> = Subject<Partial<FormState<TFieldValues>> & {
name?: InternalFieldName;
}>;
export declare type Subjects<TFieldValues extends FieldValues = FieldValues> = React.MutableRefObject<{
watch: SubjectType<{
export type Subjects<TFieldValues extends FieldValues = FieldValues> = {
values: Subject<{
name?: InternalFieldName;
type?: EventType;
values?: FieldValues;
values: FieldValues;
}>;
control: SubjectType<{
array: Subject<{
name?: InternalFieldName;
values?: FieldValues;
}>;
array: SubjectType<{
name?: InternalFieldName;
values?: FieldValues;
isReset?: boolean;
}>;
state: FormStateSubjectRef<TFieldValues>;
}>;
export declare type Names = {
};
export type Names = {
mount: InternalNameSet;

@@ -156,29 +559,47 @@ unMount: InternalNameSet;

watch: InternalNameSet;
watchAll: boolean;
focus?: InternalFieldName;
watchAll?: boolean;
};
export declare type Control<TFieldValues extends FieldValues = FieldValues> = {
shouldUnmount?: boolean;
subjectsRef: Subjects<TFieldValues>;
namesRef: React.MutableRefObject<Names>;
inFieldArrayActionRef: React.MutableRefObject<boolean>;
getIsDirty: GetIsDirty;
fieldArrayDefaultValuesRef: FieldArrayDefaultValues;
formStateRef: React.MutableRefObject<FormState<TFieldValues>>;
updateIsValid: <T extends FieldValues>(payload?: T) => void;
fieldsRef: React.MutableRefObject<FieldRefs>;
readFormStateRef: React.MutableRefObject<ReadFormState>;
defaultValuesRef: React.MutableRefObject<DefaultValues<TFieldValues>>;
watchInternal: WatchInternal<TFieldValues>;
export type BatchFieldArrayUpdate = <T extends Function, TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>(name: InternalFieldName, updatedFieldArrayValues?: Partial<FieldArray<TFieldValues, TFieldArrayName>>[], method?: T, args?: Partial<{
argA: unknown;
argB: unknown;
}>, shouldSetValue?: boolean, shouldUpdateFieldsAndErrors?: boolean) => void;
export type Control<TFieldValues extends FieldValues = FieldValues, TContext = any> = {
_subjects: Subjects<TFieldValues>;
_removeUnmounted: Noop;
_names: Names;
_state: {
mount: boolean;
action: boolean;
watch: boolean;
};
_reset: UseFormReset<TFieldValues>;
_options: UseFormProps<TFieldValues, TContext>;
_getDirty: GetIsDirty;
_resetDefaultValues: Noop;
_formState: FormState<TFieldValues>;
_updateValid: (shouldUpdateValid?: boolean) => void;
_updateFormState: (formState: Partial<FormState<TFieldValues>>) => void;
_fields: FieldRefs;
_formValues: FieldValues;
_proxyFormState: ReadFormState;
_defaultValues: Partial<DefaultValues<TFieldValues>>;
_getWatch: WatchInternal<TFieldValues>;
_updateFieldArray: BatchFieldArrayUpdate;
_getFieldArray: <TFieldArrayValues>(name: InternalFieldName) => Partial<TFieldArrayValues>[];
_executeSchema: (names: InternalFieldName[]) => Promise<{
errors: FieldErrors;
}>;
register: UseFormRegister<TFieldValues>;
setValues: (name: FieldPath<TFieldValues>, value: UnpackNestedValue<PathValue<TFieldValues, FieldPath<TFieldValues>>>, options: SetValueConfig) => void;
unregister: UseFormUnregister<TFieldValues>;
getFieldState: UseFormGetFieldState<TFieldValues>;
};
export declare type WatchObserver<TFieldValues> = (value: UnpackNestedValue<TFieldValues>, info: {
name?: string;
export type WatchObserver<TFieldValues extends FieldValues> = (value: DeepPartial<TFieldValues>, info: {
name?: FieldPath<TFieldValues>;
type?: EventType;
value?: unknown;
}) => void;
export declare type UseFormReturn<TFieldValues extends FieldValues = FieldValues> = {
export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any> = {
watch: UseFormWatch<TFieldValues>;
getValues: UseFormGetValues<TFieldValues>;
getFieldState: UseFormGetFieldState<TFieldValues>;
setError: UseFormSetError<TFieldValues>;

@@ -189,22 +610,28 @@ clearErrors: UseFormClearErrors<TFieldValues>;

formState: FormState<TFieldValues>;
resetField: UseFormResetField<TFieldValues>;
reset: UseFormReset<TFieldValues>;
handleSubmit: UseFormHandleSubmit<TFieldValues>;
unregister: UseFormUnregister<TFieldValues>;
control: Control<TFieldValues>;
control: Control<TFieldValues, TContext>;
register: UseFormRegister<TFieldValues>;
setFocus: UseFormSetFocus<TFieldValues>;
};
export declare type UseFormStateProps<TFieldValues> = Partial<{
export type UseFormStateProps<TFieldValues extends FieldValues> = Partial<{
control?: Control<TFieldValues>;
disabled?: boolean;
name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[];
exact?: boolean;
}>;
export declare type UseFormStateReturn<TFieldValues> = FormState<TFieldValues>;
export declare type UseWatchProps<TFieldValues extends FieldValues = FieldValues> = {
export type UseFormStateReturn<TFieldValues extends FieldValues> = FormState<TFieldValues>;
export type UseWatchProps<TFieldValues extends FieldValues = FieldValues> = {
defaultValue?: unknown;
disabled?: boolean;
name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[];
control?: Control<TFieldValues>;
exact?: boolean;
};
export declare type FormProviderProps<TFieldValues extends FieldValues = FieldValues> = {
children: React.ReactNode;
} & UseFormReturn<TFieldValues>;
export type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any> = {
children: React.ReactNode | React.ReactNode[];
} & UseFormReturn<TFieldValues, TContext>;
export {};
//# sourceMappingURL=form.d.ts.map

@@ -7,4 +7,6 @@ export * from './controller';

export * from './form';
export * from './path';
export * from './resolvers';
export * from './utils';
export * from './validator';
//# sourceMappingURL=index.d.ts.map
import { FieldErrors } from './errors';
import { Field, FieldName, FieldValues, InternalFieldName } from './fields';
import { CriteriaMode, UnpackNestedValue } from './form';
export declare type ResolverSuccess<TFieldValues extends FieldValues = FieldValues> = {
values: UnpackNestedValue<TFieldValues>;
import { CriteriaMode } from './form';
export type ResolverSuccess<TFieldValues extends FieldValues = FieldValues> = {
values: TFieldValues;
errors: {};
};
export declare type ResolverError<TFieldValues extends FieldValues = FieldValues> = {
export type ResolverError<TFieldValues extends FieldValues = FieldValues> = {
values: {};
errors: FieldErrors<TFieldValues>;
};
export declare type ResolverResult<TFieldValues extends FieldValues = FieldValues> = ResolverSuccess<TFieldValues> | ResolverError<TFieldValues>;
export interface ResolverOptions<TFieldValues> {
export type ResolverResult<TFieldValues extends FieldValues = FieldValues> = ResolverSuccess<TFieldValues> | ResolverError<TFieldValues>;
export interface ResolverOptions<TFieldValues extends FieldValues> {
criteriaMode?: CriteriaMode;

@@ -19,2 +19,3 @@ fields: Record<InternalFieldName, Field['_f']>;

}
export declare type Resolver<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> = (values: UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>> | ResolverResult<TFieldValues>;
export type Resolver<TFieldValues extends FieldValues = FieldValues, TContext = any> = (values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>> | ResolverResult<TFieldValues>;
//# sourceMappingURL=resolvers.d.ts.map

@@ -1,44 +0,71 @@

import { FieldValues } from './fields';
import { NestedValue } from './form';
export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
export declare type EmptyObject = {
export type Noop = () => void;
interface File extends Blob {
readonly lastModified: number;
readonly name: string;
}
interface FileList {
readonly length: number;
item(index: number): File | null;
[index: number]: File;
}
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
export type BrowserNativeObject = Date | FileList | File;
export type EmptyObject = {
[K in string | number]: never;
};
export declare type NonUndefined<T> = T extends undefined ? never : T;
export declare type LiteralUnion<T extends U, U extends Primitive> = T | (U & {
export type NonUndefined<T> = T extends undefined ? never : T;
export type LiteralUnion<T extends U, U extends Primitive> = T | (U & {
_?: never;
});
export declare type DeepPartial<T> = T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
[key in keyof T]: T[key];
} ? {
export type DeepPartial<T> = T extends BrowserNativeObject | NestedValue ? T : {
[K in keyof T]?: DeepPartial<T[K]>;
} : T;
export declare type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
export declare type DeepMap<T, TValue> = {
[K in keyof T]?: IsAny<T[K]> extends true ? any : NonNullable<T[K]> extends NestedValue | Date | FileList | File ? TValue : NonUndefined<T[K]> extends object | null ? DeepMap<T[K], TValue> : NonUndefined<T[K]> extends Array<infer U> ? IsAny<U> extends true ? Array<any> : U extends NestedValue | Date | FileList ? Array<TValue> : U extends object ? Array<DeepMap<U, TValue>> : Array<TValue> : TValue;
};
export declare type IsFlatObject<T extends object> = Extract<Exclude<T[keyof T], NestedValue | Date | FileList>, any[] | object> extends never ? true : false;
declare type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
declare type TupleKey<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
declare type ArrayKey = number;
declare type PathImpl<K extends string | number, V> = V extends Primitive ? `${K}` : `${K}` | `${K}.${Path<V>}`;
export declare type Path<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
[K in TupleKey<T>]-?: PathImpl<K & string, T[K]>;
}[TupleKey<T>] : PathImpl<ArrayKey, V> : {
[K in keyof T]-?: PathImpl<K & string, T[K]>;
}[keyof T];
export declare type FieldPath<TFieldValues extends FieldValues> = Path<TFieldValues>;
declare type ArrayPathImpl<K extends string | number, V> = V extends Primitive ? never : V extends ReadonlyArray<infer U> ? U extends Primitive ? never : `${K}` | `${K}.${ArrayPath<V>}` : `${K}.${ArrayPath<V>}`;
export declare type ArrayPath<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
[K in TupleKey<T>]-?: ArrayPathImpl<K & string, T[K]>;
}[TupleKey<T>] : ArrayPathImpl<ArrayKey, V> : {
[K in keyof T]-?: ArrayPathImpl<K & string, T[K]>;
}[keyof T];
export declare type FieldArrayPath<TFieldValues extends FieldValues> = ArrayPath<TFieldValues>;
export declare type PathValue<T, P extends Path<T> | ArrayPath<T>> = P extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? PathValue<T[K], R> : never : K extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? PathValue<V, R & Path<V>> : never : never : P extends keyof T ? T[P] : P extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? V : never : never;
export declare type FieldPathValue<TFieldValues extends FieldValues, TFieldPath extends FieldPath<TFieldValues>> = PathValue<TFieldValues, TFieldPath>;
export declare type FieldArrayPathValue<TFieldValues extends FieldValues, TFieldArrayPath extends FieldArrayPath<TFieldValues>> = PathValue<TFieldValues, TFieldArrayPath>;
export declare type FieldPathValues<TFieldValues extends FieldValues, TPath extends FieldPath<TFieldValues>[] | readonly FieldPath<TFieldValues>[]> = {} & {
[K in keyof TPath]: FieldPathValue<TFieldValues, TPath[K] & FieldPath<TFieldValues>>;
export type DeepPartialSkipArrayKey<T> = T extends BrowserNativeObject | NestedValue ? T : T extends ReadonlyArray<any> ? {
[K in keyof T]: DeepPartialSkipArrayKey<T[K]>;
} : {
[K in keyof T]?: DeepPartialSkipArrayKey<T[K]>;
};
/**
* Checks whether the type is any
* See {@link https://stackoverflow.com/a/49928360/3406963}
* @typeParam T - type which may be any
* ```
* IsAny<any> = true
* IsAny<string> = false
* ```
*/
export type IsAny<T> = 0 extends 1 & T ? true : false;
/**
* Checks whether the type is never
* @typeParam T - type which may be never
* ```
* IsAny<never> = true
* IsAny<string> = false
* ```
*/
export type IsNever<T> = [T] extends [never] ? true : false;
/**
* Checks whether T1 can be exactly (mutually) assigned to T2
* @typeParam T1 - type to check
* @typeParam T2 - type to check against
* ```
* IsEqual<string, string> = true
* IsEqual<'foo', 'foo'> = true
* IsEqual<string, number> = false
* IsEqual<string, number> = false
* IsEqual<string, 'foo'> = false
* IsEqual<'foo', string> = false
* IsEqual<'foo' | 'bar', 'foo'> = boolean // 'foo' is assignable, but 'bar' is not (true | false) -> boolean
* ```
*/
export type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
export type DeepMap<T, TValue> = IsAny<T> extends true ? any : T extends BrowserNativeObject | NestedValue ? TValue : T extends object ? {
[K in keyof T]: DeepMap<NonUndefined<T[K]>, TValue>;
} : TValue;
export type IsFlatObject<T extends object> = Extract<Exclude<T[keyof T], NestedValue | Date | FileList>, any[] | object> extends never ? true : false;
export type Merge<A, B> = {
[K in keyof A | keyof B]?: K extends keyof A & keyof B ? [A[K], B[K]] extends [object, object] ? Merge<A[K], B[K]> : A[K] | B[K] : K extends keyof A ? A[K] : K extends keyof B ? B[K] : never;
};
export {};
//# sourceMappingURL=utils.d.ts.map
import { Message } from './errors';
import { FieldValues } from './fields';
import { FieldPath, FieldPathValue } from './utils';
export declare type ValidationValue = boolean | number | string | RegExp;
export declare type ValidationRule<TValidationValue extends ValidationValue = ValidationValue> = TValidationValue | ValidationValueMessage<TValidationValue>;
export declare type ValidationValueMessage<TValidationValue extends ValidationValue = ValidationValue> = {
import { FieldValues, InternalFieldName } from './fields';
import { FieldPath, FieldPathValue } from './path';
export type ValidationValue = boolean | number | string | RegExp;
export type ValidationRule<TValidationValue extends ValidationValue = ValidationValue> = TValidationValue | ValidationValueMessage<TValidationValue>;
export type ValidationValueMessage<TValidationValue extends ValidationValue = ValidationValue> = {
value: TValidationValue;
message: Message;
};
export declare type ValidateResult = Message | Message[] | boolean | undefined;
export declare type Validate<TFieldValue> = (value: TFieldValue) => ValidateResult | Promise<ValidateResult>;
export declare type RegisterOptions<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{
export type ValidateResult = Message | Message[] | boolean | undefined;
export type Validate<TFieldValue, TFormValues> = (value: TFieldValue, formValues: TFormValues) => ValidateResult | Promise<ValidateResult>;
export type RegisterOptions<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{
required: Message | ValidationRule<boolean>;
min: ValidationRule<number | string>;
max: ValidationRule<number | string>;
maxLength: ValidationRule<number | string>;
minLength: ValidationRule<number | string>;
pattern: ValidationRule<RegExp>;
validate: Validate<FieldPathValue<TFieldValues, TFieldName>> | Record<string, Validate<FieldPathValue<TFieldValues, TFieldName>>>;
valueAsNumber: boolean;
valueAsDate: boolean;
maxLength: ValidationRule<number>;
minLength: ValidationRule<number>;
validate: Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues> | Record<string, Validate<FieldPathValue<TFieldValues, TFieldName>, TFieldValues>>;
value: FieldPathValue<TFieldValues, TFieldName>;
setValueAs: (value: any) => any;
shouldUnregister?: boolean;
}>;
onChange?: (event: any) => void;
onBlur?: (event: any) => void;
disabled: boolean;
deps: InternalFieldName | InternalFieldName[];
}> & ({
pattern?: ValidationRule<RegExp>;
valueAsNumber?: false;
valueAsDate?: false;
} | {
pattern?: undefined;
valueAsNumber?: false;
valueAsDate?: true;
} | {
pattern?: undefined;
valueAsNumber?: true;
valueAsDate?: false;
});
//# sourceMappingURL=validator.d.ts.map
import { FieldPath, FieldValues, UseControllerProps, UseControllerReturn } from './types';
export declare function useController<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, rules, defaultValue, control, shouldUnregister, }: UseControllerProps<TFieldValues, TName>): UseControllerReturn<TFieldValues, TName>;
/**
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
*
* @remarks
* [API](https://react-hook-form.com/api/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
*
* @param props - the path name to the form field value, and validation rules.
*
* @returns field properties, field and form state. {@link UseControllerReturn}
*
* @example
* ```tsx
* function Input(props) {
* const { field, fieldState, formState } = useController(props);
* return (
* <div>
* <input {...field} placeholder={props.name} />
* <p>{fieldState.isTouched && "Touched"}</p>
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
* </div>
* );
* }
* ```
*/
export declare function useController<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: UseControllerProps<TFieldValues, TName>): UseControllerReturn<TFieldValues, TName>;
//# sourceMappingURL=useController.d.ts.map

@@ -1,2 +0,40 @@

import { FieldValues, UseFieldArrayProps, UseFieldArrayReturn } from './types';
export declare const useFieldArray: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends import("./types").ArrayPath<TFieldValues> = import("./types").ArrayPath<TFieldValues>, TKeyName extends string = "id">({ control, name, keyName, shouldUnregister, }: UseFieldArrayProps<TFieldValues, TFieldArrayName, TKeyName>) => UseFieldArrayReturn<TFieldValues, TFieldArrayName, TKeyName>;
import { FieldArrayPath, FieldValues, UseFieldArrayProps, UseFieldArrayReturn } from './types';
/**
* A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc. • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn) • [Video](https://youtu.be/4MrbfGSFY2A)
*
* @remarks
* [API](https://react-hook-form.com/api/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
*
* @param props - useFieldArray props
*
* @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
*
* @example
* ```tsx
* function App() {
* const { register, control, handleSubmit, reset, trigger, setError } = useForm({
* defaultValues: {
* test: []
* }
* });
* const { fields, append } = useFieldArray({
* control,
* name: "test"
* });
*
* return (
* <form onSubmit={handleSubmit(data => console.log(data))}>
* {fields.map((item, index) => (
* <input key={item.id} {...register(`test.${index}.firstName`)} />
* ))}
* <button type="button" onClick={() => append({ firstName: "bill" })}>
* append
* </button>
* <input type="submit" />
* </form>
* );
* }
* ```
*/
export declare function useFieldArray<TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>, TKeyName extends string = 'id'>(props: UseFieldArrayProps<TFieldValues, TFieldArrayName, TKeyName>): UseFieldArrayReturn<TFieldValues, TFieldArrayName, TKeyName>;
//# sourceMappingURL=useFieldArray.d.ts.map
import { FieldValues, UseFormProps, UseFormReturn } from './types';
export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext extends object = object>({ mode, reValidateMode, resolver, context, defaultValues, shouldFocusError, delayError, shouldUseNativeValidation, shouldUnregister, criteriaMode, }?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues>;
/**
* Custom hook to manage the entire form.
*
* @remarks
* [API](https://react-hook-form.com/api/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
*
* @param props - form configuration and validation parameters.
*
* @returns methods - individual functions to manage the form state. {@link UseFormReturn}
*
* @example
* ```tsx
* function App() {
* const { register, handleSubmit, watch, formState: { errors } } = useForm();
* const onSubmit = data => console.log(data);
*
* console.log(watch("example"));
*
* return (
* <form onSubmit={handleSubmit(onSubmit)}>
* <input defaultValue="test" {...register("example")} />
* <input {...register("exampleRequired", { required: true })} />
* {errors.exampleRequired && <span>This field is required</span>}
* <input type="submit" />
* </form>
* );
* }
* ```
*/
export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext = any>(props?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues, TContext>;
//# sourceMappingURL=useForm.d.ts.map

@@ -0,3 +1,65 @@

/// <reference types="react" />
import { FieldValues, FormProviderProps, UseFormReturn } from './types';
/**
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
*
* @remarks
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
*
* @returns return all useForm methods
*
* @example
* ```tsx
* function App() {
* const methods = useForm();
* const onSubmit = data => console.log(data);
*
* return (
* <FormProvider {...methods} >
* <form onSubmit={methods.handleSubmit(onSubmit)}>
* <NestedInput />
* <input type="submit" />
* </form>
* </FormProvider>
* );
* }
*
* function NestedInput() {
* const { register } = useFormContext(); // retrieve all hook methods
* return <input {...register("test")} />;
* }
* ```
*/
export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues>;
export declare const FormProvider: <TFieldValues extends FieldValues>(props: FormProviderProps<TFieldValues>) => JSX.Element;
/**
* A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.
*
* @remarks
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
*
* @param props - all useFrom methods
*
* @example
* ```tsx
* function App() {
* const methods = useForm();
* const onSubmit = data => console.log(data);
*
* return (
* <FormProvider {...methods} >
* <form onSubmit={methods.handleSubmit(onSubmit)}>
* <NestedInput />
* <input type="submit" />
* </form>
* </FormProvider>
* );
* }
*
* function NestedInput() {
* const { register } = useFormContext(); // retrieve all hook methods
* return <input {...register("test")} />;
* }
* ```
*/
export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any>(props: FormProviderProps<TFieldValues, TContext>) => JSX.Element;
//# sourceMappingURL=useFormContext.d.ts.map
import { FieldValues, UseFormStateProps, UseFormStateReturn } from './types';
/**
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
*
* @remarks
* [API](https://react-hook-form.com/api/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
*
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
*
* @example
* ```tsx
* function App() {
* const { register, handleSubmit, control } = useForm({
* defaultValues: {
* firstName: "firstName"
* }});
* const { dirtyFields } = useFormState({
* control
* });
* const onSubmit = (data) => console.log(data);
*
* return (
* <form onSubmit={handleSubmit(onSubmit)}>
* <input {...register("firstName")} placeholder="First Name" />
* {dirtyFields.firstName && <p>Field is dirty.</p>}
* <input type="submit" />
* </form>
* );
* }
* ```
*/
declare function useFormState<TFieldValues extends FieldValues = FieldValues>(props?: UseFormStateProps<TFieldValues>): UseFormStateReturn<TFieldValues>;
export { useFormState };
//# sourceMappingURL=useFormState.d.ts.map

@@ -1,6 +0,49 @@

import { Control, DeepPartial, FieldPath, FieldPathValue, FieldPathValues, FieldValues, UnpackNestedValue } from './types';
import { Control, DeepPartialSkipArrayKey, FieldPath, FieldPathValue, FieldPathValues, FieldValues } from './types';
/**
* Subscribe to the entire form values change and re-render at the hook level.
*
* @remarks
*
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
*
* @param props - defaultValue, disable subscription and match exact name.
*
* @example
* ```tsx
* const { watch } = useForm();
* const values = useWatch({
* control,
* defaultValue: {
* name: "data"
* },
* exact: false,
* })
* ```
*/
export declare function useWatch<TFieldValues extends FieldValues = FieldValues>(props: {
defaultValue?: UnpackNestedValue<DeepPartial<TFieldValues>>;
defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
control?: Control<TFieldValues>;
}): UnpackNestedValue<DeepPartial<TFieldValues>>;
disabled?: boolean;
exact?: boolean;
}): DeepPartialSkipArrayKey<TFieldValues>;
/**
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
*
* @remarks
*
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
*
* @param props - defaultValue, disable subscription and match exact name.
*
* @example
* ```tsx
* const { watch } = useForm();
* const values = useWatch({
* control,
* name: "fieldA",
* defaultValue: "default value",
* exact: false,
* })
* ```
*/
export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: {

@@ -10,7 +53,49 @@ name: TFieldName;

control?: Control<TFieldValues>;
disabled?: boolean;
exact?: boolean;
}): FieldPathValue<TFieldValues, TFieldName>;
export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldNames extends FieldPath<TFieldValues>[] = FieldPath<TFieldValues>[]>(props: {
/**
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
*
* @remarks
*
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
*
* @param props - defaultValue, disable subscription and match exact name.
*
* @example
* ```tsx
* const { watch } = useForm();
* const values = useWatch({
* control,
* name: ["fieldA", "fieldB"],
* defaultValue: {
* fieldA: "data",
* fieldB: "data"
* },
* exact: false,
* })
* ```
*/
export declare function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[]>(props: {
name: readonly [...TFieldNames];
defaultValue?: UnpackNestedValue<DeepPartial<TFieldValues>>;
defaultValue?: DeepPartialSkipArrayKey<TFieldValues>;
control?: Control<TFieldValues>;
disabled?: boolean;
exact?: boolean;
}): FieldPathValues<TFieldValues, TFieldNames>;
/**
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
*
* @remarks
*
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
*
* @example
* ```tsx
* // can skip passing down the control into useWatch if the form is wrapped with the FormProvider
* const values = useWatch()
* ```
*/
export declare function useWatch<TFieldValues extends FieldValues = FieldValues>(): DeepPartialSkipArrayKey<TFieldValues>;
//# sourceMappingURL=useWatch.d.ts.map
export default function append<T>(data: T[], value: T | T[]): T[];
//# sourceMappingURL=append.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: (value: any[]) => any[];
declare const _default: <TValue>(value: TValue[]) => TValue[];
export default _default;
//# sourceMappingURL=compact.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: <T extends unknown>(value: T) => (T & any[]) | T[];
declare const _default: <T>(value: T) => (T & any[]) | T[];
export default _default;
//# sourceMappingURL=convertToArrayPayload.d.ts.map
export default function deepEqual(object1: any, object2: any): boolean;
//# sourceMappingURL=deepEqual.d.ts.map
export declare function deepMerge<T extends Record<keyof T, any>, U extends Record<keyof U, any>>(target: T, source: U): T & U;
//# sourceMappingURL=deepMerge.d.ts.map
declare const _default: <T>(value: T) => (true | Record<string, boolean>)[];
export default _default;
//# sourceMappingURL=fillBooleanArray.d.ts.map
declare const _default: <T>(value: T | T[]) => undefined[] | undefined;
export default _default;
//# sourceMappingURL=fillEmptyArray.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: <T extends unknown>(obj: T, path: string, defaultValue?: unknown) => any;
declare const _default: <T>(obj: T, path?: string, defaultValue?: unknown) => any;
export default _default;
//# sourceMappingURL=get.d.ts.map
import get from './get';
import set from './set';
export { get, set };
//# sourceMappingURL=index.d.ts.map
export default function insert<T>(data: T[], index: number): (T | undefined)[];
export default function insert<T>(data: T[], index: number, value: T | T[]): T[];
//# sourceMappingURL=insert.d.ts.map
declare const _default: (value: unknown) => value is boolean;
export default _default;
//# sourceMappingURL=isBoolean.d.ts.map
import { FieldElement } from '../types';
declare const _default: (element: FieldElement) => element is HTMLInputElement;
export default _default;
//# sourceMappingURL=isCheckBoxInput.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: (data: unknown) => boolean;
declare const _default: (value: unknown) => value is Date;
export default _default;
//# sourceMappingURL=isDateObject.d.ts.map
import { EmptyObject } from '../types';
declare const _default: (value: unknown) => value is EmptyObject;
export default _default;
//# sourceMappingURL=isEmptyObject.d.ts.map
import { FieldElement } from '../types';
declare const _default: (element: FieldElement) => element is HTMLInputElement;
export default _default;
//# sourceMappingURL=isFileInput.d.ts.map
declare const _default: (value: unknown) => value is Function;
export default _default;
//# sourceMappingURL=isFunction.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: (value: any) => value is HTMLElement;
declare const _default: (value: unknown) => value is HTMLElement;
export default _default;
//# sourceMappingURL=isHTMLElement.d.ts.map
declare const _default: (value: string) => boolean;
export default _default;
//# sourceMappingURL=isKey.d.ts.map
declare const _default: (value: unknown) => value is string;
export default _default;
//# sourceMappingURL=isMessage.d.ts.map
import { FieldElement } from '../types';
declare const _default: (element: FieldElement) => element is HTMLSelectElement;
export default _default;
//# sourceMappingURL=isMultipleSelect.d.ts.map
declare const _default: (value: unknown) => value is null | undefined;
export default _default;
//# sourceMappingURL=isNullOrUndefined.d.ts.map
export declare const isObjectType: (value: unknown) => boolean;
declare const _default: <T extends object>(value: unknown) => value is T;
export default _default;
//# sourceMappingURL=isObject.d.ts.map
import { Primitive } from '../types';
declare const _default: (value: unknown) => value is Primitive;
export default _default;
//# sourceMappingURL=isPrimitive.d.ts.map
import { FieldElement } from '../types';
declare const _default: (element: FieldElement) => element is HTMLInputElement;
export default _default;
//# sourceMappingURL=isRadioInput.d.ts.map
import { FieldElement } from '../types';
declare const _default: (ref: FieldElement) => ref is HTMLInputElement;
export default _default;
//# sourceMappingURL=isRadioOrCheckbox.d.ts.map
declare const _default: (value: unknown) => value is RegExp;
export default _default;
//# sourceMappingURL=isRegex.d.ts.map
import { FieldElement } from '../types';
declare const _default: (element: FieldElement) => element is HTMLSelectElement;
export default _default;
//# sourceMappingURL=isSelectInput.d.ts.map
declare const _default: (value: unknown) => value is string;
export default _default;
//# sourceMappingURL=isString.d.ts.map
declare const _default: (val: unknown) => val is undefined;
export default _default;
//# sourceMappingURL=isUndefined.d.ts.map
declare const _default: boolean;
export default _default;
//# sourceMappingURL=isWeb.d.ts.map
declare const _default: <T>(data: (T | undefined)[], from: number, to: number) => (T | undefined)[];
export default _default;
//# sourceMappingURL=move.d.ts.map
declare const _default: <Key extends string, T extends Record<Key, any>>(source: T, key: Key) => Omit<T, Key>;
export default _default;
//# sourceMappingURL=omit.d.ts.map
export default function prepend<T>(data: T[], value: T | T[]): T[];
//# sourceMappingURL=prepend.d.ts.map

@@ -1,2 +0,3 @@

declare const _default: <T>(data: T[], index?: number | number[] | undefined) => T[];
declare const _default: <T>(data: T[], index?: number | number[]) => T[];
export default _default;
//# sourceMappingURL=remove.d.ts.map
import { FieldValues } from '../types';
export default function set(object: FieldValues, path: string, value?: unknown): FieldValues;
//# sourceMappingURL=set.d.ts.map
declare const _default: (input: string) => string[];
export default _default;
//# sourceMappingURL=stringToPath.d.ts.map
declare const _default: <T>(data: T[], indexA: number, indexB: number) => void;
export default _default;
//# sourceMappingURL=swap.d.ts.map

@@ -1,1 +0,2 @@

export default function unset(object: any, path: string): any;
export default function unset(object: any, path: string | (string | number)[]): any;
//# sourceMappingURL=unset.d.ts.map
{
"name": "react-hook-form",
"description": "Performant, flexible and extensible forms library for React Hooks",
"version": "7.12.2",
"version": "7.43.9",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"module": "dist/index.esm.mjs",
"umd:main": "dist/index.umd.js",
"unpkg": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"jsnext:main": "dist/index.esm.js",
"jsnext:main": "dist/index.esm.mjs",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"sideEffects": true,
"sideEffects": false,
"files": [

@@ -21,3 +21,4 @@ "dist",

".": {
"import": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.mjs",
"require": "./dist/index.cjs.js"

@@ -28,25 +29,27 @@ }

"clean": "rimraf dist",
"prebuild": "yarn clean",
"build": "yarn build:modern && yarn cp:dts",
"prebuild": "pnpm clean",
"build": "pnpm build:modern",
"build:watch": "pnpm build:modern -w",
"postbuild": "rimraf dist/__tests__ && node ./scripts/rollup/assert-esm-exports.mjs && node ./scripts/rollup/assert-cjs-exports.cjs",
"build:modern": "rollup -c ./scripts/rollup/rollup.config.js",
"build:esm": "rollup -c ./scripts/rollup/rollup.esm.config.js",
"cp:dts": "copyfiles -f ./src/**/*.d.ts dist && rimraf dist/__tests__",
"prettier:fix": "prettier --config .prettierrc --write \"**/*.{ts,tsx}\"",
"prettier:fix": "prettier --config .prettierrc --write \"**/*.{js,ts,tsx,css}\"",
"lint": "eslint '**/*.{js,ts,tsx}'",
"lint:fix": "yarn lint -- --fix",
"lint:types": "tsc --noEmit",
"coverage": "jest --coverage --coverageReporters=text-lcov",
"lint:fix": "pnpm lint --fix",
"type": "tsc --noEmit",
"jest-preview": "jest-preview",
"test": "jest --config ./scripts/jest/jest.config.js",
"test:coverage": "yarn test -- --coverage",
"test:watch": "yarn test -- --onlyChanged --watch",
"test:web": "TEST_ENV=web yarn test",
"test:server": "TEST_ENV=server yarn test",
"test:native": "TEST_ENV=native yarn test",
"cypress": "cypress run",
"cypress:open": "cypress open",
"cypress:parallel": "cypress-parallel -s cypress -t 4 -d -a",
"test:coverage": "pnpm test -- --coverage",
"test:watch": "pnpm test -- --onlyChanged --watch",
"test:web": "TEST_ENV=web pnpm test",
"test:type": "tsd src/__typetest__",
"e2e": "cypress run",
"e2e:watch": "cypress open",
"api-extractor": "api-extractor run --local",
"api-extractor:build": "pnpm build:esm && pnpm api-extractor",
"api-extractor:ci": "node scripts/apiExtractor.js",
"postversion": "git push && git push origin v$npm_package_version",
"prepublishOnly": "yarn && yarn lint:fix && yarn lint:types && yarn test && yarn build",
"bundlesize": "yarn build:modern && bundlesize",
"start:app": "yarn build:esm && yarn link && yarn --cwd node_modules/react link && yarn --cwd ./app link react react-hook-form && yarn --cwd ./app && yarn --cwd ./app run dev"
"prepublishOnly": "pnpm install && pnpm lint:fix && pnpm type && pnpm test && pnpm build",
"bundlewatch": "pnpm build:modern && bundlewatch",
"start": "pnpm build:esm && pnpm --dir ./app install && pnpm --dir ./app run dev"
},

@@ -71,62 +74,58 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^7.0.1",
"@testing-library/react-native": "^7.2.0",
"@types/jest": "^26.0.24",
"@types/react": "^17.0.14",
"@types/react-dom": "^17.0.9",
"@types/react-native": "^0.64.12",
"@types/react-test-renderer": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"@vitejs/plugin-react-refresh": "^1.3.5",
"babel-jest": "^27.0.6",
"bundlesize": "^0.18.0",
"copyfiles": "^2.4.1",
"cypress": "7.7.0",
"cypress-parallel": "^0.3.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.11.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"jest-performance-testing": "^1.0.0",
"lint-staged": "^11.0.1",
"prettier": "^2.3.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-native": "^0.64.2",
"react-test-renderer": "^17.0.1",
"@microsoft/api-extractor": "^7.33.7",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.1.0",
"@swc/core": "^1.3.25",
"@swc/jest": "^0.2.24",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react-hooks": "^8.0.1",
"@types/jest": "^29.5.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"bundlewatch": "^0.3.3",
"cypress": "10.9.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^8.0.0",
"husky": "^8.0.3",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-preview": "^0.3.1",
"lint-staged": "^13.1.0",
"prettier": "^2.8.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.53.1",
"rollup": "^2.79.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^27.0.3",
"typescript": "^4.3.5"
"rollup-plugin-typescript2": "^0.34.1",
"tsd": "^0.27.0",
"typescript": "5.0.2"
},
"resolutions": {
"react-native/@jest/create-cache-key-function": "^27.0.2"
"bundlewatch": {
"files": [
{
"path": "./dist/index.cjs.js",
"maxSize": "9.2 kB"
}
]
},
"bundlesize": [
{
"path": "./dist/index.cjs.js",
"maxSize": "9.5 kB"
}
],
"peerDependencies": {
"react": "^16.8.0 || ^17"
"react": "^16.8.0 || ^17 || ^18"
},
"lint-staged": {
"*.{js,ts,tsx}": [
"yarn lint:fix",
"yarn prettier:fix"
"pnpm lint:fix",
"pnpm prettier:fix"
],

@@ -145,3 +144,7 @@ "*.{md,json,yml}": [

"url": "https://opencollective.com/react-hook-form"
}
},
"engines": {
"node": ">=12.22.0"
},
"packageManager": "pnpm@7.18.0"
}

@@ -8,9 +8,3 @@ <div align="center">

<div align="center">
<a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
<img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/v7_example.gif" alt="React Hook Form video - React custom hook for form validation" width="100%" />
</a>
</div>
<div align="center">
[![npm downloads](https://img.shields.io/npm/dm/react-hook-form.svg?style=for-the-badge)](https://www.npmjs.com/package/react-hook-form)

@@ -23,30 +17,25 @@ [![npm](https://img.shields.io/npm/dt/react-hook-form.svg?style=for-the-badge)](https://www.npmjs.com/package/react-hook-form)

Version 7 | [Version 6](/docs/README.V6.md)
<p align="center">
<a href="https://react-hook-form.com/get-started">Get started</a> |
<a href="https://react-hook-form.com/api">API</a> |
<a href="https://react-hook-form.com/form-builder">Form Builder</a> |
<a href="https://react-hook-form.com/faqs">FAQs</a> |
<a href="https://github.com/bluebill1049/react-hook-form/tree/master/examples">Examples</a>
</p>
## Features
### Features
- Built with performance, UX and DX in mind
- Embraces native form validation
- Embraces native HTML form [validation](https://react-hook-form.com/get-started#Applyvalidation)
- Out of the box integration with [UI libraries](https://codesandbox.io/s/react-hook-form-v7-controller-5h1q5)
- [Small size](https://bundlephobia.com/result?p=react-hook-form@latest) and no [dependencies](./package.json)
- Follows HTML standard for [validation](https://react-hook-form.com/get-started#Applyvalidation)
- Support [Yup](https://github.com/jquense/yup), [Zod](https://github.com/vriad/zod), [Superstruct](https://github.com/ianstormtaylor/superstruct), [Joi](https://github.com/hapijs/joi), [Vest](https://github.com/ealush/vest), [class-validator](https://github.com/typestack/class-validator), [io-ts](https://github.com/gcanti/io-ts), [nope](https://github.com/bvego/nope-validator) or custom
- Support [Yup](https://github.com/jquense/yup), [Zod](https://github.com/colinhacks/zod), [AJV](https://github.com/ajv-validator/ajv), [Superstruct](https://github.com/ianstormtaylor/superstruct), [Joi](https://github.com/hapijs/joi) and [others](https://github.com/react-hook-form/resolvers)
## Install
### Install
npm install react-hook-form
## Links
### Quickstart
- [Get started](https://react-hook-form.com/get-started)
- [API](https://react-hook-form.com/api)
- [Examples](https://github.com/bluebill1049/react-hook-form/tree/master/examples)
- [Demo](https://react-hook-form.com)
- [Form Builder](https://react-hook-form.com/form-builder)
- [FAQs](https://react-hook-form.com/faqs)
## Quickstart
```jsx
import React from 'react';
import { useForm } from 'react-hook-form';

@@ -60,7 +49,6 @@

} = useForm();
const onSubmit = (data) => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('firstName')} /> {/* register an input */}
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input {...register('firstName')} />
<input {...register('lastName', { required: true })} />

@@ -80,231 +68,27 @@ {errors.lastName && <p>Last name is required.</p>}

## Sponsors
### Sponsors
Thanks go to these kind and lovely sponsors (companies and individuals)!
Thanks go to these kind and lovely sponsors!
<a href="https://underbelly.is/" target="_blank">
<img src="https://images.opencollective.com/underbelly/989a4a6/logo/256.png" width="94" height="94" />
<a target="_blank" href='https://wantedlyinc.com'>
<img width="94" src="https://images.opencollective.com/wantedly/d94e44e/logo/256.png" />
</a>
<a href="https://www.leniolabs.com/" target="_blank">
<img src="https://images.opencollective.com/leniolabs_/63e9b6e/logo/256.png" width="94" height="94" />
<a target="_blank" href='https://toss.im'>
<img width="94" src="https://images.opencollective.com/toss/3ed69b3/logo/256.png" />
</a>
<a href="https://graphcms.com/" target="_blank">
<img src="https://avatars.githubusercontent.com/u/31031438?s=200&v=4" width="94" height="94" />
<a target="_blank" href="https://graphcms.com">
<img width="94" src="https://avatars.githubusercontent.com/u/31031438" />
</a>
<a target="_blank" href="https://www.beekai.com/">
<img width="94" src="https://www.beekai.com/marketing/logo/logo.svg" />
</a>
<a target="_blank" href="https://kanamekey.com">
<img width="94" src="https://images.opencollective.com/kaname/d15fd98/logo/256.png" />
</a>
<a target="_blank" href="https://formcarry.com/">
<img width="94" src="https://images.opencollective.com/formcarry/a40a4ea/logo/256.png" />
</a>
<p>
<a href="https://github.com/sayav"
><img
src="https://avatars1.githubusercontent.com/u/42376060?s=60&amp;v=4"
width="45"
height="45"
alt="@sayav"
/></a>
<a href="https://github.com/lemcii"
><img
src="https://avatars1.githubusercontent.com/u/35668113?s=60&amp;v=4"
width="45"
height="45"
alt="@lemcii"
/></a>
<a href="https://github.com/washingtonsoares"
><img
src="https://avatars.githubusercontent.com/u/5726140?v=4"
width="45"
height="45"
alt="@washingtonsoares"
/></a>
<a href="https://github.com/lixunn"
><img
src="https://avatars.githubusercontent.com/u/4017964?v=4"
width="45"
height="45"
alt="@lixunn"
/></a>
<a href="https://github.com/SamSamskies"
><img
src="https://avatars2.githubusercontent.com/u/3655410?s=60&amp;v=4"
width="45"
height="45"
alt="@SamSamskies"
/></a>
<a href="https://github.com/peaonunes"
><img
src="https://avatars2.githubusercontent.com/u/3356720?s=60&amp;v=4"
width="45"
height="45"
alt="@peaonunes"
/></a>
<a href="https://github.com/wilhelmeek"
><img
src="https://avatars2.githubusercontent.com/u/609452?s=60&amp;v=4"
width="45"
height="45"
alt="@wilhelmeek"
/></a>
<a href="https://github.com/iwarner"
><img
src="https://avatars2.githubusercontent.com/u/279251?s=60&amp;v=4"
width="45"
height="45"
alt="@iwarner"
/></a>
<a href="https://github.com/joejknowles"
><img
src="https://avatars2.githubusercontent.com/u/10728145?s=60&amp;v=4"
width="45"
height="45"
alt="@joejknowles"
/></a>
<a href="https://github.com/chris-gunawardena"
><img
src="https://avatars0.githubusercontent.com/u/5763108?s=60&amp;v=4"
width="45"
height="45"
alt="@chris-gunawardena"
/></a>
<a href="https://github.com/Tymek"
><img
src="https://avatars1.githubusercontent.com/u/2625371?s=60&amp;v=4"
width="45"
height="45"
alt="@Tymek"
/></a>
<a href="https://github.com/Luchanso"
><img
src="https://avatars0.githubusercontent.com/u/2098777?s=60&amp;v=4"
width="45"
height="45"
alt="@Luchanso"
/></a>
<a href="https://github.com/vcarel"
><img
src="https://avatars1.githubusercontent.com/u/1541093?s=60&amp;v=4"
width="45"
height="45"
alt="@vcarel"
/></a>
<a href="https://github.com/gragland"
><img
src="https://avatars0.githubusercontent.com/u/1481077?s=60&amp;v=4"
width="45"
height="45"
alt="@gragland"
/></a>
<a href="https://github.com/tjshipe"
><img
src="https://avatars2.githubusercontent.com/u/1254942?s=60&amp;v=4"
width="45"
height="45"
alt="@tjshipe"
/></a>
<a href="https://github.com/krnlde"
><img
src="https://avatars1.githubusercontent.com/u/1087002?s=60&amp;v=4"
width="45"
height="45"
alt="@krnlde"
/></a>
<a href="https://github.com/msutkowski"
><img
src="https://avatars2.githubusercontent.com/u/784953?s=60&amp;v=4"
width="45"
height="45"
alt="@msutkowski"
/></a>
<a href="https://github.com/mlukaszczyk"
><img
src="https://avatars3.githubusercontent.com/u/599247?s=60&amp;v=4"
width="45"
height="45"
alt="@mlukaszczyk"
/></a>
<a href="https://github.com/susshma"
><img
src="https://avatars0.githubusercontent.com/u/2566818?s=460&u=754ee26b96e321ff28dbc4a2744132015f534fe0&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/MatiasCiccone"
><img
src="https://avatars3.githubusercontent.com/u/32602795?s=460&u=6a0c4dbe23c4f9a5628dc8867842b75989ecc4aa&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/ghostwriternr"
><img
src="https://avatars0.githubusercontent.com/u/10023615?s=460&u=3ec1e4ba991699762fd22a9d9ef47a0599f937dc&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/neighborhood999"
><img
src="https://avatars3.githubusercontent.com/u/10325111?s=450&u=f60c932f81d95a60f77f5c7f2eab4590e07c29af&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/yjp20"
><img
src="https://avatars3.githubusercontent.com/u/44457064?s=460&u=a55119c84e0167f6a3f830dbad3133b28f0c0a8f&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/samantha-wong"
><img
src="https://avatars.githubusercontent.com/u/19571028?s=460&u=7421a02f600646b5836d5973359a257950cae8c4&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/msc-insure"
><img
src="https://avatars.githubusercontent.com/u/44406870?s=200&v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/ccheney"
><img
src="https://avatars.githubusercontent.com/u/302437?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/artischockee"
><img
src="https://avatars.githubusercontent.com/u/22125223?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/tsongas"
><img
src="https://avatars.githubusercontent.com/u/2079598?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/knoefel"
><img
src="https://avatars.githubusercontent.com/u/2396344?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/JGibel"
><img
src="https://avatars.githubusercontent.com/u/1953965?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/gpalrepo"
><img
src="https://avatars.githubusercontent.com/u/41862257?v=4"
width="45"
height="45"
/></a>
<a href="https://github.com/pjsachdev"
><img
src="https://avatars.githubusercontent.com/u/43356139?v=4"
width="45"
height="45"
/></a>
</p>
### Backers
## Backers
Thanks go to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)].

@@ -316,12 +100,4 @@

## Organizations
### Contributors
Thanks go to these wonderful organizations! [[Contribute](https://opencollective.com/react-hook-form/contribute)].
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
<img src="https://opencollective.com/react-hook-form/organizations.svg?width=890" />
</a>
## Contributors
Thanks go to these wonderful people! [[Become a contributor](CONTRIBUTING.md)].

@@ -328,0 +104,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc