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

react-hook-form

Package Overview
Dependencies
Maintainers
1
Versions
1031
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hook-form - npm Package Compare versions

Comparing version 7.44.0-rc.1 to 7.44.0-rc.3

2

dist/index.cjs.js

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

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

@@ -628,6 +628,6 @@ import React from 'react';

};
export type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any> = {
export type FormProviderProps<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined> = {
children: React.ReactNode | React.ReactNode[];
} & UseFormReturn<TFieldValues, TContext>;
} & UseFormReturn<TFieldValues, TContext, TTransformedValues>;
export {};
//# sourceMappingURL=form.d.ts.map

@@ -33,3 +33,3 @@ /// <reference types="react" />

*/
export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues>;
export declare const useFormContext: <TFieldValues extends FieldValues, TransformedValues extends FieldValues | undefined = undefined>() => UseFormReturn<TFieldValues>;
/**

@@ -65,3 +65,3 @@ * A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.

*/
export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any>(props: FormProviderProps<TFieldValues, TContext>) => JSX.Element;
export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined>(props: FormProviderProps<TFieldValues, TContext, TTransformedValues>) => JSX.Element;
//# sourceMappingURL=useFormContext.d.ts.map
{
"name": "react-hook-form",
"description": "Performant, flexible and extensible forms library for React Hooks",
"version": "7.44.0-rc.1",
"version": "7.44.0-rc.3",
"main": "dist/index.cjs.js",

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

@@ -87,2 +87,5 @@ <div align="center">

</a>
<a target="_blank" href="https://www.thinkmill.com.au/">
<img width="94" src="https://images.opencollective.com/thinkmill/28910ec/logo/256.png" />
</a>

@@ -89,0 +92,0 @@ ### Backers

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc