Socket
Socket
Sign inDemoInstall

react-hook-form

Package Overview
Dependencies
3
Maintainers
1
Versions
1026
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.45.4 to 7.46.0-next.0

dist/logic/iterateFieldsByAction.d.ts

13

dist/constants.d.ts

@@ -17,2 +17,15 @@ import { ValidationMode } from './types';

};
export declare const FORM_DEFAULT_STATE: {
isDirty: boolean;
isValidating: boolean;
isSubmitted: boolean;
isSubmitting: boolean;
isSubmitSuccessful: boolean;
isValid: boolean;
submitCount: number;
dirtyFields: {};
touchedFields: {};
errors: {};
disabled: boolean;
};
//# sourceMappingURL=constants.d.ts.map

2

dist/index.cjs.js

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

"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 o=e=>!a(e)&&!Array.isArray(e)&&n(e)&&!s(e),u=e=>o(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,i=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>{const t=e.constructor&&e.constructor.prototype;return o(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&&!o(e))return e;if(t=r?[]:{},r||l(e))for(const r in e)e.hasOwnProperty(r)&&(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||!o(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"},h={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},g="max",_="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]!==h.all&&(t._proxyFormState[a]=!s||h.all),r&&(r[a]=!0),e[a]}});return a},k=e=>o(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||h.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 E(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 j(e){const r=S(),{control:s=r.control,disabled:a,name:n,exact:o}=e||{},[u,i]=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,E({disabled:a,next:e=>l.current&&O(d.current,e.name,o)&&D(e,c.current,s._updateFormState)&&i({...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 T=e=>"string"==typeof e,U=(e,t,r,s,a)=>T(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 B(e){const r=S(),{control:s=r.control,name:a,defaultValue:n,disabled:o,exact:u}=e||{},i=t.default.useRef(a);i.current=a,E({disabled:o,subject:s._subjects.values,next:e=>{O(i.current,e.name,u)&&c(d(U(i.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=o(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,o=i(a._names.array,s),l=B({control:a,name:s,defaultValue:y(a._formValues,s,y(a._defaultValues,s,e.defaultValue)),exact:!0}),c=j({control:a,name:s}),f=t.default.useRef(a.register(s,{...e.rules,value:l}));return f.current=a.register(s,e.rules),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()=>{(o?e&&!a._state.action:e)?a.unregister(s):t(s,!1)}}),[s,a,o,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)}})}}const P="post";var q=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{};const W=(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 o(s)&&W(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)}))},H=(e,t,r={})=>r.shouldFocus||m(r.shouldFocus)?r.focusName||`${e}.${m(r.focusIndex)?t:r.focusIndex}.`:"",I=e=>({isOnSubmit:!e||e===h.onSubmit,isOnBlur:e===h.onBlur,isOnChange:e===h.onChange,isOnAll:e===h.all,isOnTouch:e===h.onTouched}),G=(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=f(y(e,r));return M(s,"root",t[r]),M(e,r,s),e},z=e=>"boolean"==typeof e,K=e=>"file"===e.type,Q=e=>"function"==typeof e,X=e=>{if(!c)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Y=e=>T(e),Z=e=>"radio"===e.type,ee=e=>e instanceof RegExp;const te={value:!1,isValid:!1},re={value:!0,isValid:!0};var se=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?re:{value:e[0].value,isValid:!0}:re:te}return te};const ae={isValid:!1,value:null};var ne=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ae):ae;function oe(e,t,r="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||z(e)&&!e)return{type:r,message:Y(e)?e:"",ref:t}}var ue=e=>o(e)&&!ee(e)?e:{value:e,message:""},ie=async(e,t,s,n,u)=>{const{ref:i,refs:l,required:c,maxLength:d,minLength:f,min:p,max:h,pattern:F,validate:S,name:w,valueAsNumber:D,mount:C,disabled:O}=e._f,E=y(t,w);if(!C||O)return{};const j=l?l[0]:i,U=e=>{n&&j.reportValidity&&(j.setCustomValidity(z(e)?"":e||""),j.reportValidity())},B={},L=Z(i),N=r(i),M=L||N,R=(D||K(i))&&m(i.value)&&m(E)||X(i)&&""===i.value||""===E||Array.isArray(E)&&!E.length,P=q.bind(null,w,s,B),W=(e,t,r,s=v,a=b)=>{const n=e?t:r;B[w]={type:e?s:a,message:n,ref:i,...P(e?s:a,n)}};if(u?!Array.isArray(E)||!E.length:c&&(!M&&(R||a(E))||z(E)&&!E||N&&!se(l).isValid||L&&!ne(l).isValid)){const{value:e,message:t}=Y(c)?{value:!!c,message:c}:ue(c);if(e&&(B[w]={type:A,message:t,ref:j,...P(A,t)},!s))return U(t),B}if(!(R||a(p)&&a(h))){let e,t;const r=ue(h),n=ue(p);if(a(E)||isNaN(E)){const s=i.valueAsDate||new Date(E),a=e=>new Date((new Date).toDateString()+" "+e),o="time"==i.type,u="week"==i.type;T(r.value)&&E&&(e=o?a(E)>a(r.value):u?E>r.value:s>new Date(r.value)),T(n.value)&&E&&(t=o?a(E)<a(n.value):u?E<n.value:s<new Date(n.value))}else{const s=i.valueAsNumber||(E?+E:E);a(r.value)||(e=s>r.value),a(n.value)||(t=s<n.value)}if((e||t)&&(W(!!e,r.message,n.message,g,_),!s))return U(B[w].message),B}if((d||f)&&!R&&(T(E)||u&&Array.isArray(E))){const e=ue(d),t=ue(f),r=!a(e.value)&&E.length>+e.value,n=!a(t.value)&&E.length<+t.value;if((r||n)&&(W(r,e.message,t.message),!s))return U(B[w].message),B}if(F&&!R&&T(E)){const{value:e,message:t}=ue(F);if(ee(e)&&!E.match(e)&&(B[w]={type:x,message:t,ref:i,...P(x,t)},!s))return U(t),B}if(S)if(Q(S)){const e=oe(await S(E,t),j);if(e&&(B[w]={...e,...P(V,e.message)},!s))return U(e.message),B}else if(o(S)){let e={};for(const r in S){if(!k(e)&&!s)break;const a=oe(await S[r](E,t),j,r);a&&(e={...a,...P(r,a.message)},U(a.message),s&&(B[w]=e))}if(!k(e)&&(B[w]={ref:j,...e},!s))return B}return U(!0),B};function le(e,t){return[...e,...C(t)]}var ce=e=>Array.isArray(e)?e.map((()=>{})):void 0;function de(e,t,r){return[...e.slice(0,t),...C(r),...e.slice(t)]}var fe=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function me(e,t){return[...C(t),...C(e)]}var ye=(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))),pe=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function he(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&&(o(s)&&k(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!m(e[t]))return!1;return!0}(s))&&he(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 ve=e=>a(e)||!n(e);function be(e,t){if(ve(e)||ve(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)||o(r)&&o(e)||Array.isArray(r)&&Array.isArray(e)?!be(r,e):r!==e)return!1}}return!0}var xe=e=>"select-multiple"===e.type,Ae=e=>Z(e)||r(e),Ve=e=>X(e)&&e.isConnected,Fe=e=>{for(const t in e)if(Q(e[t]))return!0;return!1};function Se(e,t={}){const r=Array.isArray(e);if(o(e)||r)for(const r in e)Array.isArray(e[r])||o(e[r])&&!Fe(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Se(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function we(e,t,r){const s=Array.isArray(e);if(o(e)||s)for(const s in e)Array.isArray(e[s])||o(e[s])&&!Fe(e[s])?m(t)||ve(r[s])?r[s]=Array.isArray(e[s])?Se(e[s],[]):{...Se(e[s])}:we(e[s],a(t)?{}:t[s],r[s]):r[s]=!be(e[s],t[s]);return r}var ke=(e,t)=>we(e,t,Se(t)),De=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&T(e)?new Date(e):s?s(e):e;function Ce(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return K(t)?t.files:Z(t)?ne(e.refs).value:xe(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?se(e.refs).value:De(m(t.value)?e.ref.value:t.value,e)}var Oe=(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}},Ee=e=>m(e)?e:ee(e)?e.source:o(e)?ee(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 Te(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),o=y(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(o&&o.type)return{name:s,error:o};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&&he(e,t);const Le={mode:h.onSubmit,reValidateMode:h.onChange,shouldFocusError:!0};function Ne(e={},t){let n,l={...Le,...e},g={submitCount:0,isDirty:!1,isLoading:Q(l.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},_={},v=(o(l.defaultValues)||o(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=I(l.mode),O=I(l.reValidateMode),E=l.criteriaMode===h.all,j=async e=>{if(F.isValid||e){const e=l.resolver?k((await P()).errors):await q(_,!0);e!==g.isValid&&S.state.next({isValid:e})}},B=e=>F.isValidating&&S.state.next({isValidating:e}),L=(e,t,r,s)=>{const a=y(_,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:Ce(a._f)):Y(e,n),x.mount&&j()}},N=(e,t,r,s,a)=>{let n=!1,o=!1;const u={name:e};if(!r||s){F.isDirty&&(o=g.isDirty,g.isDirty=u.isDirty=$(),n=o!==u.isDirty);const r=be(y(v,e),t);o=y(g.dirtyFields,e),r?he(g.dirtyFields,e):M(g.dirtyFields,e,!0),u.dirtyFields=g.dirtyFields,n=n||F.dirtyFields&&o!==!r}if(r){const t=y(g.touchedFields,e);t||(M(g.touchedFields,e,r),u.touchedFields=g.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(u),n?u:{}},R=(t,r,s,a)=>{const o=y(g.errors,t),u=F.isValid&&z(r)&&g.isValid!==r;var i;if(e.delayError&&s?(i=()=>((e,t)=>{M(g.errors,e,t),S.state.next({errors:g.errors})})(t,s),n=e=>{clearTimeout(V),V=setTimeout(i,e)},n(e.delayError)):(clearTimeout(V),n=null,s?M(g.errors,t,s):he(g.errors,t)),(s?!be(o,s):o)||!k(a)||u){const e={...a,...u&&z(r)?{isValid:r}:{},errors:g.errors,name:t};g={...g,...e},S.state.next(e)}B(!1)},P=async e=>l.resolver(b,l.context,Oe(e||A.mount,_,l.criteriaMode,l.shouldUseNativeValidation)),q=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 ie(a,b,E,l.shouldUseNativeValidation&&!t,s);if(n[e.name]&&(r.valid=!1,t))break;!t&&(y(n,e.name)?s?J(g.errors,n,e.name):M(g.errors,e.name,n[e.name]):he(g.errors,e.name))}s&&await q(s,t,r)}}return r.valid},$=(e,t)=>(e&&t&&M(b,e,t),!be(se(),v)),H=(e,t,r)=>U(e,A,{...x.mount?b:m(t)?v:T(e)?{[e]:t}:t},r,t),Y=(e,t,s={})=>{const n=y(_,e);let o=t;if(n){const s=n._f;s&&(!s.disabled&&M(b,e,De(t,s)),o=X(s.ref)&&a(t)?"":t,xe(s.ref)?[...s.ref.options].forEach((e=>e.selected=o.includes(e.value))):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(o)?!!o.find((t=>t===e.value)):o===e.value))):s.refs[0]&&(s.refs[0].checked=!!o):s.refs.forEach((e=>e.checked=e.value===o)):K(s.ref)?s.ref.value="":(s.ref.value=o,s.ref.type||S.values.next({name:e,values:{...b}})))}(s.shouldDirty||s.shouldTouch)&&N(e,o,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&re(e)},Z=(e,t,r)=>{for(const a in t){const n=t[a],o=`${e}.${a}`,u=y(_,o);!A.array.has(e)&&ve(n)&&(!u||u._f)||s(n)?Y(o,n,r):Z(o,n,r)}},ee=(e,r,s={})=>{const n=y(_,e),o=A.array.has(e),u=d(r);M(b,e,u),o?(S.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:ke(v,b),isDirty:$(e,u)})):!n||n._f||a(u)?Y(e,u,s):Z(e,u,s),G(e,A)&&S.state.next({...g}),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(_,r);if(a){let o,i;const c=t.type?Ce(a._f):u(e),d=e.type===p.BLUR||e.type===p.FOCUS_OUT,f=!je(a._f)&&!l.resolver&&!y(g.errors,r)&&!a._f.deps||Ue(d,y(g.touchedFields,r),g.isSubmitted,O,D),m=G(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 h=N(r,c,d,!1),v=!k(h)||m;if(!d&&S.values.next({name:r,type:e.type,values:{...b}}),f)return F.isValid&&j(),v&&S.state.next({name:r,...m?{}:h});if(!d&&m&&S.state.next({...g}),B(!0),l.resolver){const{errors:e}=await P([r]),t=Te(g.errors,_,r),s=Te(e,_,t.name||r);o=s.error,r=s.name,i=k(e)}else o=(await ie(a,b,E,l.shouldUseNativeValidation))[r],s=isNaN(c)||c===y(b,r,c),s&&(o?i=!1:F.isValid&&(i=await q(_,!0)));s&&(a._f.deps&&re(a._f.deps),R(r,i,o,h))}},re=async(e,t={})=>{let r,s;const a=C(e);if(B(!0),l.resolver){const t=await(async e=>{const{errors:t}=await P();if(e)for(const r of e){const e=y(t,r);e?M(g.errors,r,e):he(g.errors,r)}else g.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(_,e);return await q(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||g.isValid)&&j()):s=r=await q(_);return S.state.next({...!T(e)||F.isValid&&r!==g.isValid?{}:{name:e},...l.resolver||!e?{isValid:r}:{},errors:g.errors,isValidating:!1}),t.shouldFocus&&!s&&W(_,(e=>e&&y(g.errors,e)),e?a:A.mount),s},se=e=>{const t={...v,...x.mount?b:{}};return m(e)?t:T(e)?y(t,e):e.map((e=>y(t,e)))},ae=(e,t)=>({invalid:!!y((t||g).errors,e),isDirty:!!y((t||g).dirtyFields,e),isTouched:!!y((t||g).touchedFields,e),error:y((t||g).errors,e)}),ne=(e,t,r)=>{const s=(y(_,e,{_f:{}})._f||{}).ref;M(g.errors,e,{...t,ref:s}),S.state.next({name:e,errors:g.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},oe=(e,t={})=>{for(const r of e?C(e):A.mount)A.mount.delete(r),A.array.delete(r),t.keepValue||(he(_,r),he(b,r)),!t.keepError&&he(g.errors,r),!t.keepDirty&&he(g.dirtyFields,r),!t.keepTouched&&he(g.touchedFields,r),!l.shouldUnregister&&!t.keepDefaultValue&&he(v,r);S.values.next({values:{...b}}),S.state.next({...g,...t.keepDirty?{isDirty:$()}:{}}),!t.keepIsValid&&j()},ue=(e,t={})=>{let r=y(_,e);const s=z(t.disabled);return M(_,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,Ce(r._f))):L(e,!0,t.value),{...s?{disabled:t.disabled}:{},...l.progressive?{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:s=>{if(s){ue(e,t),r=y(_,e);const a=m(s.value)&&s.querySelectorAll&&s.querySelectorAll("input,select,textarea")[0]||s,n=Ae(a),o=r._f.refs||[];if(n?o.find((e=>e===a)):a===r._f.ref)return;M(_,e,{_f:{...r._f,...n?{refs:[...o.filter(Ve),a,...Array.isArray(y(v,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),L(e,!1,void 0,a)}else r=y(_,e,{}),r._f&&(r._f.mount=!1),(l.shouldUnregister||t.shouldUnregister)&&(!i(A.array,e)||!x.action)&&A.unMount.add(e)}}},le=()=>l.shouldFocusError&&W(_,(e=>e&&y(g.errors,e)),A.mount),ce=(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 P();g.errors=e,s=t}else await q(_);he(g.errors,"root"),k(g.errors)?(S.state.next({errors:{}}),await e(s,r)):(t&&await t({...g.errors},r),le(),setTimeout(le)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:k(g.errors),submitCount:g.submitCount+1,errors:g.errors})},de=(r,s={})=>{const a=r||v,n=d(a),o=r&&!k(r)?n:v;if(s.keepDefaultValues||(v=a),!s.keepValues){if(s.keepDirtyValues||w)for(const e of A.mount)y(g.dirtyFields,e)?M(o,e,y(b,e)):ee(e,y(o,e));else{if(c&&m(r))for(const e of A.mount){const t=y(_,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(X(e)){const t=e.closest("form");if(t){t.reset();break}}}}_={}}b=e.shouldUnregister?s.keepDefaultValues?d(v):{}:d(o),S.array.next({values:{...o}}),S.values.next({values:{...o}})}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?g.submitCount:0,isDirty:s.keepDirty?g.isDirty:!(!s.keepDefaultValues||be(r,v)),isSubmitted:!!s.keepIsSubmitted&&g.isSubmitted,dirtyFields:s.keepDirtyValues?g.dirtyFields:s.keepDefaultValues&&r?ke(v,r):{},touchedFields:s.keepTouched?g.touchedFields:{},errors:s.keepErrors?g.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},fe=(e,t)=>de(Q(e)?e(b):e,t);return{control:{register:ue,unregister:oe,getFieldState:ae,handleSubmit:ce,setError:ne,_executeSchema:P,_getWatch:H,_getDirty:$,_updateValid:j,_removeUnmounted:()=>{for(const e of A.unMount){const t=y(_,e);t&&(t._f.refs?t._f.refs.every((e=>!Ve(e))):!Ve(t._f.ref))&&oe(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(_,e))){const t=r(y(_,e),s.argA,s.argB);a&&M(_,e,t)}if(n&&Array.isArray(y(g.errors,e))){const t=r(y(g.errors,e),s.argA,s.argB);a&&M(g.errors,e,t),Be(g.errors,e)}if(F.touchedFields&&n&&Array.isArray(y(g.touchedFields,e))){const t=r(y(g.touchedFields,e),s.argA,s.argB);a&&M(g.touchedFields,e,t)}F.dirtyFields&&(g.dirtyFields=ke(v,b)),S.state.next({name:e,isDirty:$(e,t),dirtyFields:g.dirtyFields,errors:g.errors,isValid:g.isValid})}else M(b,e,t)},_getFieldArray:t=>f(y(x.mount?b:v,t,e.shouldUnregister?y(v,t,[]):[])),_reset:de,_resetDefaultValues:()=>Q(l.defaultValues)&&l.defaultValues().then((e=>{fe(e,l.resetOptions),S.state.next({isLoading:!1})})),_updateFormState:e=>{g={...g,...e}},_subjects:S,_proxyFormState:F,get _fields(){return _},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 g},set _formState(e){g=e},get _options(){return l},set _options(e){l={...l,...e}}},trigger:re,register:ue,handleSubmit:ce,watch:(e,t)=>Q(e)?S.values.subscribe({next:r=>e(H(void 0,t),r)}):H(e,t,!0),setValue:ee,getValues:se,reset:fe,resetField:(e,t={})=>{y(_,e)&&(m(t.defaultValue)?ee(e,y(v,e)):(ee(e,t.defaultValue),M(v,e,t.defaultValue)),t.keepTouched||he(g.touchedFields,e),t.keepDirty||(he(g.dirtyFields,e),g.isDirty=t.defaultValue?$(e,y(v,e)):$()),t.keepError||(he(g.errors,e),F.isValid&&j()),S.state.next({...g}))},clearErrors:e=>{e&&C(e).forEach((e=>he(g.errors,e))),S.state.next({errors:e?g.errors:{}})},unregister:oe,setError:ne,setFocus:(e,t={})=>{const r=y(_,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.Form=function(e){const r=S(),[s,a]=t.default.useState(!1),{control:n=r.control,onSubmit:o,children:u,action:i,method:l=P,headers:c,encType:d,onError:f,render:m,onSuccess:p,validateStatus:h,...g}=e,_=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,y(e,t));if(o&&await o({data:e,event:t,method:l,formData:a,formDataJson:u}),i)try{const e=[c&&c["Content-Type"],d].some((e=>e&&e.includes("json"))),t=await fetch(i,{method:l,headers:{...c,...d?{"Content-Type":d}:{}},body:e?u:a});t&&(h?!h(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):p&&p({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return t.default.useEffect((()=>{a(!0)}),[]),m?t.default.createElement(t.default.Fragment,null,m({submit:_})):t.default.createElement("form",{noValidate:s,action:i,method:l,encType:d,onSubmit:_,...g},u)},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:o}=e,[u,i]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map($)),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),E({next:({values:e,name:t})=>{if(t===f.current||!t){const t=y(e,f.current);Array.isArray(t)&&(i(t),l.current=t.map($))}},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,G(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!I(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&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?M(s._formState.errors,a,t):he(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=y(s._fields,a);e&&e._f&&ie(e,s._formValues,s._options.criteriaMode===h.all,s._options.shouldUseNativeValidation,!0).then((e=>!k(e)&&s._subjects.state.next({errors:J(s._formState.errors,e,a)})))}s._subjects.values.next({name:a,values:{...s._formValues}}),s._names.focus&&W(s._fields,(e=>!!e&&e.startsWith(s._names.focus||""))),s._names.focus="",s._updateValid(),m.current=!1}),[u,a,s]),t.default.useEffect((()=>(!y(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||o)&&s.unregister(a)})),[a,s,n,o]),{swap:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);pe(r,e,t),pe(l.current,e,t),p(r),i(r),s._updateFieldArray(a,r,pe,{argA:e,argB:t},!1)}),[p,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);fe(r,e,t),fe(l.current,e,t),p(r),i(r),s._updateFieldArray(a,r,fe,{argA:e,argB:t},!1)}),[p,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=me(s._getFieldArray(a),r);s._names.focus=H(a,0,t),l.current=me(l.current,r.map($)),p(n),i(n),s._updateFieldArray(a,n,me,{argA:ce(e)})}),[p,a,s]),append:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=le(s._getFieldArray(a),r);s._names.focus=H(a,n.length-1,t),l.current=le(l.current,r.map($)),p(n),i(n),s._updateFieldArray(a,n,le,{argA:ce(e)})}),[p,a,s]),remove:t.default.useCallback((e=>{const t=ye(s._getFieldArray(a),e);l.current=ye(l.current,e),p(t),i(t),s._updateFieldArray(a,t,ye,{argA:e})}),[p,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=C(d(t)),o=de(s._getFieldArray(a),e,n);s._names.focus=H(a,e,r),l.current=de(l.current,e,n.map($)),p(o),i(o),s._updateFieldArray(a,o,de,{argA:e,argB:ce(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]:$())),p(n),i([...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($),p([...t]),i([...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]||$()})))),[u,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),s=t.default.useRef(),[a,n]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:Q(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:Q(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Ne(e,(()=>n((e=>({...e}))))),formState:a});const o=r.current.control;return o._options=e,E({subject:o._subjects.state,next:e=>{D(e,o._proxyFormState,o._updateFormState,!0)&&n({...o._formState})}}),t.default.useEffect((()=>{e.values&&!be(e.values,s.current)?(o._reset(e.values,o._options.resetOptions),s.current=e.values):o._resetDefaultValues()}),[e.values,o]),t.default.useEffect((()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()})),r.current.formState=w(a,o),r.current},exports.useFormContext=S,exports.useFormState=j,exports.useWatch=B;
"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?[]:{},r||l(e))for(const r in e)e.hasOwnProperty(r)&&(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"},h={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},g="max",_="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]!==h.all&&(t._proxyFormState[a]=!s||h.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||h.all)))},C=e=>Array.isArray(e)?e:[e],E=(e,t,r)=>r&&t?e===t:!e||!t||e===t||C(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function O(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 j(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,O({disabled:a,next:e=>l.current&&E(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 T=e=>"string"==typeof e,U=(e,t,r,s,a)=>T(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 B(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,O({disabled:i,subject:s._subjects.values,next:e=>{E(o.current,e.name,u)&&c(d(U(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=B({control:a,name:s,defaultValue:y(a._formValues,s,y(a._defaultValues,s,e.defaultValue)),exact:!0}),c=j({control:a,name:s}),f=t.default.useRef(a.register(s,{...e.rules,value:l}));return f.current=a.register(s,e.rules),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,disabled:c.disabled,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)}})}}const P="post";var q=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},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===h.onSubmit,isOnBlur:e===h.onBlur,isOnChange:e===h.onChange,isOnAll:e===h.all,isOnTouch:e===h.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)))));const G=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=y(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break}else i(n)&&G(n,t)}}};var J=(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,K=e=>"file"===e.type,Q=e=>"function"==typeof e,X=e=>{if(!c)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Y=e=>T(e),Z=e=>"radio"===e.type,ee=e=>e instanceof RegExp;const te={value:!1,isValid:!1},re={value:!0,isValid:!0};var se=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?re:{value:e[0].value,isValid:!0}:re:te}return te};const ae={isValid:!1,value:null};var ne=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ae):ae;function ie(e,t,r="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||z(e)&&!e)return{type:r,message:Y(e)?e:"",ref:t}}var ue=e=>i(e)&&!ee(e)?e:{value:e,message:""},oe=async(e,t,s,n,u)=>{const{ref:o,refs:l,required:c,maxLength:d,minLength:f,min:p,max:h,pattern:F,validate:S,name:w,valueAsNumber:D,mount:C,disabled:E}=e._f,O=y(t,w);if(!C||E)return{};const j=l?l[0]:o,U=e=>{n&&j.reportValidity&&(j.setCustomValidity(z(e)?"":e||""),j.reportValidity())},B={},L=Z(o),N=r(o),M=L||N,R=(D||K(o))&&m(o.value)&&m(O)||X(o)&&""===o.value||""===O||Array.isArray(O)&&!O.length,P=q.bind(null,w,s,B),W=(e,t,r,s=v,a=b)=>{const n=e?t:r;B[w]={type:e?s:a,message:n,ref:o,...P(e?s:a,n)}};if(u?!Array.isArray(O)||!O.length:c&&(!M&&(R||a(O))||z(O)&&!O||N&&!se(l).isValid||L&&!ne(l).isValid)){const{value:e,message:t}=Y(c)?{value:!!c,message:c}:ue(c);if(e&&(B[w]={type:A,message:t,ref:j,...P(A,t)},!s))return U(t),B}if(!(R||a(p)&&a(h))){let e,t;const r=ue(h),n=ue(p);if(a(O)||isNaN(O)){const s=o.valueAsDate||new Date(O),a=e=>new Date((new Date).toDateString()+" "+e),i="time"==o.type,u="week"==o.type;T(r.value)&&O&&(e=i?a(O)>a(r.value):u?O>r.value:s>new Date(r.value)),T(n.value)&&O&&(t=i?a(O)<a(n.value):u?O<n.value:s<new Date(n.value))}else{const s=o.valueAsNumber||(O?+O:O);a(r.value)||(e=s>r.value),a(n.value)||(t=s<n.value)}if((e||t)&&(W(!!e,r.message,n.message,g,_),!s))return U(B[w].message),B}if((d||f)&&!R&&(T(O)||u&&Array.isArray(O))){const e=ue(d),t=ue(f),r=!a(e.value)&&O.length>+e.value,n=!a(t.value)&&O.length<+t.value;if((r||n)&&(W(r,e.message,t.message),!s))return U(B[w].message),B}if(F&&!R&&T(O)){const{value:e,message:t}=ue(F);if(ee(e)&&!O.match(e)&&(B[w]={type:x,message:t,ref:o,...P(x,t)},!s))return U(t),B}if(S)if(Q(S)){const e=ie(await S(O,t),j);if(e&&(B[w]={...e,...P(V,e.message)},!s))return U(e.message),B}else if(i(S)){let e={};for(const r in S){if(!k(e)&&!s)break;const a=ie(await S[r](O,t),j,r);a&&(e={...a,...P(r,a.message)},U(a.message),s&&(B[w]=e))}if(!k(e)&&(B[w]={ref:j,...e},!s))return B}return U(!0),B};function le(e,t){return[...e,...C(t)]}var ce=e=>Array.isArray(e)?e.map((()=>{})):void 0;function de(e,t,r){return[...e.slice(0,t),...C(r),...e.slice(t)]}var fe=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function me(e,t){return[...C(t),...C(e)]}var ye=(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))),pe=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function he(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(e.hasOwnProperty(t)&&!m(e[t]))return!1;return!0}(s))&&he(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 ve=e=>a(e)||!n(e);function be(e,t){if(ve(e)||ve(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)?!be(r,e):r!==e)return!1}}return!0}var xe=e=>"select-multiple"===e.type,Ae=e=>Z(e)||r(e),Ve=e=>X(e)&&e.isConnected,Fe=e=>{for(const t in e)if(Q(e[t]))return!0;return!1};function Se(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!Fe(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Se(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function we(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!Fe(e[s])?m(t)||ve(r[s])?r[s]=Array.isArray(e[s])?Se(e[s],[]):{...Se(e[s])}:we(e[s],a(t)?{}:t[s],r[s]):r[s]=!be(e[s],t[s]);return r}var ke=(e,t)=>we(e,t,Se(t)),De=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&T(e)?new Date(e):s?s(e):e;function Ce(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return K(t)?t.files:Z(t)?ne(e.refs).value:xe(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?se(e.refs).value:De(m(t.value)?e.ref.value:t.value,e)}var Ee=(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:ee(e)?e.source:i(e)?ee(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 Te(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&&he(e,t);const Le={mode:h.onSubmit,reValidateMode:h.onChange,shouldFocusError:!0};function Ne(e={},t){let n,l={...Le,...e},g={submitCount:0,isDirty:!1,isLoading:Q(l.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},_={},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),E=H(l.reValidateMode),O=l.criteriaMode===h.all,j=async e=>{if(F.isValid||e){const e=l.resolver?k((await P()).errors):await q(_,!0);e!==g.isValid&&S.state.next({isValid:e})}},B=e=>F.isValidating&&S.state.next({isValidating:e}),L=(e,t,r,s)=>{const a=y(_,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:Ce(a._f)):Y(e,n),x.mount&&j()}},N=(e,t,r,s,a)=>{let n=!1,i=!1;const u={name:e};if(!r||s){F.isDirty&&(i=g.isDirty,g.isDirty=u.isDirty=W(),n=i!==u.isDirty);const r=be(y(v,e),t);i=y(g.dirtyFields,e),r?he(g.dirtyFields,e):M(g.dirtyFields,e,!0),u.dirtyFields=g.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=y(g.touchedFields,e);t||(M(g.touchedFields,e,r),u.touchedFields=g.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(u),n?u:{}},R=(t,r,s,a)=>{const i=y(g.errors,t),u=F.isValid&&z(r)&&g.isValid!==r;var o;if(e.delayError&&s?(o=()=>((e,t)=>{M(g.errors,e,t),S.state.next({errors:g.errors})})(t,s),n=e=>{clearTimeout(V),V=setTimeout(o,e)},n(e.delayError)):(clearTimeout(V),n=null,s?M(g.errors,t,s):he(g.errors,t)),(s?!be(i,s):i)||!k(a)||u){const e={...a,...u&&z(r)?{isValid:r}:{},errors:g.errors,name:t};g={...g,...e},S.state.next(e)}B(!1)},P=async e=>l.resolver(b,l.context,Ee(e||A.mount,_,l.criteriaMode,l.shouldUseNativeValidation)),q=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 oe(a,b,O,l.shouldUseNativeValidation&&!t,s);if(n[e.name]&&(r.valid=!1,t))break;!t&&(y(n,e.name)?s?J(g.errors,n,e.name):M(g.errors,e.name,n[e.name]):he(g.errors,e.name))}s&&await q(s,t,r)}}return r.valid},W=(e,t)=>(e&&t&&M(b,e,t),!be(ae(),v)),$=(e,t,r)=>U(e,A,{...x.mount?b:m(t)?v:T(e)?{[e]:t}:t},r,t),Y=(e,t,s={})=>{const n=y(_,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&M(b,e,De(t,s)),i=X(s.ref)&&a(t)?"":t,xe(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)):K(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&&se(e)},Z=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,u=y(_,i);!A.array.has(e)&&ve(n)&&(!u||u._f)||s(n)?Y(i,n,r):Z(i,n,r)}},ee=(e,r,s={})=>{const n=y(_,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:ke(v,b),isDirty:W(e,u)})):!n||n._f||a(u)?Y(e,u,s):Z(e,u,s),I(e,A)&&S.state.next({...g}),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(_,r);if(a){let i,o;const c=t.type?Ce(a._f):u(e),d=e.type===p.BLUR||e.type===p.FOCUS_OUT,f=!je(a._f)&&!l.resolver&&!y(g.errors,r)&&!a._f.deps||Ue(d,y(g.touchedFields,r),g.isSubmitted,E,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 h=N(r,c,d,!1),v=!k(h)||m;if(!d&&S.values.next({name:r,type:e.type,values:{...b}}),f)return F.isValid&&j(),v&&S.state.next({name:r,...m?{}:h});if(!d&&m&&S.state.next({...g}),B(!0),l.resolver){const{errors:e}=await P([r]),t=Te(g.errors,_,r),s=Te(e,_,t.name||r);i=s.error,r=s.name,o=k(e)}else i=(await oe(a,b,O,l.shouldUseNativeValidation))[r],s=isNaN(c)||c===y(b,r,c),s&&(i?o=!1:F.isValid&&(o=await q(_,!0)));s&&(a._f.deps&&se(a._f.deps),R(r,o,i,h))}},re=(e,t)=>{if(y(g.errors,t)&&e.focus)return e.focus(),1},se=async(e,t={})=>{let r,s;const a=C(e);if(B(!0),l.resolver){const t=await(async e=>{const{errors:t}=await P();if(e)for(const r of e){const e=y(t,r);e?M(g.errors,r,e):he(g.errors,r)}else g.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(_,e);return await q(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||g.isValid)&&j()):s=r=await q(_);return S.state.next({...!T(e)||F.isValid&&r!==g.isValid?{}:{name:e},...l.resolver||!e?{isValid:r}:{},errors:g.errors,isValidating:!1}),t.shouldFocus&&!s&&G(_,re,e?a:A.mount),s},ae=e=>{const t={...v,...x.mount?b:{}};return m(e)?t:T(e)?y(t,e):e.map((e=>y(t,e)))},ne=(e,t)=>({invalid:!!y((t||g).errors,e),isDirty:!!y((t||g).dirtyFields,e),isTouched:!!y((t||g).touchedFields,e),error:y((t||g).errors,e)}),ie=(e,t,r)=>{const s=(y(_,e,{_f:{}})._f||{}).ref;M(g.errors,e,{...t,ref:s}),S.state.next({name:e,errors:g.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ue=(e,t={})=>{for(const r of e?C(e):A.mount)A.mount.delete(r),A.array.delete(r),t.keepValue||(he(_,r),he(b,r)),!t.keepError&&he(g.errors,r),!t.keepDirty&&he(g.dirtyFields,r),!t.keepTouched&&he(g.touchedFields,r),!l.shouldUnregister&&!t.keepDefaultValue&&he(v,r);S.values.next({values:{...b}}),S.state.next({...g,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&j()},le=(e,t={})=>{let r=y(_,e);const s=z(t.disabled);return M(_,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,Ce(r._f))):L(e,!0,t.value),{...s?{disabled:t.disabled}:{},...l.progressive?{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){le(e,t),r=y(_,e);const a=m(s.value)&&s.querySelectorAll&&s.querySelectorAll("input,select,textarea")[0]||s,n=Ae(a),i=r._f.refs||[];if(n?i.find((e=>e===a)):a===r._f.ref)return;M(_,e,{_f:{...r._f,...n?{refs:[...i.filter(Ve),a,...Array.isArray(y(v,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),L(e,!1,void 0,a)}else r=y(_,e,{}),r._f&&(r._f.mount=!1),(l.shouldUnregister||t.shouldUnregister)&&(!o(A.array,e)||!x.action)&&A.unMount.add(e)}}},ce=()=>l.shouldFocusError&&G(_,re,A.mount),de=(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 P();g.errors=e,s=t}else await q(_);he(g.errors,"root"),k(g.errors)?(S.state.next({errors:{}}),await e(s,r)):(t&&await t({...g.errors},r),ce(),setTimeout(ce)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:k(g.errors),submitCount:g.submitCount+1,errors:g.errors})},fe=(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(g.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(_,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(X(e)){const t=e.closest("form");if(t){t.reset();break}}}}_={}}b=e.shouldUnregister?s.keepDefaultValues?d(v):{}:d(i),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?g.submitCount:0,isDirty:s.keepDirty?g.isDirty:!(!s.keepDefaultValues||be(r,v)),isSubmitted:!!s.keepIsSubmitted&&g.isSubmitted,dirtyFields:s.keepDirtyValues?g.dirtyFields:s.keepDefaultValues&&r?ke(v,r):{},touchedFields:s.keepTouched?g.touchedFields:{},errors:s.keepErrors?g.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},me=(e,t)=>fe(Q(e)?e(b):e,t);return{control:{register:le,unregister:ue,getFieldState:ne,handleSubmit:de,setError:ie,_executeSchema:P,_getWatch:$,_getDirty:W,_updateValid:j,_removeUnmounted:()=>{for(const e of A.unMount){const t=y(_,e);t&&(t._f.refs?t._f.refs.every((e=>!Ve(e))):!Ve(t._f.ref))&&ue(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(_,e))){const t=r(y(_,e),s.argA,s.argB);a&&M(_,e,t)}if(n&&Array.isArray(y(g.errors,e))){const t=r(y(g.errors,e),s.argA,s.argB);a&&M(g.errors,e,t),Be(g.errors,e)}if(F.touchedFields&&n&&Array.isArray(y(g.touchedFields,e))){const t=r(y(g.touchedFields,e),s.argA,s.argB);a&&M(g.touchedFields,e,t)}F.dirtyFields&&(g.dirtyFields=ke(v,b)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:g.dirtyFields,errors:g.errors,isValid:g.isValid})}else M(b,e,t)},_getFieldArray:t=>f(y(x.mount?b:v,t,e.shouldUnregister?y(v,t,[]):[])),_reset:fe,_resetDefaultValues:()=>Q(l.defaultValues)&&l.defaultValues().then((e=>{me(e,l.resetOptions),S.state.next({isLoading:!1})})),_updateFormState:e=>{g={...g,...e}},_disableForm:t=>{z(e.disabled)&&(S.state.next({disabled:e.disabled}),G(_,(e=>{e.disabled=t}),0,!1))},_subjects:S,_proxyFormState:F,get _fields(){return _},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 g},set _formState(e){g=e},get _options(){return l},set _options(e){l={...l,...e}}},trigger:se,register:le,handleSubmit:de,watch:(e,t)=>Q(e)?S.values.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:ee,getValues:ae,reset:me,resetField:(e,t={})=>{y(_,e)&&(m(t.defaultValue)?ee(e,y(v,e)):(ee(e,t.defaultValue),M(v,e,t.defaultValue)),t.keepTouched||he(g.touchedFields,e),t.keepDirty||(he(g.dirtyFields,e),g.isDirty=t.defaultValue?W(e,y(v,e)):W()),t.keepError||(he(g.errors,e),F.isValid&&j()),S.state.next({...g}))},clearErrors:e=>{e&&C(e).forEach((e=>he(g.errors,e))),S.state.next({errors:e?g.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=y(_,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:ne}}exports.Controller=e=>e.render(R(e)),exports.Form=function(e){const r=S(),[s,a]=t.default.useState(!1),{control:n=r.control,onSubmit:i,children:u,action:o,method:l=P,headers:c,encType:d,onError:f,render:m,onSuccess:p,validateStatus:h,...g}=e,_=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,y(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[c&&c["Content-Type"],d].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...c,...d?{"Content-Type":d}:{}},body:e?u:a});t&&(h?!h(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):p&&p({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return t.default.useEffect((()=>{a(!0)}),[]),m?t.default.createElement(t.default.Fragment,null,m({submit:_})):t.default.createElement("form",{noValidate:s,action:o,method:l,encType:d,onSubmit:_,...g},u)},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),O({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&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?M(s._formState.errors,a,t):he(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=y(s._fields,a);e&&e._f&&oe(e,s._formValues,s._options.criteriaMode===h.all,s._options.shouldUseNativeValidation,!0).then((e=>!k(e)&&s._subjects.state.next({errors:J(s._formState.errors,e,a)})))}s._subjects.values.next({name:a,values:{...s._formValues}}),s._names.focus&&G(s._fields,((e,t)=>{if(s._names.focus&&t.startsWith(s._names.focus)&&e.focus)return e.focus(),1})),s._names.focus="",s._updateValid(),m.current=!1}),[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);pe(r,e,t),pe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,pe,{argA:e,argB:t},!1)}),[p,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);fe(r,e,t),fe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,fe,{argA:e,argB:t},!1)}),[p,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=me(s._getFieldArray(a),r);s._names.focus=$(a,0,t),l.current=me(l.current,r.map(W)),p(n),o(n),s._updateFieldArray(a,n,me,{argA:ce(e)})}),[p,a,s]),append:t.default.useCallback(((e,t)=>{const r=C(d(e)),n=le(s._getFieldArray(a),r);s._names.focus=$(a,n.length-1,t),l.current=le(l.current,r.map(W)),p(n),o(n),s._updateFieldArray(a,n,le,{argA:ce(e)})}),[p,a,s]),remove:t.default.useCallback((e=>{const t=ye(s._getFieldArray(a),e);l.current=ye(l.current,e),p(t),o(t),s._updateFieldArray(a,t,ye,{argA:e})}),[p,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=C(d(t)),i=de(s._getFieldArray(a),e,n);s._names.focus=$(a,e,r),l.current=de(l.current,e,n.map(W)),p(i),o(i),s._updateFieldArray(a,i,de,{argA:e,argB:ce(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=t.default.useRef(),[a,n]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:Q(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Q(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Ne(e,(()=>n((e=>({...e}))))),formState:a});const i=r.current.control;return i._options=e,O({subject:i._subjects.state,next:e=>{D(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),t.default.useEffect((()=>{e.values&&!be(e.values,s.current)?(i._reset(e.values,i._options.resetOptions),s.current=e.values):i._resetDefaultValues()}),[e.values,i]),t.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),t.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),r.current.formState=w(a,i),r.current},exports.useFormContext=S,exports.useFormState=j,exports.useWatch=B;
//# sourceMappingURL=index.cjs.js.map

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

!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,o=e=>null==e;const u=e=>"object"==typeof e;var i=e=>!o(e)&&!Array.isArray(e)&&u(e)&&!n(e),l=e=>i(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 i(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&&!i(e))return e;if(t=r?[]:{},r||d(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=m(e[r]));else t=e}return t}var y=e=>Array.isArray(e)?e.filter(Boolean):[],p=e=>void 0===e,h=(e,t,r)=>{if(!t||!i(e))return r;const s=y(t.split(/[,[\].]+?/)).reduce(((e,t)=>o(e)?e:e[t]),e);return p(s)||s===e?p(e[t])?r:e[t]:s};const g={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},_={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]!==_.all&&(t._proxyFormState[a]=!s||_.all),r&&(r[a]=!0),e[a]}});return a},C=e=>i(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||_.all)))},E=e=>Array.isArray(e)?e:[e],j=(e,t,r)=>r&&t?e===t:!e||!t||e===t||E(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function T(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 U(e){const t=k(),{control:r=t.control,disabled:a,name:n,exact:o}=e||{},[u,i]=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,T({disabled:a,next:e=>l.current&&j(d.current,e.name,o)&&O(e,c.current,r._updateFormState)&&i({...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),h(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),h(r,e)))):(s&&(t.watchAll=!0),r);function N(e){const t=k(),{control:r=t.control,name:a,defaultValue:n,disabled:o,exact:u}=e||{},i=s.default.useRef(a);i.current=a,T({disabled:o,subject:r._subjects.values,next:e=>{j(i.current,e.name,u)&&c(m(L(i.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 R=e=>/^\w*$/.test(e),M=e=>y(e.replace(/["|']|\]/g,"").split(/\.|\[/));function P(e,t,r){let s=-1;const a=R(t)?[t]:M(t),n=a.length,o=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==o){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}function q(e){const t=k(),{name:r,control:a=t.control,shouldUnregister:n}=e,o=c(a._names.array,r),u=N({control:a,name:r,defaultValue:h(a._formValues,r,h(a._defaultValues,r,e.defaultValue)),exact:!0}),i=U({control:a,name:r}),d=s.default.useRef(a.register(r,{...e.rules,value:u}));return d.current=a.register(r,e.rules),s.default.useEffect((()=>{const e=a._options.shouldUnregister||n,t=(e,t)=>{const r=h(a._fields,e);r&&(r._f.mount=t)};if(t(r,!0),e){const e=m(h(a._options.defaultValues,r));P(a._defaultValues,r,e),p(h(a._formValues,r))&&P(a._formValues,r,e)}return()=>{(o?e&&!a._state.action:e)?a.unregister(r):t(r,!1)}}),[r,a,o,n]),{field:{name:r,value:u,onChange:s.default.useCallback((e=>d.current.onChange({target:{value:l(e),name:r},type:g.CHANGE})),[r]),onBlur:s.default.useCallback((()=>d.current.onBlur({target:{value:h(a._formValues,r),name:r},type:g.BLUR})),[r,a]),ref:e=>{const t=h(a._fields,r);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:i,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!h(i.errors,r)},isDirty:{enumerable:!0,get:()=>!!h(i.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!h(i.touchedFields,r)},error:{enumerable:!0,get:()=>h(i.errors,r)}})}}const W="post";var H=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{};const $=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=h(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)&&$(s,t)}}};var I=()=>{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)}))},G=(e,t,r={})=>r.shouldFocus||p(r.shouldFocus)?r.focusName||`${e}.${p(r.focusIndex)?t:r.focusIndex}.`:"",J=e=>({isOnSubmit:!e||e===_.onSubmit,isOnBlur:e===_.onBlur,isOnChange:e===_.onChange,isOnAll:e===_.all,isOnTouch:e===_.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))))),K=(e,t,r)=>{const s=y(h(e,r));return P(s,"root",t[r]),P(e,r,s),e},Q=e=>"boolean"==typeof e,X=e=>"file"===e.type,Y=e=>"function"==typeof e,Z=e=>{if(!f)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ee=e=>B(e),te=e=>"radio"===e.type,re=e=>e instanceof RegExp;const se={value:!1,isValid:!1},ae={value:!0,isValid:!0};var ne=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?ae:{value:e[0].value,isValid:!0}:ae:se}return se};const oe={isValid:!1,value:null};var ue=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),oe):oe;function ie(e,t,r="validate"){if(ee(e)||Array.isArray(e)&&e.every(ee)||Q(e)&&!e)return{type:r,message:ee(e)?e:"",ref:t}}var le=e=>i(e)&&!re(e)?e:{value:e,message:""},ce=async(e,t,r,s,n)=>{const{ref:u,refs:l,required:c,maxLength:d,minLength:f,min:m,max:y,pattern:g,validate:_,name:w,valueAsNumber:k,mount:D,disabled:O}=e._f,E=h(t,w);if(!D||O)return{};const j=l?l[0]:u,T=e=>{s&&j.reportValidity&&(j.setCustomValidity(Q(e)?"":e||""),j.reportValidity())},U={},L=te(u),N=a(u),R=L||N,M=(k||X(u))&&p(u.value)&&p(E)||Z(u)&&""===u.value||""===E||Array.isArray(E)&&!E.length,P=H.bind(null,w,r,U),q=(e,t,r,s=A,a=V)=>{const n=e?t:r;U[w]={type:e?s:a,message:n,ref:u,...P(e?s:a,n)}};if(n?!Array.isArray(E)||!E.length:c&&(!R&&(M||o(E))||Q(E)&&!E||N&&!ne(l).isValid||L&&!ue(l).isValid)){const{value:e,message:t}=ee(c)?{value:!!c,message:c}:le(c);if(e&&(U[w]={type:F,message:t,ref:j,...P(F,t)},!r))return T(t),U}if(!(M||o(m)&&o(y))){let e,t;const s=le(y),a=le(m);if(o(E)||isNaN(E)){const r=u.valueAsDate||new Date(E),n=e=>new Date((new Date).toDateString()+" "+e),o="time"==u.type,i="week"==u.type;B(s.value)&&E&&(e=o?n(E)>n(s.value):i?E>s.value:r>new Date(s.value)),B(a.value)&&E&&(t=o?n(E)<n(a.value):i?E<a.value:r<new Date(a.value))}else{const r=u.valueAsNumber||(E?+E:E);o(s.value)||(e=r>s.value),o(a.value)||(t=r<a.value)}if((e||t)&&(q(!!e,s.message,a.message,v,b),!r))return T(U[w].message),U}if((d||f)&&!M&&(B(E)||n&&Array.isArray(E))){const e=le(d),t=le(f),s=!o(e.value)&&E.length>+e.value,a=!o(t.value)&&E.length<+t.value;if((s||a)&&(q(s,e.message,t.message),!r))return T(U[w].message),U}if(g&&!M&&B(E)){const{value:e,message:t}=le(g);if(re(e)&&!E.match(e)&&(U[w]={type:x,message:t,ref:u,...P(x,t)},!r))return T(t),U}if(_)if(Y(_)){const e=ie(await _(E,t),j);if(e&&(U[w]={...e,...P(S,e.message)},!r))return T(e.message),U}else if(i(_)){let e={};for(const s in _){if(!C(e)&&!r)break;const a=ie(await _[s](E,t),j,s);a&&(e={...a,...P(s,a.message)},T(a.message),r&&(U[w]=e))}if(!C(e)&&(U[w]={ref:j,...e},!r))return U}return T(!0),U};function de(e,t){return[...e,...E(t)]}var fe=e=>Array.isArray(e)?e.map((()=>{})):void 0;function me(e,t,r){return[...e.slice(0,t),...E(r),...e.slice(t)]}var ye=(e,t,r)=>Array.isArray(e)?(p(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function pe(e,t){return[...E(t),...E(e)]}var he=(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,E(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:R(t)?[t]:M(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&&(i(s)&&C(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!p(e[t]))return!1;return!0}(s))&&_e(e,r.slice(0,-1)),e}var ve=(e,t,r)=>(e[t]=r,e);function be(){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 Ae=e=>o(e)||!u(e);function Ve(e,t){if(Ae(e)||Ae(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)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!Ve(r,e):r!==e)return!1}}return!0}var xe=e=>"select-multiple"===e.type,Fe=e=>te(e)||a(e),Se=e=>Z(e)&&e.isConnected,we=e=>{for(const t in e)if(Y(e[t]))return!0;return!1};function ke(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!we(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ke(e[r],t[r])):o(e[r])||(t[r]=!0);return t}function De(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!we(e[s])?p(t)||Ae(r[s])?r[s]=Array.isArray(e[s])?ke(e[s],[]):{...ke(e[s])}:De(e[s],o(t)?{}:t[s],r[s]):r[s]=!Ve(e[s],t[s]);return r}var Ce=(e,t)=>De(e,t,ke(t)),Oe=(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 Ee(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return X(t)?t.files:te(t)?ue(e.refs).value:xe(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ne(e.refs).value:Oe(p(t.value)?e.ref.value:t.value,e)}var je=(e,t,r,s)=>{const a={};for(const r of e){const e=h(t,r);e&&P(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Te=e=>p(e)?e:re(e)?e.source:i(e)?re(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 Be(e,t,r){const s=h(e,r);if(s||R(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=h(t,s),o=h(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(o&&o.type)return{name:s,error:o};a.pop()}return{name:r}}var Le=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Ne=(e,t)=>!y(h(e,t)).length&&_e(e,t);const Re={mode:_.onSubmit,reValidateMode:_.onChange,shouldFocusError:!0};function Me(e={},t){let r,s={...Re,...e},u={submitCount:0,isDirty:!1,isLoading:Y(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},d={},v=(i(s.defaultValues)||i(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:be(),array:be(),state:be()},w=e.resetOptions&&e.resetOptions.keepDirtyValues,k=J(s.mode),D=J(s.reValidateMode),O=s.criteriaMode===_.all,j=async e=>{if(F.isValid||e){const e=s.resolver?C((await M()).errors):await q(d,!0);e!==u.isValid&&S.state.next({isValid:e})}},T=e=>F.isValidating&&S.state.next({isValidating:e}),U=(e,t,r,s)=>{const a=h(d,e);if(a){const n=h(b,e,p(r)?h(v,e):r);p(n)||s&&s.defaultChecked||t?P(b,e,t?n:Ee(a._f)):I(e,n),A.mount&&j()}},N=(e,t,r,s,a)=>{let n=!1,o=!1;const i={name:e};if(!r||s){F.isDirty&&(o=u.isDirty,u.isDirty=i.isDirty=W(),n=o!==i.isDirty);const r=Ve(h(v,e),t);o=h(u.dirtyFields,e),r?_e(u.dirtyFields,e):P(u.dirtyFields,e,!0),i.dirtyFields=u.dirtyFields,n=n||F.dirtyFields&&o!==!r}if(r){const t=h(u.touchedFields,e);t||(P(u.touchedFields,e,r),i.touchedFields=u.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(i),n?i:{}},R=(t,s,a,n)=>{const o=h(u.errors,t),i=F.isValid&&Q(s)&&u.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{P(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?P(u.errors,t,a):_e(u.errors,t)),(a?!Ve(o,a):o)||!C(n)||i){const e={...n,...i&&Q(s)?{isValid:s}:{},errors:u.errors,name:t};u={...u,...e},S.state.next(e)}T(!1)},M=async e=>s.resolver(b,s.context,je(e||V.mount,d,s.criteriaMode,s.shouldUseNativeValidation)),q=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),o=await ce(n,b,O,s.shouldUseNativeValidation&&!t,a);if(o[e.name]&&(r.valid=!1,t))break;!t&&(h(o,e.name)?a?K(u.errors,o,e.name):P(u.errors,e.name,o[e.name]):_e(u.errors,e.name))}a&&await q(a,t,r)}}return r.valid},W=(e,t)=>(e&&t&&P(b,e,t),!Ve(se(),v)),H=(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=h(d,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&P(b,e,Oe(t,r)),n=Z(r.ref)&&o(t)?"":t,xe(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)):X(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)},G=(e,t,r)=>{for(const s in t){const a=t[s],o=`${e}.${s}`,u=h(d,o);!V.array.has(e)&&Ae(a)&&(!u||u._f)||n(a)?I(o,a,r):G(o,a,r)}},ee=(e,r,s={})=>{const a=h(d,e),n=V.array.has(e),i=m(r);P(b,e,i),n?(S.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:Ce(v,b),isDirty:W(e,i)})):!a||a._f||o(i)?I(e,i,s):G(e,i,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 o=h(d,a);if(o){let i,c;const f=t.type?Ee(o._f):l(e),m=e.type===g.BLUR||e.type===g.FOCUS_OUT,y=!Ue(o._f)&&!s.resolver&&!h(u.errors,a)&&!o._f.deps||Le(m,h(u.touchedFields,a),u.isSubmitted,D,k),p=z(a,V,m);P(b,a,f),m?(o._f.onBlur&&o._f.onBlur(e),r&&r(0)):o._f.onChange&&o._f.onChange(e);const _=N(a,f,m,!1),v=!C(_)||p;if(!m&&S.values.next({name:a,type:e.type,values:{...b}}),y)return F.isValid&&j(),v&&S.state.next({name:a,...p?{}:_});if(!m&&p&&S.state.next({...u}),T(!0),s.resolver){const{errors:e}=await M([a]),t=Be(u.errors,d,a),r=Be(e,d,t.name||a);i=r.error,a=r.name,c=C(e)}else i=(await ce(o,b,O,s.shouldUseNativeValidation))[a],n=isNaN(f)||f===h(b,a,f),n&&(i?c=!1:F.isValid&&(c=await q(d,!0)));n&&(o._f.deps&&re(o._f.deps),R(a,c,i,_))}},re=async(e,t={})=>{let r,a;const n=E(e);if(T(!0),s.resolver){const t=await(async e=>{const{errors:t}=await M();if(e)for(const r of e){const e=h(t,r);e?P(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=>h(t,e))):r}else e?(a=(await Promise.all(n.map((async e=>{const t=h(d,e);return await q(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&j()):a=r=await q(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&&$(d,(e=>e&&h(u.errors,e)),e?n:V.mount),a},se=e=>{const t={...v,...A.mount?b:{}};return p(e)?t:B(e)?h(t,e):e.map((e=>h(t,e)))},ae=(e,t)=>({invalid:!!h((t||u).errors,e),isDirty:!!h((t||u).dirtyFields,e),isTouched:!!h((t||u).touchedFields,e),error:h((t||u).errors,e)}),ne=(e,t,r)=>{const s=(h(d,e,{_f:{}})._f||{}).ref;P(u.errors,e,{...t,ref:s}),S.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},oe=(e,t={})=>{for(const r of e?E(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&&j()},ue=(e,t={})=>{let r=h(d,e);const a=Q(t.disabled);return P(d,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?a&&P(b,e,t.disabled?void 0:h(b,e,Ee(r._f))):U(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.progressive?{required:!!t.required,min:Te(t.min),max:Te(t.max),minLength:Te(t.minLength),maxLength:Te(t.maxLength),pattern:Te(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:a=>{if(a){ue(e,t),r=h(d,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=Fe(s),o=r._f.refs||[];if(n?o.find((e=>e===s)):s===r._f.ref)return;P(d,e,{_f:{...r._f,...n?{refs:[...o.filter(Se),s,...Array.isArray(h(v,e))?[{}]:[]],ref:{type:s.type,name:e}}:{ref:s}}}),U(e,!1,void 0,s)}else r=h(d,e,{}),r._f&&(r._f.mount=!1),(s.shouldUnregister||t.shouldUnregister)&&(!c(V.array,e)||!A.action)&&V.unMount.add(e)}}},ie=()=>s.shouldFocusError&&$(d,(e=>e&&h(u.errors,e)),V.mount),le=(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 M();u.errors=e,a=t}else await q(d);_e(u.errors,"root"),C(u.errors)?(S.state.next({errors:{}}),await e(a,r)):(t&&await t({...u.errors},r),ie(),setTimeout(ie)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:C(u.errors),submitCount:u.submitCount+1,errors:u.errors})},de=(r,s={})=>{const a=r||v,n=m(a),o=r&&!C(r)?n:v;if(s.keepDefaultValues||(v=a),!s.keepValues){if(s.keepDirtyValues||w)for(const e of V.mount)h(u.dirtyFields,e)?P(o,e,h(b,e)):ee(e,h(o,e));else{if(f&&p(r))for(const e of V.mount){const t=h(d,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Z(e)){const t=e.closest("form");if(t){t.reset();break}}}}d={}}b=e.shouldUnregister?s.keepDefaultValues?m(v):{}:m(o),S.array.next({values:{...o}}),S.values.next({values:{...o}})}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||Ve(r,v)),isSubmitted:!!s.keepIsSubmitted&&u.isSubmitted,dirtyFields:s.keepDirtyValues?u.dirtyFields:s.keepDefaultValues&&r?Ce(v,r):{},touchedFields:s.keepTouched?u.touchedFields:{},errors:s.keepErrors?u.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},fe=(e,t)=>de(Y(e)?e(b):e,t);return{control:{register:ue,unregister:oe,getFieldState:ae,handleSubmit:le,setError:ne,_executeSchema:M,_getWatch:H,_getDirty:W,_updateValid:j,_removeUnmounted:()=>{for(const e of V.unMount){const t=h(d,e);t&&(t._f.refs?t._f.refs.every((e=>!Se(e))):!Se(t._f.ref))&&oe(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(A.action=!0,n&&Array.isArray(h(d,e))){const t=r(h(d,e),s.argA,s.argB);a&&P(d,e,t)}if(n&&Array.isArray(h(u.errors,e))){const t=r(h(u.errors,e),s.argA,s.argB);a&&P(u.errors,e,t),Ne(u.errors,e)}if(F.touchedFields&&n&&Array.isArray(h(u.touchedFields,e))){const t=r(h(u.touchedFields,e),s.argA,s.argB);a&&P(u.touchedFields,e,t)}F.dirtyFields&&(u.dirtyFields=Ce(v,b)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else P(b,e,t)},_getFieldArray:t=>y(h(A.mount?b:v,t,e.shouldUnregister?h(v,t,[]):[])),_reset:de,_resetDefaultValues:()=>Y(s.defaultValues)&&s.defaultValues().then((e=>{fe(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:ue,handleSubmit:le,watch:(e,t)=>Y(e)?S.values.subscribe({next:r=>e(H(void 0,t),r)}):H(e,t,!0),setValue:ee,getValues:se,reset:fe,resetField:(e,t={})=>{h(d,e)&&(p(t.defaultValue)?ee(e,h(v,e)):(ee(e,t.defaultValue),P(v,e,t.defaultValue)),t.keepTouched||_e(u.touchedFields,e),t.keepDirty||(_e(u.dirtyFields,e),u.isDirty=t.defaultValue?W(e,h(v,e)):W()),t.keepError||(_e(u.errors,e),F.isValid&&j()),S.state.next({...u}))},clearErrors:e=>{e&&E(e).forEach((e=>_e(u.errors,e))),S.state.next({errors:e?u.errors:{}})},unregister:oe,setError:ne,setFocus:(e,t={})=>{const r=h(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(q(e)),e.Form=function(e){const t=k(),[r,a]=s.default.useState(!1),{control:n=t.control,onSubmit:o,children:u,action:i,method:l=W,headers:c,encType:d,onError:f,render:m,onSuccess:y,validateStatus:p,...g}=e,_=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,h(e,t));if(o&&await o({data:e,event:t,method:l,formData:a,formDataJson:u}),i)try{const e=[c&&c["Content-Type"],d].some((e=>e&&e.includes("json"))),t=await fetch(i,{method:l,headers:{...c,...d?{"Content-Type":d}:{}},body:e?u:a});t&&(p?!p(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):y&&y({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return s.default.useEffect((()=>{a(!0)}),[]),m?s.default.createElement(s.default.Fragment,null,m({submit:_})):s.default.createElement("form",{noValidate:r,action:i,method:l,encType:d,onSubmit:_,...g},u)},e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(w.Provider,{value:r},t)},e.appendErrors=H,e.get=h,e.set=P,e.useController=q,e.useFieldArray=function(e){const t=k(),{control:r=t.control,name:a,keyName:n="id",shouldUnregister:o}=e,[u,i]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map(I)),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),T({next:({values:e,name:t})=>{if(t===d.current||!t){const t=h(e,d.current);Array.isArray(t)&&(i(t),l.current=t.map(I))}},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&&(!J(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=h(e.errors,a),s=h(r._formState.errors,a);(s?!t&&s.type||t&&(s.type!==t.type||s.message!==t.message):t&&t.type)&&(t?P(r._formState.errors,a,t):_e(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=h(r._fields,a);e&&e._f&&ce(e,r._formValues,r._options.criteriaMode===_.all,r._options.shouldUseNativeValidation,!0).then((e=>!C(e)&&r._subjects.state.next({errors:K(r._formState.errors,e,a)})))}r._subjects.values.next({name:a,values:{...r._formValues}}),r._names.focus&&$(r._fields,(e=>!!e&&e.startsWith(r._names.focus||""))),r._names.focus="",r._updateValid(),f.current=!1}),[u,a,r]),s.default.useEffect((()=>(!h(r._formValues,a)&&r._updateFieldArray(a),()=>{(r._options.shouldUnregister||o)&&r.unregister(a)})),[a,r,n,o]),{swap:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);ge(s,e,t),ge(l.current,e,t),y(s),i(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);ye(s,e,t),ye(l.current,e,t),y(s),i(s),r._updateFieldArray(a,s,ye,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=E(m(e)),n=pe(r._getFieldArray(a),s);r._names.focus=G(a,0,t),l.current=pe(l.current,s.map(I)),y(n),i(n),r._updateFieldArray(a,n,pe,{argA:fe(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=E(m(e)),n=de(r._getFieldArray(a),s);r._names.focus=G(a,n.length-1,t),l.current=de(l.current,s.map(I)),y(n),i(n),r._updateFieldArray(a,n,de,{argA:fe(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=he(r._getFieldArray(a),e);l.current=he(l.current,e),y(t),i(t),r._updateFieldArray(a,t,he,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=E(m(t)),o=me(r._getFieldArray(a),e,n);r._names.focus=G(a,e,s),l.current=me(l.current,e,n.map(I)),y(o),i(o),r._updateFieldArray(a,o,me,{argA:e,argB:fe(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=m(t),n=ve(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:I())),y(n),i([...n]),r._updateFieldArray(a,n,ve,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=E(m(e));l.current=t.map(I),y([...t]),i([...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]||I()})))),[u,n])}},e.useForm=function(e={}){const t=s.default.useRef(),r=s.default.useRef(),[a,n]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:Y(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:Y(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Me(e,(()=>n((e=>({...e}))))),formState:a});const o=t.current.control;return o._options=e,T({subject:o._subjects.state,next:e=>{O(e,o._proxyFormState,o._updateFormState,!0)&&n({...o._formState})}}),s.default.useEffect((()=>{e.values&&!Ve(e.values,r.current)?(o._reset(e.values,o._options.resetOptions),r.current=e.values):o._resetDefaultValues()}),[e.values,o]),s.default.useEffect((()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()})),t.current.formState=D(a,o),t.current},e.useFormContext=k,e.useFormState=U,e.useWatch=N,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,d=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),c=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?[]:{},r||c(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=m(e[r]));else t=e}return t}var y=e=>Array.isArray(e)?e.filter(Boolean):[],p=e=>void 0===e,h=(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 g={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},_={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},v="max",b="min",A="maxLength",x="minLength",V="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]!==_.all&&(t._proxyFormState[a]=!s||_.all),r&&(r[a]=!0),e[a]}});return a},C=e=>o(e)&&!Object.keys(e).length,E=(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||_.all)))},O=e=>Array.isArray(e)?e:[e],j=(e,t,r)=>r&&t?e===t:!e||!t||e===t||O(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function T(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 U(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),d=s.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=s.default.useRef(n);return c.current=n,T({disabled:a,next:e=>l.current&&j(c.current,e.name,i)&&E(e,d.current,r._updateFormState)&&o({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>(l.current=!0,d.current.isValid&&r._updateValid(!0),()=>{l.current=!1})),[r]),D(u,r,d.current,!1)}var B=e=>"string"==typeof e,L=(e,t,r,s,a)=>B(e)?(s&&t.watch.add(e),h(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),h(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,T({disabled:i,subject:r._subjects.values,next:e=>{j(o.current,e.name,u)&&d(m(L(o.current,r._names,e.values||r._formValues,!1,n)))}});const[l,d]=s.default.useState(r._getWatch(a,n));return s.default.useEffect((()=>r._removeUnmounted())),l}var R=e=>/^\w*$/.test(e),M=e=>y(e.replace(/["|']|\]/g,"").split(/\.|\[/));function P(e,t,r){let s=-1;const a=R(t)?[t]:M(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 q(e){const t=k(),{name:r,control:a=t.control,shouldUnregister:n}=e,i=d(a._names.array,r),u=N({control:a,name:r,defaultValue:h(a._formValues,r,h(a._defaultValues,r,e.defaultValue)),exact:!0}),o=U({control:a,name:r}),c=s.default.useRef(a.register(r,{...e.rules,value:u}));return c.current=a.register(r,e.rules),s.default.useEffect((()=>{const e=a._options.shouldUnregister||n,t=(e,t)=>{const r=h(a._fields,e);r&&(r._f.mount=t)};if(t(r,!0),e){const e=m(h(a._options.defaultValues,r));P(a._defaultValues,r,e),p(h(a._formValues,r))&&P(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,disabled:o.disabled,onChange:s.default.useCallback((e=>c.current.onChange({target:{value:l(e),name:r},type:g.CHANGE})),[r]),onBlur:s.default.useCallback((()=>c.current.onBlur({target:{value:h(a._formValues,r),name:r},type:g.BLUR})),[r,a]),ref:e=>{const t=h(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:()=>!!h(o.errors,r)},isDirty:{enumerable:!0,get:()=>!!h(o.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!h(o.touchedFields,r)},error:{enumerable:!0,get:()=>h(o.errors,r)}})}}const W="post";var H=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},$=()=>{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===_.onSubmit,isOnBlur:e===_.onBlur,isOnChange:e===_.onChange,isOnAll:e===_.all,isOnTouch:e===_.onTouched}),J=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const z=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=h(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break}else o(n)&&z(n,t)}}};var K=(e,t,r)=>{const s=y(h(e,r));return P(s,"root",t[r]),P(e,r,s),e},Q=e=>"boolean"==typeof e,X=e=>"file"===e.type,Y=e=>"function"==typeof e,Z=e=>{if(!f)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ee=e=>B(e),te=e=>"radio"===e.type,re=e=>e instanceof RegExp;const se={value:!1,isValid:!1},ae={value:!0,isValid:!0};var ne=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?ae:{value:e[0].value,isValid:!0}:ae:se}return se};const ie={isValid:!1,value:null};var ue=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ie):ie;function oe(e,t,r="validate"){if(ee(e)||Array.isArray(e)&&e.every(ee)||Q(e)&&!e)return{type:r,message:ee(e)?e:"",ref:t}}var le=e=>o(e)&&!re(e)?e:{value:e,message:""},de=async(e,t,r,s,n)=>{const{ref:u,refs:l,required:d,maxLength:c,minLength:f,min:m,max:y,pattern:g,validate:_,name:w,valueAsNumber:k,mount:D,disabled:E}=e._f,O=h(t,w);if(!D||E)return{};const j=l?l[0]:u,T=e=>{s&&j.reportValidity&&(j.setCustomValidity(Q(e)?"":e||""),j.reportValidity())},U={},L=te(u),N=a(u),R=L||N,M=(k||X(u))&&p(u.value)&&p(O)||Z(u)&&""===u.value||""===O||Array.isArray(O)&&!O.length,P=H.bind(null,w,r,U),q=(e,t,r,s=A,a=x)=>{const n=e?t:r;U[w]={type:e?s:a,message:n,ref:u,...P(e?s:a,n)}};if(n?!Array.isArray(O)||!O.length:d&&(!R&&(M||i(O))||Q(O)&&!O||N&&!ne(l).isValid||L&&!ue(l).isValid)){const{value:e,message:t}=ee(d)?{value:!!d,message:d}:le(d);if(e&&(U[w]={type:F,message:t,ref:j,...P(F,t)},!r))return T(t),U}if(!(M||i(m)&&i(y))){let e,t;const s=le(y),a=le(m);if(i(O)||isNaN(O)){const r=u.valueAsDate||new Date(O),n=e=>new Date((new Date).toDateString()+" "+e),i="time"==u.type,o="week"==u.type;B(s.value)&&O&&(e=i?n(O)>n(s.value):o?O>s.value:r>new Date(s.value)),B(a.value)&&O&&(t=i?n(O)<n(a.value):o?O<a.value:r<new Date(a.value))}else{const r=u.valueAsNumber||(O?+O:O);i(s.value)||(e=r>s.value),i(a.value)||(t=r<a.value)}if((e||t)&&(q(!!e,s.message,a.message,v,b),!r))return T(U[w].message),U}if((c||f)&&!M&&(B(O)||n&&Array.isArray(O))){const e=le(c),t=le(f),s=!i(e.value)&&O.length>+e.value,a=!i(t.value)&&O.length<+t.value;if((s||a)&&(q(s,e.message,t.message),!r))return T(U[w].message),U}if(g&&!M&&B(O)){const{value:e,message:t}=le(g);if(re(e)&&!O.match(e)&&(U[w]={type:V,message:t,ref:u,...P(V,t)},!r))return T(t),U}if(_)if(Y(_)){const e=oe(await _(O,t),j);if(e&&(U[w]={...e,...P(S,e.message)},!r))return T(e.message),U}else if(o(_)){let e={};for(const s in _){if(!C(e)&&!r)break;const a=oe(await _[s](O,t),j,s);a&&(e={...a,...P(s,a.message)},T(a.message),r&&(U[w]=e))}if(!C(e)&&(U[w]={ref:j,...e},!r))return U}return T(!0),U};function ce(e,t){return[...e,...O(t)]}var fe=e=>Array.isArray(e)?e.map((()=>{})):void 0;function me(e,t,r){return[...e.slice(0,t),...O(r),...e.slice(t)]}var ye=(e,t,r)=>Array.isArray(e)?(p(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function pe(e,t){return[...O(t),...O(e)]}var he=(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,O(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:R(t)?[t]:M(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(e.hasOwnProperty(t)&&!p(e[t]))return!1;return!0}(s))&&_e(e,r.slice(0,-1)),e}var ve=(e,t,r)=>(e[t]=r,e);function be(){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 Ae=e=>i(e)||!u(e);function xe(e,t){if(Ae(e)||Ae(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)?!xe(r,e):r!==e)return!1}}return!0}var Ve=e=>"select-multiple"===e.type,Fe=e=>te(e)||a(e),Se=e=>Z(e)&&e.isConnected,we=e=>{for(const t in e)if(Y(e[t]))return!0;return!1};function ke(e,t={}){const r=Array.isArray(e);if(o(e)||r)for(const r in e)Array.isArray(e[r])||o(e[r])&&!we(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ke(e[r],t[r])):i(e[r])||(t[r]=!0);return t}function De(e,t,r){const s=Array.isArray(e);if(o(e)||s)for(const s in e)Array.isArray(e[s])||o(e[s])&&!we(e[s])?p(t)||Ae(r[s])?r[s]=Array.isArray(e[s])?ke(e[s],[]):{...ke(e[s])}:De(e[s],i(t)?{}:t[s],r[s]):r[s]=!xe(e[s],t[s]);return r}var Ce=(e,t)=>De(e,t,ke(t)),Ee=(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 X(t)?t.files:te(t)?ue(e.refs).value:Ve(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ne(e.refs).value:Ee(p(t.value)?e.ref.value:t.value,e)}var je=(e,t,r,s)=>{const a={};for(const r of e){const e=h(t,r);e&&P(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Te=e=>p(e)?e:re(e)?e.source:o(e)?re(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 Be(e,t,r){const s=h(e,r);if(s||R(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=h(t,s),i=h(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 Le=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Ne=(e,t)=>!y(h(e,t)).length&&_e(e,t);const Re={mode:_.onSubmit,reValidateMode:_.onChange,shouldFocusError:!0};function Me(e={},t){let r,s={...Re,...e},u={submitCount:0,isDirty:!1,isLoading:Y(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},c={},v=(o(s.defaultValues)||o(s.values))&&m(s.defaultValues||s.values)||{},b=s.shouldUnregister?{}:m(v),A={action:!1,mount:!1,watch:!1},x={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:be(),array:be(),state:be()},w=e.resetOptions&&e.resetOptions.keepDirtyValues,k=G(s.mode),D=G(s.reValidateMode),E=s.criteriaMode===_.all,j=async e=>{if(F.isValid||e){const e=s.resolver?C((await M()).errors):await q(c,!0);e!==u.isValid&&S.state.next({isValid:e})}},T=e=>F.isValidating&&S.state.next({isValidating:e}),U=(e,t,r,s)=>{const a=h(c,e);if(a){const n=h(b,e,p(r)?h(v,e):r);p(n)||s&&s.defaultChecked||t?P(b,e,t?n:Oe(a._f)):$(e,n),A.mount&&j()}},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=xe(h(v,e),t);i=h(u.dirtyFields,e),r?_e(u.dirtyFields,e):P(u.dirtyFields,e,!0),o.dirtyFields=u.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=h(u.touchedFields,e);t||(P(u.touchedFields,e,r),o.touchedFields=u.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(o),n?o:{}},R=(t,s,a,n)=>{const i=h(u.errors,t),o=F.isValid&&Q(s)&&u.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{P(u.errors,e,t),S.state.next({errors:u.errors})})(t,a),r=e=>{clearTimeout(V),V=setTimeout(l,e)},r(e.delayError)):(clearTimeout(V),r=null,a?P(u.errors,t,a):_e(u.errors,t)),(a?!xe(i,a):i)||!C(n)||o){const e={...n,...o&&Q(s)?{isValid:s}:{},errors:u.errors,name:t};u={...u,...e},S.state.next(e)}T(!1)},M=async e=>s.resolver(b,s.context,je(e||x.mount,c,s.criteriaMode,s.shouldUseNativeValidation)),q=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=x.array.has(e.name),i=await de(n,b,E,s.shouldUseNativeValidation&&!t,a);if(i[e.name]&&(r.valid=!1,t))break;!t&&(h(i,e.name)?a?K(u.errors,i,e.name):P(u.errors,e.name,i[e.name]):_e(u.errors,e.name))}a&&await q(a,t,r)}}return r.valid},W=(e,t)=>(e&&t&&P(b,e,t),!xe(ae(),v)),H=(e,t,r)=>L(e,x,{...A.mount?b:p(t)?v:B(e)?{[e]:t}:t},r,t),$=(e,t,r={})=>{const s=h(c,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&P(b,e,Ee(t,r)),n=Z(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)):X(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&&se(e)},I=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,u=h(c,i);!x.array.has(e)&&Ae(a)&&(!u||u._f)||n(a)?$(i,a,r):I(i,a,r)}},ee=(e,r,s={})=>{const a=h(c,e),n=x.array.has(e),o=m(r);P(b,e,o),n?(S.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:Ce(v,b),isDirty:W(e,o)})):!a||a._f||i(o)?$(e,o,s):I(e,o,s),J(e,x)&&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=h(c,a);if(i){let o,d;const f=t.type?Oe(i._f):l(e),m=e.type===g.BLUR||e.type===g.FOCUS_OUT,y=!Ue(i._f)&&!s.resolver&&!h(u.errors,a)&&!i._f.deps||Le(m,h(u.touchedFields,a),u.isSubmitted,D,k),p=J(a,x,m);P(b,a,f),m?(i._f.onBlur&&i._f.onBlur(e),r&&r(0)):i._f.onChange&&i._f.onChange(e);const _=N(a,f,m,!1),v=!C(_)||p;if(!m&&S.values.next({name:a,type:e.type,values:{...b}}),y)return F.isValid&&j(),v&&S.state.next({name:a,...p?{}:_});if(!m&&p&&S.state.next({...u}),T(!0),s.resolver){const{errors:e}=await M([a]),t=Be(u.errors,c,a),r=Be(e,c,t.name||a);o=r.error,a=r.name,d=C(e)}else o=(await de(i,b,E,s.shouldUseNativeValidation))[a],n=isNaN(f)||f===h(b,a,f),n&&(o?d=!1:F.isValid&&(d=await q(c,!0)));n&&(i._f.deps&&se(i._f.deps),R(a,d,o,_))}},re=(e,t)=>{if(h(u.errors,t)&&e.focus)return e.focus(),1},se=async(e,t={})=>{let r,a;const n=O(e);if(T(!0),s.resolver){const t=await(async e=>{const{errors:t}=await M();if(e)for(const r of e){const e=h(t,r);e?P(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=>h(t,e))):r}else e?(a=(await Promise.all(n.map((async e=>{const t=h(c,e);return await q(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&j()):a=r=await q(c);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&&z(c,re,e?n:x.mount),a},ae=e=>{const t={...v,...A.mount?b:{}};return p(e)?t:B(e)?h(t,e):e.map((e=>h(t,e)))},ne=(e,t)=>({invalid:!!h((t||u).errors,e),isDirty:!!h((t||u).dirtyFields,e),isTouched:!!h((t||u).touchedFields,e),error:h((t||u).errors,e)}),ie=(e,t,r)=>{const s=(h(c,e,{_f:{}})._f||{}).ref;P(u.errors,e,{...t,ref:s}),S.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ue=(e,t={})=>{for(const r of e?O(e):x.mount)x.mount.delete(r),x.array.delete(r),t.keepValue||(_e(c,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&&j()},oe=(e,t={})=>{let r=h(c,e);const a=Q(t.disabled);return P(c,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),x.mount.add(e),r?a&&P(b,e,t.disabled?void 0:h(b,e,Oe(r._f))):U(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.progressive?{required:!!t.required,min:Te(t.min),max:Te(t.max),minLength:Te(t.minLength),maxLength:Te(t.maxLength),pattern:Te(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:a=>{if(a){oe(e,t),r=h(c,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=Fe(s),i=r._f.refs||[];if(n?i.find((e=>e===s)):s===r._f.ref)return;P(c,e,{_f:{...r._f,...n?{refs:[...i.filter(Se),s,...Array.isArray(h(v,e))?[{}]:[]],ref:{type:s.type,name:e}}:{ref:s}}}),U(e,!1,void 0,s)}else r=h(c,e,{}),r._f&&(r._f.mount=!1),(s.shouldUnregister||t.shouldUnregister)&&(!d(x.array,e)||!A.action)&&x.unMount.add(e)}}},le=()=>s.shouldFocusError&&z(c,re,x.mount),ce=(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 M();u.errors=e,a=t}else await q(c);_e(u.errors,"root"),C(u.errors)?(S.state.next({errors:{}}),await e(a,r)):(t&&await t({...u.errors},r),le(),setTimeout(le)),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:C(u.errors),submitCount:u.submitCount+1,errors:u.errors})},fe=(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 x.mount)h(u.dirtyFields,e)?P(i,e,h(b,e)):ee(e,h(i,e));else{if(f&&p(r))for(const e of x.mount){const t=h(c,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Z(e)){const t=e.closest("form");if(t){t.reset();break}}}}c={}}b=e.shouldUnregister?s.keepDefaultValues?m(v):{}:m(i),S.array.next({values:{...i}}),S.values.next({values:{...i}})}x={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||xe(r,v)),isSubmitted:!!s.keepIsSubmitted&&u.isSubmitted,dirtyFields:s.keepDirtyValues?u.dirtyFields:s.keepDefaultValues&&r?Ce(v,r):{},touchedFields:s.keepTouched?u.touchedFields:{},errors:s.keepErrors?u.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},me=(e,t)=>fe(Y(e)?e(b):e,t);return{control:{register:oe,unregister:ue,getFieldState:ne,handleSubmit:ce,setError:ie,_executeSchema:M,_getWatch:H,_getDirty:W,_updateValid:j,_removeUnmounted:()=>{for(const e of x.unMount){const t=h(c,e);t&&(t._f.refs?t._f.refs.every((e=>!Se(e))):!Se(t._f.ref))&&ue(e)}x.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(A.action=!0,n&&Array.isArray(h(c,e))){const t=r(h(c,e),s.argA,s.argB);a&&P(c,e,t)}if(n&&Array.isArray(h(u.errors,e))){const t=r(h(u.errors,e),s.argA,s.argB);a&&P(u.errors,e,t),Ne(u.errors,e)}if(F.touchedFields&&n&&Array.isArray(h(u.touchedFields,e))){const t=r(h(u.touchedFields,e),s.argA,s.argB);a&&P(u.touchedFields,e,t)}F.dirtyFields&&(u.dirtyFields=Ce(v,b)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else P(b,e,t)},_getFieldArray:t=>y(h(A.mount?b:v,t,e.shouldUnregister?h(v,t,[]):[])),_reset:fe,_resetDefaultValues:()=>Y(s.defaultValues)&&s.defaultValues().then((e=>{me(e,s.resetOptions),S.state.next({isLoading:!1})})),_updateFormState:e=>{u={...u,...e}},_disableForm:t=>{Q(e.disabled)&&(S.state.next({disabled:e.disabled}),z(c,(e=>{e.disabled=t}),0,!1))},_subjects:S,_proxyFormState:F,get _fields(){return c},get _formValues(){return b},get _state(){return A},set _state(e){A=e},get _defaultValues(){return v},get _names(){return x},set _names(e){x=e},get _formState(){return u},set _formState(e){u=e},get _options(){return s},set _options(e){s={...s,...e}}},trigger:se,register:oe,handleSubmit:ce,watch:(e,t)=>Y(e)?S.values.subscribe({next:r=>e(H(void 0,t),r)}):H(e,t,!0),setValue:ee,getValues:ae,reset:me,resetField:(e,t={})=>{h(c,e)&&(p(t.defaultValue)?ee(e,h(v,e)):(ee(e,t.defaultValue),P(v,e,t.defaultValue)),t.keepTouched||_e(u.touchedFields,e),t.keepDirty||(_e(u.dirtyFields,e),u.isDirty=t.defaultValue?W(e,h(v,e)):W()),t.keepError||(_e(u.errors,e),F.isValid&&j()),S.state.next({...u}))},clearErrors:e=>{e&&O(e).forEach((e=>_e(u.errors,e))),S.state.next({errors:e?u.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=h(c,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:ne}}e.Controller=e=>e.render(q(e)),e.Form=function(e){const t=k(),[r,a]=s.default.useState(!1),{control:n=t.control,onSubmit:i,children:u,action:o,method:l=W,headers:d,encType:c,onError:f,render:m,onSuccess:y,validateStatus:p,...g}=e,_=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,h(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...d,...c?{"Content-Type":c}:{}},body:e?u:a});t&&(p?!p(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):y&&y({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return s.default.useEffect((()=>{a(!0)}),[]),m?s.default.createElement(s.default.Fragment,null,m({submit:_})):s.default.createElement("form",{noValidate:r,action:o,method:l,encType:c,onSubmit:_,...g},u)},e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(w.Provider,{value:r},t)},e.appendErrors=H,e.get=h,e.set=P,e.useController=q,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($)),d=s.default.useRef(u),c=s.default.useRef(a),f=s.default.useRef(!1);c.current=a,d.current=u,r._names.array.add(a),e.rules&&r.register(a,e.rules),T({next:({values:e,name:t})=>{if(t===c.current||!t){const t=h(e,c.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,J(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=h(e.errors,a),s=h(r._formState.errors,a);(s?!t&&s.type||t&&(s.type!==t.type||s.message!==t.message):t&&t.type)&&(t?P(r._formState.errors,a,t):_e(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=h(r._fields,a);e&&e._f&&de(e,r._formValues,r._options.criteriaMode===_.all,r._options.shouldUseNativeValidation,!0).then((e=>!C(e)&&r._subjects.state.next({errors:K(r._formState.errors,e,a)})))}r._subjects.values.next({name:a,values:{...r._formValues}}),r._names.focus&&z(r._fields,((e,t)=>{if(r._names.focus&&t.startsWith(r._names.focus)&&e.focus)return e.focus(),1})),r._names.focus="",r._updateValid(),f.current=!1}),[u,a,r]),s.default.useEffect((()=>(!h(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);ye(s,e,t),ye(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,ye,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=O(m(e)),n=pe(r._getFieldArray(a),s);r._names.focus=I(a,0,t),l.current=pe(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,pe,{argA:fe(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=O(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:fe(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=he(r._getFieldArray(a),e);l.current=he(l.current,e),y(t),o(t),r._updateFieldArray(a,t,he,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=O(m(t)),i=me(r._getFieldArray(a),e,n);r._names.focus=I(a,e,s),l.current=me(l.current,e,n.map($)),y(i),o(i),r._updateFieldArray(a,i,me,{argA:e,argB:fe(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=m(t),n=ve(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,ve,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=O(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=s.default.useRef(),[a,n]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:Y(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Y(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Me(e,(()=>n((e=>({...e}))))),formState:a});const i=t.current.control;return i._options=e,T({subject:i._subjects.state,next:e=>{E(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),s.default.useEffect((()=>{e.values&&!xe(e.values,r.current)?(i._reset(e.values,i._options.resetOptions),r.current=e.values):i._resetDefaultValues()}),[e.values,i]),s.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),s.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),t.current.formState=D(a,i),t.current},e.useFormContext=k,e.useFormState=U,e.useWatch=N,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.js.map
import { FieldValues, UseFormReturn } from '../types';
export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any>(props: Partial<{
mode: keyof import("../types").ValidationMode;
disabled: boolean;
reValidateMode: "onSubmit" | "onChange" | "onBlur";

@@ -5,0 +6,0 @@ defaultValues: ((payload?: unknown) => Promise<TFieldValues>) | import("../types").DefaultValues<TFieldValues>;

@@ -14,2 +14,3 @@ import React from 'react';

value: FieldPathValue<TFieldValues, TName>;
disabled: boolean;
name: TName;

@@ -16,0 +17,0 @@ ref: RefCallBack;

@@ -60,2 +60,3 @@ import React from 'react';

mode: Mode;
disabled: boolean;
reValidateMode: Exclude<Mode, 'onTouched' | 'all'>;

@@ -94,2 +95,3 @@ defaultValues: DefaultValues<TFieldValues> | AsyncDefaultValues<TFieldValues>;

isValid: boolean;
disabled: boolean;
submitCount: number;

@@ -598,2 +600,3 @@ defaultValues?: undefined | Readonly<DeepPartial<TFieldValues>>;

handleSubmit: UseFormHandleSubmit<TFieldValues>;
_disableForm: (disabled?: boolean) => void;
unregister: UseFormUnregister<TFieldValues>;

@@ -600,0 +603,0 @@ getFieldState: UseFormGetFieldState<TFieldValues>;

{
"name": "react-hook-form",
"description": "Performant, flexible and extensible forms library for React Hooks",
"version": "7.45.4",
"version": "7.46.0-next.0",
"main": "dist/index.cjs.js",

@@ -6,0 +6,0 @@ "module": "dist/index.esm.mjs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc