react-hook-form
Advanced tools
Comparing version 7.44.0-next.1 to 7.44.0-rc.0
import * as React from 'react'; | ||
import { Control, FieldValues, SubmitHandler } from './types'; | ||
export type FormProps<T extends FieldValues, U extends FieldValues | undefined = undefined> = Partial<{ | ||
control: Control<T>; | ||
export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = Partial<{ | ||
control: Control<TFieldValues>; | ||
children?: React.ReactNode | React.ReactNode[]; | ||
@@ -9,3 +9,3 @@ render?: (props: { | ||
}) => React.ReactNode | React.ReactNode[]; | ||
onSubmit: U extends FieldValues ? SubmitHandler<U> : SubmitHandler<T>; | ||
onSubmit: TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : SubmitHandler<TFieldValues>; | ||
}> & Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onError'> & (Partial<{ | ||
@@ -31,5 +31,7 @@ onSuccess: ({ response }: { | ||
fetcher: (action: string, payload: { | ||
values?: T; | ||
values?: TFieldValues; | ||
method: string; | ||
event?: React.BaseSyntheticEvent; | ||
formData: FormData; | ||
formDataJson: string; | ||
}) => Promise<void> | void; | ||
@@ -36,0 +38,0 @@ }>); |
@@ -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,o=e=>null==e;const u=e=>"object"==typeof e;var l=e=>!o(e)&&!Array.isArray(e)&&u(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=e=>Array.isArray(e)?e.filter(Boolean):[],m=e=>void 0===e,y=(e,t,r)=>{if(!t||!l(e))return r;const s=f(t.split(/[,[\].]+?/)).reduce(((e,t)=>o(e)?e:e[t]),e);return m(s)||s===e?m(e[t])?r:e[t]:s};const p="blur",h="focusout",g="change",_="onBlur",v="onChange",b="onSubmit",x="onTouched",A="all",V="max",F="min",S="maxLength",w="minLength",k="pattern",D="required",C="validate",E=s.default.createContext(null),j=()=>s.default.useContext(E);var O=(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]!==A&&(t._proxyFormState[a]=!s||A),r&&(r[a]=!0),e[a]}});return a},T=e=>l(e)&&!Object.keys(e).length,U=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return T(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||A)))},B=e=>Array.isArray(e)?e:[e],L=(e,t,r)=>r&&t?e===t:!e||!t||e===t||B(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function M(e){const t=s.default.useRef(e);t.current=e,s.default.useEffect((()=>{const r=!e.disabled&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}}),[e.disabled])}function N(e){const t=j(),{control:r=t.control,disabled:a,name:n,exact:i}=e||{},[o,u]=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,M({disabled:a,next:e=>l.current&&L(d.current,e.name,i)&&U(e,c.current,r._updateFormState)&&u({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>{l.current=!0;const e=r._proxyFormState.isDirty&&r._getDirty();return e!==r._formState.isDirty&&r._subjects.state.next({isDirty:e}),c.current.isValid&&r._updateValid(!0),()=>{l.current=!1}}),[r]),O(o,r,c.current,!1)}var R=e=>"string"==typeof e,P=(e,t,r,s,a)=>R(e)?(s&&t.watch.add(e),y(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),y(r,e)))):(s&&(t.watchAll=!0),r),q="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function W(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(q&&(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]=W(e[r]);else t=e}return t}function $(e){const t=j(),{control:r=t.control,name:a,defaultValue:n,disabled:i,exact:o}=e||{},u=s.default.useRef(a);u.current=a,M({disabled:i,subject:r._subjects.watch,next:e=>{L(u.current,e.name,o)&&c(W(P(u.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}function I(e){const t=j(),{name:r,control:a=t.control,shouldUnregister:n}=e,i=d(a._names.array,r),o=$({control:a,name:r,defaultValue:y(a._formValues,r,y(a._defaultValues,r,e.defaultValue)),exact:!0}),u=N({control:a,name:r}),l=s.default.useRef(a.register(r,{...e.rules,value:o}));return s.default.useEffect((()=>{const e=(e,t)=>{const r=y(a._fields,e);r&&(r._f.mount=t)};return e(r,!0),()=>{const t=a._options.shouldUnregister||n;(i?t&&!a._stateFlags.action:t)?a.unregister(r):e(r,!1)}}),[r,a,i,n]),{field:{name:r,value:o,onChange:s.default.useCallback((e=>l.current.onChange({target:{value:c(e),name:r},type:g})),[r]),onBlur:s.default.useCallback((()=>l.current.onBlur({target:{value:y(a._formValues,r),name:r},type:p})),[r,a]),ref:e=>{const t=y(a._fields,r);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:u,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!y(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!y(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!y(u.touchedFields,r)},error:{enumerable:!0,get:()=>y(u.errors,r)}})}}const H="post";var z=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},J=e=>/^\w*$/.test(e),G=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/));function K(e,t,r){let s=-1;const a=J(t)?[t]:G(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}const Q=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=y(e,s);if(r){const{_f:e,...s}=r;if(e&&t(e.name)){if(e.ref.focus){e.ref.focus();break}if(e.refs&&e.refs[0].focus){e.refs[0].focus();break}}else 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||m(r.shouldFocus)?r.focusName||`${e}.${m(r.focusIndex)?t:r.focusIndex}.`:"",Z=e=>({isOnSubmit:!e||e===b,isOnBlur:e===_,isOnChange:e===v,isOnAll:e===A,isOnTouch:e===x}),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=f(y(e,r));return K(s,"root",t[r]),K(e,r,s),e},re=e=>"boolean"==typeof e,se=e=>"file"===e.type,ae=e=>"function"==typeof e,ne=e=>{if(!q)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ie=e=>R(e),oe=e=>"radio"===e.type,ue=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&&!m(e[0].attributes.value)?m(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)&&!ue(e)?e:{value:e,message:""},he=async(e,t,r,s,a)=>{const{ref:i,refs:u,required:c,maxLength:d,minLength:f,min:p,max:h,pattern:g,validate:_,name:v,valueAsNumber:b,mount:x,disabled:A}=e._f,E=y(t,v);if(!x||A)return{};const j=u?u[0]:i,O=e=>{s&&j.reportValidity&&(j.setCustomValidity(re(e)?"":e||""),j.reportValidity())},U={},B=oe(i),L=n(i),M=B||L,N=(b||se(i))&&m(i.value)&&m(E)||ne(i)&&""===i.value||""===E||Array.isArray(E)&&!E.length,P=z.bind(null,v,r,U),q=(e,t,r,s=S,a=w)=>{const n=e?t:r;U[v]={type:e?s:a,message:n,ref:i,...P(e?s:a,n)}};if(a?!Array.isArray(E)||!E.length:c&&(!M&&(N||o(E))||re(E)&&!E||L&&!de(u).isValid||B&&!me(u).isValid)){const{value:e,message:t}=ie(c)?{value:!!c,message:c}:pe(c);if(e&&(U[v]={type:D,message:t,ref:j,...P(D,t)},!r))return O(t),U}if(!(N||o(p)&&o(h))){let e,t;const s=pe(h),a=pe(p);if(o(E)||isNaN(E)){const r=i.valueAsDate||new Date(E),n=e=>new Date((new Date).toDateString()+" "+e),o="time"==i.type,u="week"==i.type;R(s.value)&&E&&(e=o?n(E)>n(s.value):u?E>s.value:r>new Date(s.value)),R(a.value)&&E&&(t=o?n(E)<n(a.value):u?E<a.value:r<new Date(a.value))}else{const r=i.valueAsNumber||(E?+E:E);o(s.value)||(e=r>s.value),o(a.value)||(t=r<a.value)}if((e||t)&&(q(!!e,s.message,a.message,V,F),!r))return O(U[v].message),U}if((d||f)&&!N&&(R(E)||a&&Array.isArray(E))){const e=pe(d),t=pe(f),s=!o(e.value)&&E.length>e.value,a=!o(t.value)&&E.length<t.value;if((s||a)&&(q(s,e.message,t.message),!r))return O(U[v].message),U}if(g&&!N&&R(E)){const{value:e,message:t}=pe(g);if(ue(e)&&!E.match(e)&&(U[v]={type:k,message:t,ref:i,...P(k,t)},!r))return O(t),U}if(_)if(ae(_)){const e=ye(await _(E,t),j);if(e&&(U[v]={...e,...P(C,e.message)},!r))return O(e.message),U}else if(l(_)){let e={};for(const s in _){if(!T(e)&&!r)break;const a=ye(await _[s](E,t),j,s);a&&(e={...a,...P(s,a.message)},O(a.message),r&&(U[v]=e))}if(!T(e)&&(U[v]={ref:j,...e},!r))return U}return O(!0),U};function ge(e,t){return[...e,...B(t)]}var _e=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ve(e,t,r){return[...e.slice(0,t),...B(r),...e.slice(t)]}var be=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function xe(e,t){return[...B(t),...B(e)]}var Ae=(e,t)=>m(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return f(s).length?s:[]}(e,B(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:J(t)?[t]:G(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=m(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(l(s)&&T(s)||Array.isArray(s)&&function(e){for(const t in e)if(!m(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(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var ke=e=>o(e)||!u(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,Ee=e=>ne(e)&&e.isConnected,je=e=>{for(const t in e)if(ae(e[t]))return!0;return!1};function Oe(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])?[]:{},Oe(e[r],t[r])):o(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])?m(t)||ke(r[s])?r[s]=Array.isArray(e[s])?Oe(e[s],[]):{...Oe(e[s])}:Te(e[s],o(t)?{}:t[s],r[s]):De(e[s],t[s])?delete r[s]:r[s]=!0;return r}var Ue=(e,t)=>Te(e,t,Oe(t)),Be=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&R(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 se(t)?t.files:oe(t)?me(e.refs).value:Ce(t)?[...t.selectedOptions].map((({value:e})=>e)):n(t)?de(e.refs).value:Be(m(t.value)?e.ref.value:t.value,e)}var Me=e=>m(e)?e:ue(e)?e.source:l(e)?ue(e.value)?e.value.source:e.value:e;function Ne(e,t,r){const s=y(e,r);if(s||J(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=y(t,s),i=y(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}const Re={mode:b,reValidateMode:v,shouldFocusError:!0};function Pe(e={},t){let r={...Re,...e};const s=e.resetOptions&&e.resetOptions.keepDirtyValues;let a,u={submitCount:0,isDirty:!1,isLoading:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},g={},_=(l(r.defaultValues)||l(r.values))&&W(r.defaultValues||r.values)||{},v=r.shouldUnregister?{}:W(_),b={action:!1,mount:!1,watch:!1},x={mount:new Set,unMount:new Set,array:new Set,watch:new Set},V=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},S={watch:we(),array:we(),state:we()},w=Z(r.mode),k=Z(r.reValidateMode),D=r.criteriaMode===A,C=async e=>{if(F.isValid||e){const e=r.resolver?T((await L()).errors):await M(g,!0);e!==u.isValid&&S.state.next({isValid:e})}},E=e=>F.isValidating&&S.state.next({isValidating:e}),j=(e,t,r,s)=>{const a=y(g,e);if(a){const n=y(v,e,m(r)?y(_,e):r);m(n)||s&&s.defaultChecked||t?K(v,e,t?n:Le(a._f)):I(e,n),b.mount&&C()}},O=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e};if(!r||s){F.isDirty&&(i=u.isDirty,u.isDirty=o.isDirty=N(),n=i!==o.isDirty);const r=De(y(_,e),t);i=y(u.dirtyFields,e),r?Fe(u.dirtyFields,e):K(u.dirtyFields,e,!0),o.dirtyFields=u.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=y(u.touchedFields,e);t||(K(u.touchedFields,e,r),o.touchedFields=u.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(o),n?o:{}},U=(t,r,s,n)=>{const i=y(u.errors,t),o=F.isValid&&re(r)&&u.isValid!==r;var l;if(e.delayError&&s?(l=()=>((e,t)=>{K(u.errors,e,t),S.state.next({errors:u.errors})})(t,s),a=e=>{clearTimeout(V),V=window.setTimeout(l,e)},a(e.delayError)):(clearTimeout(V),a=null,s?K(u.errors,t,s):Fe(u.errors,t)),(s?!De(i,s):i)||!T(n)||o){const e={...n,...o&&re(r)?{isValid:r}:{},errors:u.errors,name:t};u={...u,...e},S.state.next(e)}E(!1)},L=async e=>await r.resolver(v,r.context,((e,t,r,s)=>{const a={};for(const r of e){const e=y(t,r);e&&K(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||x.mount,g,r.criteriaMode,r.shouldUseNativeValidation)),M=async(e,t,s={valid:!0})=>{for(const a in e){const n=e[a];if(n){const{_f:e,...a}=n;if(e){const a=x.array.has(e.name),i=await he(n,v,D,r.shouldUseNativeValidation,a);if(i[e.name]&&(s.valid=!1,t))break;!t&&(y(i,e.name)?a?te(u.errors,i,e.name):K(u.errors,e.name,i[e.name]):Fe(u.errors,e.name))}a&&await M(a,t,s)}}return s.valid},N=(e,t)=>(e&&t&&K(v,e,t),!De(X(),_)),$=(e,t,r)=>P(e,x,{...b.mount?v:m(t)?_:R(e)?{[e]:t}:t},r,t),I=(e,t,r={})=>{const s=y(g,e);let a=t;if(s){const r=s._f;r&&(!r.disabled&&K(v,e,Be(t,r)),a=ne(r.ref)&&o(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||S.watch.next({name:e})))}(r.shouldDirty||r.shouldTouch)&&O(e,a,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&G(e)},H=(e,t,r)=>{for(const s in t){const a=t[s],n=`${e}.${s}`,o=y(g,n);!x.array.has(e)&&ke(a)&&(!o||o._f)||i(a)?I(n,a,r):H(n,a,r)}},z=(e,r,s={})=>{const a=y(g,e),n=x.array.has(e),i=W(r);K(v,e,i),n?(S.array.next({name:e,values:v}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:Ue(_,v),isDirty:N(e,i)})):!a||a._f||o(i)?I(e,i,s):H(e,i,s),ee(e,x)&&S.state.next({}),S.watch.next({name:e}),!b.mount&&t()},J=async e=>{const t=e.target;let s=t.name;const n=y(g,s);if(n){let o,l;const d=t.type?Le(n._f):c(e),f=e.type===p||e.type===h,m=!((i=n._f).mount&&(i.required||i.min||i.max||i.maxLength||i.minLength||i.pattern||i.validate)||r.resolver||y(u.errors,s)||n._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))(f,y(u.touchedFields,s),u.isSubmitted,k,w),_=ee(s,x,f);K(v,s,d),f?(n._f.onBlur&&n._f.onBlur(e),a&&a(0)):n._f.onChange&&n._f.onChange(e);const b=O(s,d,f,!1),A=!T(b)||_;if(!f&&S.watch.next({name:s,type:e.type}),m)return F.isValid&&C(),A&&S.state.next({name:s,..._?{}:b});if(!f&&_&&S.state.next({}),E(!0),r.resolver){const{errors:e}=await L([s]),t=Ne(u.errors,g,s),r=Ne(e,g,t.name||s);o=r.error,s=r.name,l=T(e)}else o=(await he(n,v,D,r.shouldUseNativeValidation))[s],o?l=!1:F.isValid&&(l=await M(g,!0));n._f.deps&&G(n._f.deps),U(s,l,o,b)}var i},G=async(e,t={})=>{let s,a;const n=B(e);if(E(!0),r.resolver){const t=await(async e=>{const{errors:t}=await L();if(e)for(const r of e){const e=y(t,r);e?K(u.errors,r,e):Fe(u.errors,r)}else u.errors=t;return t})(m(e)?e:n);s=T(t),a=e?!n.some((e=>y(t,e))):s}else e?(a=(await Promise.all(n.map((async e=>{const t=y(g,e);return await M(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&C()):a=s=await M(g);return S.state.next({...!R(e)||F.isValid&&s!==u.isValid?{}:{name:e},...r.resolver||!e?{isValid:s}:{},errors:u.errors,isValidating:!1}),t.shouldFocus&&!a&&Q(g,(e=>e&&y(u.errors,e)),e?n:x.mount),a},X=e=>{const t={..._,...b.mount?v:{}};return m(e)?t:R(e)?y(t,e):e.map((e=>y(t,e)))},Y=(e,t)=>({invalid:!!y((t||u).errors,e),isDirty:!!y((t||u).dirtyFields,e),isTouched:!!y((t||u).touchedFields,e),error:y((t||u).errors,e)}),ie=(e,t,r)=>{const s=(y(g,e,{_f:{}})._f||{}).ref;K(u.errors,e,{...t,ref:s}),S.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ue=(e,t={})=>{for(const s of e?B(e):x.mount)x.mount.delete(s),x.array.delete(s),y(g,s)&&(t.keepValue||(Fe(g,s),Fe(v,s)),!t.keepError&&Fe(u.errors,s),!t.keepDirty&&Fe(u.dirtyFields,s),!t.keepTouched&&Fe(u.touchedFields,s),!r.shouldUnregister&&!t.keepDefaultValue&&Fe(_,s));S.watch.next({}),S.state.next({...u,...t.keepDirty?{isDirty:N()}:{}}),!t.keepIsValid&&C()},le=(e,t={})=>{let s=y(g,e);const a=re(t.disabled);return K(g,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),x.mount.add(e),s?a&&K(v,e,t.disabled?void 0:y(v,e,Le(s._f))):j(e,!0,t.value),{...a?{disabled:t.disabled}:{},...r.shouldUseNativeValidation||r.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:J,onBlur:J,ref:a=>{if(a){le(e,t),s=y(g,e);const r=m(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,i=(e=>oe(e)||n(e))(r),o=s._f.refs||[];if(i?o.find((e=>e===r)):r===s._f.ref)return;K(g,e,{_f:{...s._f,...i?{refs:[...o.filter(Ee),r,...Array.isArray(y(_,e))?[{}]:[]],ref:{type:r.type,name:e}}:{ref:r}}}),j(e,!1,void 0,r)}else s=y(g,e,{}),s._f&&(s._f.mount=!1),(r.shouldUnregister||t.shouldUnregister)&&(!d(x.array,e)||!b.action)&&x.unMount.add(e)}}},ce=()=>r.shouldFocusError&&Q(g,(e=>e&&y(u.errors,e)),x.mount),de=(e,t)=>async s=>{s&&(s.preventDefault&&s.preventDefault(),s.persist&&s.persist());let a=W(v);if(S.state.next({isSubmitting:!0}),r.resolver){const{errors:e,values:t}=await L();u.errors=e,a=t}else await M(g);Fe(u.errors,"root"),T(u.errors)?(S.state.next({errors:{}}),await e(a,s)):(t&&await t({...u.errors},s),ce()),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:T(u.errors),submitCount:u.submitCount+1,errors:u.errors})},fe=(r,a={})=>{const n=r||_,i=W(n),o=r&&!T(r)?i:_;if(a.keepDefaultValues||(_=n),!a.keepValues){if(a.keepDirtyValues||s)for(const e of x.mount)y(u.dirtyFields,e)?K(o,e,y(v,e)):z(e,y(o,e));else{if(q&&m(r))for(const e of x.mount){const t=y(g,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}}}}g={}}v=e.shouldUnregister?a.keepDefaultValues?W(_):{}:i,S.array.next({values:o}),S.watch.next({values:o})}x={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!b.mount&&t(),b.mount=!F.isValid||!!a.keepIsValid,b.watch=!!e.shouldUnregister,S.state.next({submitCount:a.keepSubmitCount?u.submitCount:0,isDirty:a.keepDirty||a.keepDirtyValues?u.isDirty:!(!a.keepDefaultValues||De(r,_)),isSubmitted:!!a.keepIsSubmitted&&u.isSubmitted,dirtyFields:a.keepDirty||a.keepDirtyValues?u.dirtyFields:a.keepDefaultValues&&r?Ue(_,r):{},touchedFields:a.keepTouched?u.touchedFields:{},errors:a.keepErrors?u.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},me=(e,t)=>fe(ae(e)?e(v):e,t);return ae(r.defaultValues)&&r.defaultValues().then((e=>{me(e,r.resetOptions),S.state.next({isLoading:!1})})),{control:{register:le,unregister:ue,getFieldState:Y,handleSubmit:de,setError:ie,_executeSchema:L,_focusError:ce,_getWatch:$,_getDirty:N,_updateValid:C,_removeUnmounted:()=>{for(const e of x.unMount){const t=y(g,e);t&&(t._f.refs?t._f.refs.every((e=>!Ee(e))):!Ee(t._f.ref))&&ue(e)}x.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(b.action=!0,n&&Array.isArray(y(g,e))){const t=r(y(g,e),s.argA,s.argB);a&&K(g,e,t)}if(n&&Array.isArray(y(u.errors,e))){const t=r(y(u.errors,e),s.argA,s.argB);a&&K(u.errors,e,t),((e,t)=>{!f(y(e,t)).length&&Fe(e,t)})(u.errors,e)}if(F.touchedFields&&n&&Array.isArray(y(u.touchedFields,e))){const t=r(y(u.touchedFields,e),s.argA,s.argB);a&&K(u.touchedFields,e,t)}F.dirtyFields&&(u.dirtyFields=Ue(_,v)),S.state.next({name:e,isDirty:N(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else K(v,e,t)},_getFieldArray:t=>f(y(b.mount?v:_,t,e.shouldUnregister?y(_,t,[]):[])),_reset:fe,_updateFormState:e=>{u={...u,...e}},_subjects:S,_proxyFormState:F,get _fields(){return g},get _formValues(){return v},get _stateFlags(){return b},set _stateFlags(e){b=e},get _defaultValues(){return _},get _names(){return x},set _names(e){x=e},get _formState(){return u},set _formState(e){u=e},get _options(){return r},set _options(e){r={...r,...e}}},trigger:G,register:le,handleSubmit:de,watch:(e,t)=>ae(e)?S.watch.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:z,getValues:X,reset:me,resetField:(e,t={})=>{y(g,e)&&(m(t.defaultValue)?z(e,y(_,e)):(z(e,t.defaultValue),K(_,e,t.defaultValue)),t.keepTouched||Fe(u.touchedFields,e),t.keepDirty||(Fe(u.dirtyFields,e),u.isDirty=t.defaultValue?N(e,y(_,e)):N()),t.keepError||(Fe(u.errors,e),F.isValid&&C()),S.state.next({...u}))},clearErrors:e=>{e&&B(e).forEach((e=>Fe(u.errors,e))),S.state.next({errors:e?u.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=y(g,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(I(e)),exports.Form=function(e){const t=j(),[r,s]=a.useState(!1),{control:n=t.control,onSubmit:i,children:o,action:u,method:l=H,headers:c,encType:d,onError:f,render:m,onSuccess:p,validateStatus:h,fetcher:g,..._}=e,v=l===H,b=async t=>{let r=!1;await n.handleSubmit((async e=>{if(i&&i(e),u){const s=new FormData;let a=!1;if(c?a=c["Content-Type"].includes("json"):n._names.mount.forEach((t=>s.append(t,y(e,t)))),g)await g(u,{method:l,values:e,event:t});else try{const t=await fetch(u,{method:l,headers:{...c,...d?{"Content-Type":d}:{}},...v?{body:a?JSON.stringify(e):s}:{}});t&&(h?!h(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t})):p&&p({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:b})):a.createElement("form",{noValidate:r,action:u,method:l,encType:d,onSubmit:b,..._},o)},exports.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(E.Provider,{value:r},t)},exports.appendErrors=z,exports.get=y,exports.set=K,exports.useController=I,exports.useFieldArray=function(e){const t=j(),{control:r=t.control,name:a,keyName:n="id",shouldUnregister:i}=e,[o,u]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map(X)),c=s.default.useRef(o),d=s.default.useRef(a),f=s.default.useRef(!1);d.current=a,c.current=o,r._names.array.add(a),e.rules&&r.register(a,e.rules),M({next:({values:e,name:t})=>{if(t===d.current||!t){const t=y(e,d.current);Array.isArray(t)&&(u(t),l.current=t.map(X))}},subject:r._subjects.array});const m=s.default.useCallback((e=>{f.current=!0,r._updateFieldArray(a,e)}),[r,a]);return s.default.useEffect((()=>{if(r._stateFlags.action=!1,ee(a,r._names)&&r._subjects.state.next({}),f.current&&(!Z(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=y(e.errors,a),s=y(r._formState.errors,a);(s?!t&&s.type:t&&t.type)&&(t?K(r._formState.errors,a,t):Fe(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=y(r._fields,a);e&&e._f&&he(e,r._formValues,r._options.criteriaMode===A,r._options.shouldUseNativeValidation,!0).then((e=>!T(e)&&r._subjects.state.next({errors:te(r._formState.errors,e,a)})))}r._subjects.watch.next({name:a,values:r._formValues}),r._names.focus&&Q(r._fields,(e=>!!e&&e.startsWith(r._names.focus||""))),r._names.focus="",r._updateValid()}),[o,a,r]),s.default.useEffect((()=>(!y(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),m(s),u(s),r._updateFieldArray(a,s,Ve,{argA:e,argB:t},!1)}),[m,a,r]),move:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);be(s,e,t),be(l.current,e,t),m(s),u(s),r._updateFieldArray(a,s,be,{argA:e,argB:t},!1)}),[m,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=B(W(e)),n=xe(r._getFieldArray(a),s);r._names.focus=Y(a,0,t),l.current=xe(l.current,s.map(X)),m(n),u(n),r._updateFieldArray(a,n,xe,{argA:_e(e)})}),[m,a,r]),append:s.default.useCallback(((e,t)=>{const s=B(W(e)),n=ge(r._getFieldArray(a),s);r._names.focus=Y(a,n.length-1,t),l.current=ge(l.current,s.map(X)),m(n),u(n),r._updateFieldArray(a,n,ge,{argA:_e(e)})}),[m,a,r]),remove:s.default.useCallback((e=>{const t=Ae(r._getFieldArray(a),e);l.current=Ae(l.current,e),m(t),u(t),r._updateFieldArray(a,t,Ae,{argA:e})}),[m,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=B(W(t)),i=ve(r._getFieldArray(a),e,n);r._names.focus=Y(a,e,s),l.current=ve(l.current,e,n.map(X)),m(i),u(i),r._updateFieldArray(a,i,ve,{argA:e,argB:_e(t)})}),[m,a,r]),update:s.default.useCallback(((e,t)=>{const s=W(t),n=Se(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:X())),m(n),u([...n]),r._updateFieldArray(a,n,Se,{argA:e,argB:s},!0,!1)}),[m,a,r]),replace:s.default.useCallback((e=>{const t=B(W(e));l.current=t.map(X),m([...t]),u([...t]),r._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[m,a,r]),fields:s.default.useMemo((()=>o.map(((e,t)=>({...e,[n]:l.current[t]||X()})))),[o,n])}},exports.useForm=function(e={}){const t=s.default.useRef(),[r,a]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:!0,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,M({subject:n._subjects.state,next:e=>{U(e,n._proxyFormState,n._updateFormState,!0)&&a({...n._formState})}}),s.default.useEffect((()=>{n._stateFlags.mount||(n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()})),s.default.useEffect((()=>{e.values&&!De(e.values,n._defaultValues)&&n._reset(e.values,n._options.resetOptions)}),[e.values,n]),s.default.useEffect((()=>{r.submitCount&&n._focusError()}),[n,r.submitCount]),t.current.formState=O(r,n),t.current},exports.useFormContext=j,exports.useFormState=N,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,o=e=>null==e;const u=e=>"object"==typeof e;var l=e=>!o(e)&&!Array.isArray(e)&&u(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)=>o(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 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]!==F&&(t._proxyFormState[a]=!s||F),r&&(r[a]=!0),e[a]}});return a},B=e=>l(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||F)))},M=e=>Array.isArray(e)?e:[e],N=(e,t,r)=>r&&t?e===t:!e||!t||e===t||M(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||{},[o,u]=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&&N(d.current,e.name,i)&&L(e,c.current,r._updateFormState)&&u({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>{l.current=!0;const e=r._proxyFormState.isDirty&&r._getDirty();return e!==r._formState.isDirty&&r._subjects.state.next({isDirty:e}),c.current.isValid&&r._updateValid(!0),()=>{l.current=!1}}),[r]),U(o,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:o}=e||{},u=s.default.useRef(a);u.current=a,R({disabled:i,subject:r._subjects.values,next:e=>{N(u.current,e.name,o)&&c(m(W(u.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),o=$({control:a,name:r,defaultValue:h(a._formValues,r,h(a._defaultValues,r,e.defaultValue)),exact:!0}),u=P({control:a,name:r}),l=s.default.useRef(a.register(r,{...e.rules,value:o}));return s.default.useEffect((()=>{const e=a._options.shouldUnregister||n,t=(e,t)=>{const r=h(a._fields,e);r&&(r._f.mount=t)};return t(r,!0),e&&J(a._defaultValues,r,m(h(a._options.defaultValues,r))),()=>{(i?e&&!a._state.action:e)?a.unregister(r):t(r,!1)}}),[r,a,i,n]),{field:{name:r,value:o,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:u,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!h(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!h(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!h(u.touchedFields,r)},error:{enumerable:!0,get:()=>h(u.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),oe=e=>"radio"===e.type,ue=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)&&!ue(e)?e:{value:e,message:""},he=async(e,t,r,s,a)=>{const{ref:i,refs:u,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=u?u[0]:i,E=e=>{s&&F.reportValidity&&(F.setCustomValidity(re(e)?"":e||""),F.reportValidity())},T={},U=oe(i),L=n(i),M=U||L,N=(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&&(!M&&(N||o(V))||re(V)&&!V||L&&!de(u).isValid||U&&!me(u).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(!(N||o(m)&&o(y))){let e,t;const s=pe(y),a=pe(m);if(o(V)||isNaN(V)){const r=i.valueAsDate||new Date(V),n=e=>new Date((new Date).toDateString()+" "+e),o="time"==i.type,u="week"==i.type;q(s.value)&&V&&(e=o?n(V)>n(s.value):u?V>s.value:r>new Date(s.value)),q(a.value)&&V&&(t=o?n(V)<n(a.value):u?V<a.value:r<new Date(a.value))}else{const r=i.valueAsNumber||(V?+V:V);o(s.value)||(e=r>s.value),o(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)&&!N&&(q(V)||a&&Array.isArray(V))){const e=pe(d),t=pe(f),s=!o(e.value)&&V.length>e.value,a=!o(t.value)&&V.length<t.value;if((s||a)&&(P(s,e.message,t.message),!r))return E(T[v].message),T}if(g&&!N&&q(V)){const{value:e,message:t}=pe(g);if(ue(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(!B(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(!B(e)&&(T[v]={ref:F,...e},!r))return T}return E(!0),T};function ge(e,t){return[...e,...M(t)]}var _e=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ve(e,t,r){return[...e.slice(0,t),...M(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[...M(t),...M(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,M(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)&&B(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=>o(e)||!u(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])):o(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],o(t)?{}:t[s],r[s]):r[s]=!De(e[s],t[s]);return r}var Ue=(e,t)=>Te(e,t,Ee(t)),Be=(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 Le(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return se(t)?t.files:oe(t)?me(e.refs).value:Ce(t)?[...t.selectedOptions].map((({value:e})=>e)):n(t)?de(e.refs).value:Be(p(t.value)?e.ref.value:t.value,e)}var Me=e=>p(e)?e:ue(e)?e.source:l(e)?ue(e.value)?e.value.source:e.value:e;function Ne(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:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},u={},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?B((await N()).errors):await R(u,!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(u,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:Le(a._f)):I(e,n),x.mount&&O()}},U=(e,t,r,s,n)=>{let i=!1,o=!1;const u={name:e};if(!r||s){S.isDirty&&(o=a.isDirty,a.isDirty=u.isDirty=P(),i=o!==u.isDirty);const r=De(h(v,e),t);o=h(a.dirtyFields,e),r?Fe(a.dirtyFields,e):J(a.dirtyFields,e,!0),u.dirtyFields=a.dirtyFields,i=i||S.dirtyFields&&o!==!r}if(r){const t=h(a.touchedFields,e);t||(J(a.touchedFields,e,r),u.touchedFields=a.touchedFields,i=i||S.touchedFields&&t!==r)}return i&&n&&w.state.next(u),i?u:{}},L=(t,s,n,i)=>{const o=h(a.errors,t),u=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(o,n):o)||!B(i)||u){const e={...i,...u&&re(s)?{isValid:s}:{},errors:a.errors,name:t};a={...a,...e},w.state.next(e)}E(!1)},N=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,u,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),o=await he(i,b,j,s.shouldUseNativeValidation&&!t,n);if(o[e.name]&&(r.valid=!1,t))break;!t&&(h(o,e.name)?n?te(a.errors,o,e.name):J(a.errors,e.name,o[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(u,e);let a=t;if(s){const r=s._f;r&&(!r.disabled&&J(b,e,Be(t,r)),a=ne(r.ref)&&o(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)&&U(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}`,o=h(u,n);!A.array.has(e)&&ke(a)&&(!o||o._f)||i(a)?I(n,a,r):H(n,a,r)}},z=(e,r,s={})=>{const n=h(u,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:Ue(v,b),isDirty:P(e,l)})):!n||n._f||o(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 o=h(u,n);if(o){let d,f;const m=t.type?Le(o._f):c(e),y=e.type===g||e.type===_,p=!((l=o._f).mount&&(l.required||l.min||l.max||l.maxLength||l.minLength||l.pattern||l.validate)||s.resolver||h(a.errors,n)||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,h(a.touchedFields,n),a.isSubmitted,C,D),v=ee(n,A,y);J(b,n,m),y?(o._f.onBlur&&o._f.onBlur(e),r&&r(0)):o._f.onChange&&o._f.onChange(e);const x=U(n,m,y,!1),V=!B(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 N([n]),t=Ne(a.errors,u,n),r=Ne(e,u,t.name||n);d=r.error,n=r.name,f=B(e)}else d=(await he(o,b,j,s.shouldUseNativeValidation))[n],i=m===h(b,n,m),i&&(d?f=!1:S.isValid&&(f=await R(u,!0)));i&&(o._f.deps&&K(o._f.deps),L(n,f,d,x))}var l},K=async(e,t={})=>{let r,n;const i=M(e);if(E(!0),s.resolver){const t=await(async e=>{const{errors:t}=await N();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=B(t),n=e?!i.some((e=>h(t,e))):r}else e?(n=(await Promise.all(i.map((async e=>{const t=h(u,e);return await R(t&&t._f?{[e]:t}:t)})))).every(Boolean),(n||a.isValid)&&O()):n=r=await R(u);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(u,(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(u,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()},ue=(e,t={})=>{for(const r of e?M(e):A.mount)A.mount.delete(r),A.array.delete(r),h(u,r)&&(t.keepValue||(Fe(u,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(u,e);const a=re(t.disabled);return J(u,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,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=h(u,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,i=(e=>oe(e)||n(e))(s),o=r._f.refs||[];if(i?o.find((e=>e===s)):s===r._f.ref)return;J(u,e,{_f:{...r._f,...i?{refs:[...o.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(u,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(u,(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 N();a.errors=e,n=t}else await R(u);Fe(a.errors,"root"),B(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:B(a.errors),submitCount:a.submitCount+1,errors:a.errors})},fe=(r,s={})=>{const n=r||v,i=m(n),o=r&&!B(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(o,e,h(b,e)):z(e,h(o,e));else{if(f&&p(r))for(const e of A.mount){const t=h(u,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}}}}u={}}b=e.shouldUnregister?s.keepDefaultValues?m(v):{}:i,w.array.next({values:{...o}}),w.values.next({values:{...o}})}A={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&t(),x.mount=!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?Ue(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 ae(s.defaultValues)&&s.defaultValues().then((e=>{me(e,s.resetOptions),w.state.next({isLoading:!1})})),{control:{register:le,unregister:ue,getFieldState:Y,handleSubmit:de,setError:ie,_executeSchema:N,_getWatch:$,_getDirty:P,_updateValid:O,_removeUnmounted:()=>{for(const e of A.unMount){const t=h(u,e);t&&(t._f.refs?t._f.refs.every((e=>!je(e))):!je(t._f.ref))&&ue(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(u,e))){const t=r(h(u,e),s.argA,s.argB);n&&J(u,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=Ue(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,_updateFormState:e=>{a={...a,...e}},_subjects:w,_proxyFormState:S,get _fields(){return u},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(u,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&&M(e).forEach((e=>Fe(a.errors,e))),w.state.next({errors:e?a.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=h(u,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:o,action:u,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,a=JSON.stringify(e);if(n._names.mount.forEach((t=>s.append(t,h(e,t)))),i&&i(e),u)try{if(g)await g(u,{method:l,values:e,event:t,formData:s,formDataJson:a});else{const e=c&&c["Content-Type"].includes("json"),t=await fetch(u,{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:u,method:l,encType:d,onSubmit:v,..._},o)},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,[o,u]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map(X)),c=s.default.useRef(o),d=s.default.useRef(a),f=s.default.useRef(!1);d.current=a,c.current=o,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)&&(u(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&&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=>!B(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()}),[o,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),u(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),u(s),r._updateFieldArray(a,s,be,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=M(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),u(n),r._updateFieldArray(a,n,xe,{argA:_e(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=M(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),u(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),u(t),r._updateFieldArray(a,t,Ae,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=M(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),u(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),u([...n]),r._updateFieldArray(a,n,Se,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=M(m(e));l.current=t.map(X),y([...t]),u([...t]),r._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,r]),fields:s.default.useMemo((()=>o.map(((e,t)=>({...e,[n]:l.current[t]||X()})))),[o,n])}},exports.useForm=function(e={}){const t=s.default.useRef(),[r,a]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:!0,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=>{L(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)}),[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=U(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,o=e=>e instanceof Date,u=e=>null==e;const l=e=>"object"==typeof e;var c=e=>!u(e)&&!Array.isArray(e)&&l(e)&&!o(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=e=>Array.isArray(e)?e.filter(Boolean):[],y=e=>void 0===e,p=(e,t,r)=>{if(!t||!c(e))return r;const s=m(t.split(/[,[\].]+?/)).reduce(((e,t)=>u(e)?e:e[t]),e);return y(s)||s===e?y(e[t])?r:e[t]:s};const h="blur",g="focusout",_="change",v="onBlur",b="onChange",A="onSubmit",x="onTouched",V="all",F="max",S="min",w="maxLength",k="minLength",D="pattern",C="required",j="validate",E=a.default.createContext(null),O=()=>a.default.useContext(E);var T=(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]!==V&&(t._proxyFormState[a]=!s||V),r&&(r[a]=!0),e[a]}});return a},U=e=>c(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||V)))},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 N(e){const t=a.default.useRef(e);t.current=e,a.default.useEffect((()=>{const r=!e.disabled&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}}),[e.disabled])}function R(e){const t=O(),{control:r=t.control,disabled:s,name:n,exact:i}=e||{},[o,u]=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,N({disabled:s,next:e=>l.current&&M(d.current,e.name,i)&&B(e,c.current,r._updateFormState)&&u({...r._formState,...e}),subject:r._subjects.state}),a.default.useEffect((()=>{l.current=!0;const e=r._proxyFormState.isDirty&&r._getDirty();return e!==r._formState.isDirty&&r._subjects.state.next({isDirty:e}),c.current.isValid&&r._updateValid(!0),()=>{l.current=!1}}),[r]),T(o,r,c.current,!1)}var P=e=>"string"==typeof e,q=(e,t,r,s,a)=>P(e)?(s&&t.watch.add(e),p(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),p(r,e)))):(s&&(t.watchAll=!0),r),W="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function $(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(W&&(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]=$(e[r]);else t=e}return t}function I(e){const t=O(),{control:r=t.control,name:s,defaultValue:n,disabled:i,exact:o}=e||{},u=a.default.useRef(s);u.current=s,N({disabled:i,subject:r._subjects.watch,next:e=>{M(u.current,e.name,o)&&c($(q(u.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}function H(e){const t=O(),{name:r,control:s=t.control,shouldUnregister:n}=e,i=f(s._names.array,r),o=I({control:s,name:r,defaultValue:p(s._formValues,r,p(s._defaultValues,r,e.defaultValue)),exact:!0}),u=R({control:s,name:r}),l=a.default.useRef(s.register(r,{...e.rules,value:o}));return a.default.useEffect((()=>{const e=(e,t)=>{const r=p(s._fields,e);r&&(r._f.mount=t)};return e(r,!0),()=>{const t=s._options.shouldUnregister||n;(i?t&&!s._stateFlags.action:t)?s.unregister(r):e(r,!1)}}),[r,s,i,n]),{field:{name:r,value:o,onChange:a.default.useCallback((e=>l.current.onChange({target:{value:d(e),name:r},type:_})),[r]),onBlur:a.default.useCallback((()=>l.current.onBlur({target:{value:p(s._formValues,r),name:r},type:h})),[r,s]),ref:e=>{const t=p(s._fields,r);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:u,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!p(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!p(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!p(u.touchedFields,r)},error:{enumerable:!0,get:()=>p(u.errors,r)}})}}const z="post";var J=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},G=e=>/^\w*$/.test(e),K=e=>m(e.replace(/["|']|\]/g,"").split(/\.|\[/));function Q(e,t,r){let s=-1;const a=G(t)?[t]:K(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}const X=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=p(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||y(r.shouldFocus)?r.focusName||`${e}.${y(r.focusIndex)?t:r.focusIndex}.`:"",ee=e=>({isOnSubmit:!e||e===A,isOnBlur:e===v,isOnChange:e===b,isOnAll:e===V,isOnTouch:e===x}),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=m(p(e,r));return Q(s,"root",t[r]),Q(e,r,s),e},se=e=>"boolean"==typeof e,ae=e=>"file"===e.type,ne=e=>"function"==typeof e,ie=e=>{if(!W)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},oe=e=>P(e),ue=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&&!y(e[0].attributes.value)?y(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(oe(e)||Array.isArray(e)&&e.every(oe)||se(e)&&!e)return{type:r,message:oe(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:o,required:l,maxLength:d,minLength:f,min:m,max:h,pattern:g,validate:_,name:v,valueAsNumber:b,mount:A,disabled:x}=e._f,V=p(t,v);if(!A||x)return{};const E=o?o[0]:n,O=e=>{s&&E.reportValidity&&(E.setCustomValidity(se(e)?"":e||""),E.reportValidity())},T={},B=ue(n),L=i(n),M=B||L,N=(b||ae(n))&&y(n.value)&&y(V)||ie(n)&&""===n.value||""===V||Array.isArray(V)&&!V.length,R=J.bind(null,v,r,T),q=(e,t,r,s=w,a=k)=>{const i=e?t:r;T[v]={type:e?s:a,message:i,ref:n,...R(e?s:a,i)}};if(a?!Array.isArray(V)||!V.length:l&&(!M&&(N||u(V))||se(V)&&!V||L&&!fe(o).isValid||B&&!ye(o).isValid)){const{value:e,message:t}=oe(l)?{value:!!l,message:l}:he(l);if(e&&(T[v]={type:C,message:t,ref:E,...R(C,t)},!r))return O(t),T}if(!(N||u(m)&&u(h))){let e,t;const s=he(h),a=he(m);if(u(V)||isNaN(V)){const r=n.valueAsDate||new Date(V),i=e=>new Date((new Date).toDateString()+" "+e),o="time"==n.type,u="week"==n.type;P(s.value)&&V&&(e=o?i(V)>i(s.value):u?V>s.value:r>new Date(s.value)),P(a.value)&&V&&(t=o?i(V)<i(a.value):u?V<a.value:r<new Date(a.value))}else{const r=n.valueAsNumber||(V?+V:V);u(s.value)||(e=r>s.value),u(a.value)||(t=r<a.value)}if((e||t)&&(q(!!e,s.message,a.message,F,S),!r))return O(T[v].message),T}if((d||f)&&!N&&(P(V)||a&&Array.isArray(V))){const e=he(d),t=he(f),s=!u(e.value)&&V.length>e.value,a=!u(t.value)&&V.length<t.value;if((s||a)&&(q(s,e.message,t.message),!r))return O(T[v].message),T}if(g&&!N&&P(V)){const{value:e,message:t}=he(g);if(le(e)&&!V.match(e)&&(T[v]={type:D,message:t,ref:n,...R(D,t)},!r))return O(t),T}if(_)if(ne(_)){const e=pe(await _(V,t),E);if(e&&(T[v]={...e,...R(j,e.message)},!r))return O(e.message),T}else if(c(_)){let e={};for(const s in _){if(!U(e)&&!r)break;const a=pe(await _[s](V,t),E,s);a&&(e={...a,...R(s,a.message)},O(a.message),r&&(T[v]=e))}if(!U(e)&&(T[v]={ref:E,...e},!r))return T}return O(!0),T};function _e(e,t){return[...e,...L(t)]}var ve=e=>Array.isArray(e)?e.map((()=>{})):void 0;function be(e,t,r){return[...e.slice(0,t),...L(r),...e.slice(t)]}var Ae=(e,t,r)=>Array.isArray(e)?(y(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 Ve=(e,t)=>y(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return m(s).length?s:[]}(e,L(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:G(t)?[t]:K(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=y(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(!y(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(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var De=e=>u(e)||!l(e);function Ce(e,t){if(De(e)||De(t))return e===t;if(o(e)&&o(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(o(r)&&o(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,Ee=e=>ie(e)&&e.isConnected,Oe=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])&&!Oe(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Te(e[r],t[r])):u(e[r])||(t[r]=!0);return t}function Ue(e,t,r){const s=Array.isArray(e);if(c(e)||s)for(const s in e)Array.isArray(e[s])||c(e[s])&&!Oe(e[s])?y(t)||De(r[s])?r[s]=Array.isArray(e[s])?Te(e[s],[]):{...Te(e[s])}:Ue(e[s],u(t)?{}:t[s],r[s]):Ce(e[s],t[s])?delete r[s]:r[s]=!0;return r}var Be=(e,t)=>Ue(e,t,Te(t)),Le=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>y(e)?e:t?""===e?NaN:e?+e:e:r&&P(e)?new Date(e):s?s(e):e;function Me(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return ae(t)?t.files:ue(t)?ye(e.refs).value:je(t)?[...t.selectedOptions].map((({value:e})=>e)):i(t)?fe(e.refs).value:Le(y(t.value)?e.ref.value:t.value,e)}var Ne=e=>y(e)?e:le(e)?e.source:c(e)?le(e.value)?e.value.source:e.value:e;function Re(e,t,r){const s=p(e,r);if(s||G(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=p(t,s),i=p(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:A,reValidateMode:b,shouldFocusError:!0};function qe(e={},t){let r={...Pe,...e};const s=e.resetOptions&&e.resetOptions.keepDirtyValues;let a,n={submitCount:0,isDirty:!1,isLoading:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},l={},_=(c(r.defaultValues)||c(r.values))&&$(r.defaultValues||r.values)||{},v=r.shouldUnregister?{}:$(_),b={action:!1,mount:!1,watch:!1},A={mount:new Set,unMount:new Set,array:new Set,watch:new Set},x=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},S={watch:ke(),array:ke(),state:ke()},w=ee(r.mode),k=ee(r.reValidateMode),D=r.criteriaMode===V,C=async e=>{if(F.isValid||e){const e=r.resolver?U((await B()).errors):await M(l,!0);e!==n.isValid&&S.state.next({isValid:e})}},j=e=>F.isValidating&&S.state.next({isValidating:e}),E=(e,t,r,s)=>{const a=p(l,e);if(a){const n=p(v,e,y(r)?p(_,e):r);y(n)||s&&s.defaultChecked||t?Q(v,e,t?n:Me(a._f)):I(e,n),b.mount&&C()}},O=(e,t,r,s,a)=>{let i=!1,o=!1;const u={name:e};if(!r||s){F.isDirty&&(o=n.isDirty,n.isDirty=u.isDirty=N(),i=o!==u.isDirty);const r=Ce(p(_,e),t);o=p(n.dirtyFields,e),r?Se(n.dirtyFields,e):Q(n.dirtyFields,e,!0),u.dirtyFields=n.dirtyFields,i=i||F.dirtyFields&&o!==!r}if(r){const t=p(n.touchedFields,e);t||(Q(n.touchedFields,e,r),u.touchedFields=n.touchedFields,i=i||F.touchedFields&&t!==r)}return i&&a&&S.state.next(u),i?u:{}},T=(t,r,s,i)=>{const o=p(n.errors,t),u=F.isValid&&se(r)&&n.isValid!==r;var l;if(e.delayError&&s?(l=()=>((e,t)=>{Q(n.errors,e,t),S.state.next({errors:n.errors})})(t,s),a=e=>{clearTimeout(x),x=window.setTimeout(l,e)},a(e.delayError)):(clearTimeout(x),a=null,s?Q(n.errors,t,s):Se(n.errors,t)),(s?!Ce(o,s):o)||!U(i)||u){const e={...i,...u&&se(r)?{isValid:r}:{},errors:n.errors,name:t};n={...n,...e},S.state.next(e)}j(!1)},B=async e=>await r.resolver(v,r.context,((e,t,r,s)=>{const a={};for(const r of e){const e=p(t,r);e&&Q(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||A.mount,l,r.criteriaMode,r.shouldUseNativeValidation)),M=async(e,t,s={valid:!0})=>{for(const a in e){const i=e[a];if(i){const{_f:e,...a}=i;if(e){const a=A.array.has(e.name),o=await ge(i,v,D,r.shouldUseNativeValidation,a);if(o[e.name]&&(s.valid=!1,t))break;!t&&(p(o,e.name)?a?re(n.errors,o,e.name):Q(n.errors,e.name,o[e.name]):Se(n.errors,e.name))}a&&await M(a,t,s)}}return s.valid},N=(e,t)=>(e&&t&&Q(v,e,t),!Ce(K(),_)),R=(e,t,r)=>q(e,A,{...b.mount?v:y(t)?_:P(e)?{[e]:t}:t},r,t),I=(e,t,r={})=>{const s=p(l,e);let a=t;if(s){const r=s._f;r&&(!r.disabled&&Q(v,e,Le(t,r)),a=ie(r.ref)&&u(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||S.watch.next({name:e})))}(r.shouldDirty||r.shouldTouch)&&O(e,a,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&G(e)},H=(e,t,r)=>{for(const s in t){const a=t[s],n=`${e}.${s}`,i=p(l,n);!A.array.has(e)&&De(a)&&(!i||i._f)||o(a)?I(n,a,r):H(n,a,r)}},z=(e,r,s={})=>{const a=p(l,e),n=A.array.has(e),i=$(r);Q(v,e,i),n?(S.array.next({name:e,values:v}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&S.state.next({name:e,dirtyFields:Be(_,v),isDirty:N(e,i)})):!a||a._f||u(i)?I(e,i,s):H(e,i,s),te(e,A)&&S.state.next({}),S.watch.next({name:e}),!b.mount&&t()},J=async e=>{const t=e.target;let s=t.name;const i=p(l,s);if(i){let u,c;const f=t.type?Me(i._f):d(e),m=e.type===h||e.type===g,y=!((o=i._f).mount&&(o.required||o.min||o.max||o.maxLength||o.minLength||o.pattern||o.validate)||r.resolver||p(n.errors,s)||i._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))(m,p(n.touchedFields,s),n.isSubmitted,k,w),_=te(s,A,m);Q(v,s,f),m?(i._f.onBlur&&i._f.onBlur(e),a&&a(0)):i._f.onChange&&i._f.onChange(e);const b=O(s,f,m,!1),x=!U(b)||_;if(!m&&S.watch.next({name:s,type:e.type}),y)return F.isValid&&C(),x&&S.state.next({name:s,..._?{}:b});if(!m&&_&&S.state.next({}),j(!0),r.resolver){const{errors:e}=await B([s]),t=Re(n.errors,l,s),r=Re(e,l,t.name||s);u=r.error,s=r.name,c=U(e)}else u=(await ge(i,v,D,r.shouldUseNativeValidation))[s],u?c=!1:F.isValid&&(c=await M(l,!0));i._f.deps&&G(i._f.deps),T(s,c,u,b)}var o},G=async(e,t={})=>{let s,a;const i=L(e);if(j(!0),r.resolver){const t=await(async e=>{const{errors:t}=await B();if(e)for(const r of e){const e=p(t,r);e?Q(n.errors,r,e):Se(n.errors,r)}else n.errors=t;return t})(y(e)?e:i);s=U(t),a=e?!i.some((e=>p(t,e))):s}else e?(a=(await Promise.all(i.map((async e=>{const t=p(l,e);return await M(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||n.isValid)&&C()):a=s=await M(l);return S.state.next({...!P(e)||F.isValid&&s!==n.isValid?{}:{name:e},...r.resolver||!e?{isValid:s}:{},errors:n.errors,isValidating:!1}),t.shouldFocus&&!a&&X(l,(e=>e&&p(n.errors,e)),e?i:A.mount),a},K=e=>{const t={..._,...b.mount?v:{}};return y(e)?t:P(e)?p(t,e):e.map((e=>p(t,e)))},Y=(e,t)=>({invalid:!!p((t||n).errors,e),isDirty:!!p((t||n).dirtyFields,e),isTouched:!!p((t||n).touchedFields,e),error:p((t||n).errors,e)}),Z=(e,t,r)=>{const s=(p(l,e,{_f:{}})._f||{}).ref;Q(n.errors,e,{...t,ref:s}),S.state.next({name:e,errors:n.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},oe=(e,t={})=>{for(const s of e?L(e):A.mount)A.mount.delete(s),A.array.delete(s),p(l,s)&&(t.keepValue||(Se(l,s),Se(v,s)),!t.keepError&&Se(n.errors,s),!t.keepDirty&&Se(n.dirtyFields,s),!t.keepTouched&&Se(n.touchedFields,s),!r.shouldUnregister&&!t.keepDefaultValue&&Se(_,s));S.watch.next({}),S.state.next({...n,...t.keepDirty?{isDirty:N()}:{}}),!t.keepIsValid&&C()},le=(e,t={})=>{let s=p(l,e);const a=se(t.disabled);return Q(l,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),A.mount.add(e),s?a&&Q(v,e,t.disabled?void 0:p(v,e,Me(s._f))):E(e,!0,t.value),{...a?{disabled:t.disabled}:{},...r.shouldUseNativeValidation||r.progressive?{required:!!t.required,min:Ne(t.min),max:Ne(t.max),minLength:Ne(t.minLength),maxLength:Ne(t.maxLength),pattern:Ne(t.pattern)}:{},name:e,onChange:J,onBlur:J,ref:a=>{if(a){le(e,t),s=p(l,e);const r=y(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=(e=>ue(e)||i(e))(r),o=s._f.refs||[];if(n?o.find((e=>e===r)):r===s._f.ref)return;Q(l,e,{_f:{...s._f,...n?{refs:[...o.filter(Ee),r,...Array.isArray(p(_,e))?[{}]:[]],ref:{type:r.type,name:e}}:{ref:r}}}),E(e,!1,void 0,r)}else s=p(l,e,{}),s._f&&(s._f.mount=!1),(r.shouldUnregister||t.shouldUnregister)&&(!f(A.array,e)||!b.action)&&A.unMount.add(e)}}},ce=()=>r.shouldFocusError&&X(l,(e=>e&&p(n.errors,e)),A.mount),de=(e,t)=>async s=>{s&&(s.preventDefault&&s.preventDefault(),s.persist&&s.persist());let a=$(v);if(S.state.next({isSubmitting:!0}),r.resolver){const{errors:e,values:t}=await B();n.errors=e,a=t}else await M(l);Se(n.errors,"root"),U(n.errors)?(S.state.next({errors:{}}),await e(a,s)):(t&&await t({...n.errors},s),ce()),S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:U(n.errors),submitCount:n.submitCount+1,errors:n.errors})},fe=(r,a={})=>{const i=r||_,o=$(i),u=r&&!U(r)?o:_;if(a.keepDefaultValues||(_=i),!a.keepValues){if(a.keepDirtyValues||s)for(const e of A.mount)p(n.dirtyFields,e)?Q(u,e,p(v,e)):z(e,p(u,e));else{if(W&&y(r))for(const e of A.mount){const t=p(l,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}}}}l={}}v=e.shouldUnregister?a.keepDefaultValues?$(_):{}:o,S.array.next({values:u}),S.watch.next({values:u})}A={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!b.mount&&t(),b.mount=!F.isValid||!!a.keepIsValid,b.watch=!!e.shouldUnregister,S.state.next({submitCount:a.keepSubmitCount?n.submitCount:0,isDirty:a.keepDirty||a.keepDirtyValues?n.isDirty:!(!a.keepDefaultValues||Ce(r,_)),isSubmitted:!!a.keepIsSubmitted&&n.isSubmitted,dirtyFields:a.keepDirty||a.keepDirtyValues?n.dirtyFields:a.keepDefaultValues&&r?Be(_,r):{},touchedFields:a.keepTouched?n.touchedFields:{},errors:a.keepErrors?n.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},me=(e,t)=>fe(ne(e)?e(v):e,t);return ne(r.defaultValues)&&r.defaultValues().then((e=>{me(e,r.resetOptions),S.state.next({isLoading:!1})})),{control:{register:le,unregister:oe,getFieldState:Y,handleSubmit:de,setError:Z,_executeSchema:B,_focusError:ce,_getWatch:R,_getDirty:N,_updateValid:C,_removeUnmounted:()=>{for(const e of A.unMount){const t=p(l,e);t&&(t._f.refs?t._f.refs.every((e=>!Ee(e))):!Ee(t._f.ref))&&oe(e)}A.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,i=!0)=>{if(s&&r){if(b.action=!0,i&&Array.isArray(p(l,e))){const t=r(p(l,e),s.argA,s.argB);a&&Q(l,e,t)}if(i&&Array.isArray(p(n.errors,e))){const t=r(p(n.errors,e),s.argA,s.argB);a&&Q(n.errors,e,t),((e,t)=>{!m(p(e,t)).length&&Se(e,t)})(n.errors,e)}if(F.touchedFields&&i&&Array.isArray(p(n.touchedFields,e))){const t=r(p(n.touchedFields,e),s.argA,s.argB);a&&Q(n.touchedFields,e,t)}F.dirtyFields&&(n.dirtyFields=Be(_,v)),S.state.next({name:e,isDirty:N(e,t),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Q(v,e,t)},_getFieldArray:t=>m(p(b.mount?v:_,t,e.shouldUnregister?p(_,t,[]):[])),_reset:fe,_updateFormState:e=>{n={...n,...e}},_subjects:S,_proxyFormState:F,get _fields(){return l},get _formValues(){return v},get _stateFlags(){return b},set _stateFlags(e){b=e},get _defaultValues(){return _},get _names(){return A},set _names(e){A=e},get _formState(){return n},set _formState(e){n=e},get _options(){return r},set _options(e){r={...r,...e}}},trigger:G,register:le,handleSubmit:de,watch:(e,t)=>ne(e)?S.watch.subscribe({next:r=>e(R(void 0,t),r)}):R(e,t,!0),setValue:z,getValues:K,reset:me,resetField:(e,t={})=>{p(l,e)&&(y(t.defaultValue)?z(e,p(_,e)):(z(e,t.defaultValue),Q(_,e,t.defaultValue)),t.keepTouched||Se(n.touchedFields,e),t.keepDirty||(Se(n.dirtyFields,e),n.isDirty=t.defaultValue?N(e,p(_,e)):N()),t.keepError||(Se(n.errors,e),F.isValid&&C()),S.state.next({...n}))},clearErrors:e=>{e&&L(e).forEach((e=>Se(n.errors,e))),S.state.next({errors:e?n.errors:{}})},unregister:oe,setError:Z,setFocus:(e,t={})=>{const r=p(l,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(H(e)),e.Form=function(e){const t=O(),[r,s]=n.useState(!1),{control:a=t.control,onSubmit:i,children:o,action:u,method:l=z,headers:c,encType:d,onError:f,render:m,onSuccess:y,validateStatus:h,fetcher:g,..._}=e,v=l===z,b=async t=>{let r=!1;await a.handleSubmit((async e=>{if(i&&i(e),u){const s=new FormData;let n=!1;if(c?n=c["Content-Type"].includes("json"):a._names.mount.forEach((t=>s.append(t,p(e,t)))),g)await g(u,{method:l,values:e,event:t});else try{const t=await fetch(u,{method:l,headers:{...c,...d?{"Content-Type":d}:{}},...v?{body:n?JSON.stringify(e):s}:{}});t&&(h?!h(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:b})):n.createElement("form",{noValidate:r,action:u,method:l,encType:d,onSubmit:b,..._},o)},e.FormProvider=e=>{const{children:t,...r}=e;return a.default.createElement(E.Provider,{value:r},t)},e.appendErrors=J,e.get=p,e.set=Q,e.useController=H,e.useFieldArray=function(e){const t=O(),{control:r=t.control,name:s,keyName:n="id",shouldUnregister:i}=e,[o,u]=a.default.useState(r._getFieldArray(s)),l=a.default.useRef(r._getFieldArray(s).map(Y)),c=a.default.useRef(o),d=a.default.useRef(s),f=a.default.useRef(!1);d.current=s,c.current=o,r._names.array.add(s),e.rules&&r.register(s,e.rules),N({next:({values:e,name:t})=>{if(t===d.current||!t){const t=p(e,d.current);Array.isArray(t)&&(u(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._stateFlags.action=!1,te(s,r._names)&&r._subjects.state.next({}),f.current&&(!ee(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([s]).then((e=>{const t=p(e.errors,s),a=p(r._formState.errors,s);(a?!t&&a.type:t&&t.type)&&(t?Q(r._formState.errors,s,t):Se(r._formState.errors,s),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=p(r._fields,s);e&&e._f&&ge(e,r._formValues,r._options.criteriaMode===V,r._options.shouldUseNativeValidation,!0).then((e=>!U(e)&&r._subjects.state.next({errors:re(r._formState.errors,e,s)})))}r._subjects.watch.next({name:s,values:r._formValues}),r._names.focus&&X(r._fields,(e=>!!e&&e.startsWith(r._names.focus||""))),r._names.focus="",r._updateValid()}),[o,s,r]),a.default.useEffect((()=>(!p(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),u(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),u(a),r._updateFieldArray(s,a,Ae,{argA:e,argB:t},!1)}),[m,s,r]),prepend:a.default.useCallback(((e,t)=>{const a=L($(e)),n=xe(r._getFieldArray(s),a);r._names.focus=Z(s,0,t),l.current=xe(l.current,a.map(Y)),m(n),u(n),r._updateFieldArray(s,n,xe,{argA:ve(e)})}),[m,s,r]),append:a.default.useCallback(((e,t)=>{const a=L($(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),u(n),r._updateFieldArray(s,n,_e,{argA:ve(e)})}),[m,s,r]),remove:a.default.useCallback((e=>{const t=Ve(r._getFieldArray(s),e);l.current=Ve(l.current,e),m(t),u(t),r._updateFieldArray(s,t,Ve,{argA:e})}),[m,s,r]),insert:a.default.useCallback(((e,t,a)=>{const n=L($(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),u(i),r._updateFieldArray(s,i,be,{argA:e,argB:ve(t)})}),[m,s,r]),update:a.default.useCallback(((e,t)=>{const a=$(t),n=we(r._getFieldArray(s),e,a);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:Y())),m(n),u([...n]),r._updateFieldArray(s,n,we,{argA:e,argB:a},!0,!1)}),[m,s,r]),replace:a.default.useCallback((e=>{const t=L($(e));l.current=t.map(Y),m([...t]),u([...t]),r._updateFieldArray(s,[...t],(e=>e),{},!0,!1)}),[m,s,r]),fields:a.default.useMemo((()=>o.map(((e,t)=>({...e,[n]:l.current[t]||Y()})))),[o,n])}},e.useForm=function(e={}){const t=a.default.useRef(),[r,s]=a.default.useState({isDirty:!1,isValidating:!1,isLoading:!0,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,N({subject:n._subjects.state,next:e=>{B(e,n._proxyFormState,n._updateFormState,!0)&&s({...n._formState})}}),a.default.useEffect((()=>{n._stateFlags.mount||(n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()})),a.default.useEffect((()=>{e.values&&!Ce(e.values,n._defaultValues)&&n._reset(e.values,n._options.resetOptions)}),[e.values,n]),a.default.useEffect((()=>{r.submitCount&&n._focusError()}),[n,r.submitCount]),t.current.formState=T(r,n),t.current},e.useFormContext=O,e.useFormState=R,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,o=e=>e instanceof Date,u=e=>null==e;const l=e=>"object"==typeof e;var c=e=>!u(e)&&!Array.isArray(e)&&l(e)&&!o(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)=>u(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",x="onChange",V="onSubmit",F="onTouched",S="all",w="max",k="min",D="maxLength",C="minLength",j="pattern",O="required",E="validate",T=a.default.createContext(null),U=()=>a.default.useContext(T);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]!==S&&(t._proxyFormState[a]=!s||S),r&&(r[a]=!0),e[a]}});return a},L=e=>c(e)&&!Object.keys(e).length,M=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return L(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||S)))},N=e=>Array.isArray(e)?e:[e],R=(e,t,r)=>r&&t?e===t:!e||!t||e===t||N(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=U(),{control:r=t.control,disabled:s,name:n,exact:i}=e||{},[o,u]=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)&&M(e,c.current,r._updateFormState)&&u({...r._formState,...e}),subject:r._subjects.state}),a.default.useEffect((()=>{l.current=!0;const e=r._proxyFormState.isDirty&&r._getDirty();return e!==r._formState.isDirty&&r._subjects.state.next({isDirty:e}),c.current.isValid&&r._updateValid(!0),()=>{l.current=!1}}),[r]),B(o,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=U(),{control:r=t.control,name:s,defaultValue:n,disabled:i,exact:o}=e||{},u=a.default.useRef(s);u.current=s,P({disabled:i,subject:r._subjects.values,next:e=>{R(u.current,e.name,o)&&c(y($(u.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=U(),{name:r,control:s=t.control,shouldUnregister:n}=e,i=f(s._names.array,r),o=I({control:s,name:r,defaultValue:g(s._formValues,r,g(s._defaultValues,r,e.defaultValue)),exact:!0}),u=q({control:s,name:r}),l=a.default.useRef(s.register(r,{...e.rules,value:o}));return a.default.useEffect((()=>{const e=s._options.shouldUnregister||n,t=(e,t)=>{const r=g(s._fields,e);r&&(r._f.mount=t)};return t(r,!0),e&&z(s._defaultValues,r,y(g(s._options.defaultValues,r))),()=>{(i?e&&!s._state.action:e)?s.unregister(r):t(r,!1)}}),[r,s,i,n]),{field:{name:r,value:o,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:u,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!g(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!g(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!g(u.touchedFields,r)},error:{enumerable:!0,get:()=>g(u.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===V,isOnBlur:e===A,isOnChange:e===x,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)},oe=e=>W(e),ue=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(oe(e)||Array.isArray(e)&&e.every(oe)||se(e)&&!e)return{type:r,message:oe(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:o,required:l,maxLength:d,minLength:f,min:m,max:y,pattern:p,validate:_,name:v,valueAsNumber:b,mount:A,disabled:x}=e._f,V=g(t,v);if(!A||x)return{};const F=o?o[0]:n,S=e=>{s&&F.reportValidity&&(F.setCustomValidity(se(e)?"":e||""),F.reportValidity())},T={},U=ue(n),B=i(n),M=U||B,N=(b||ae(n))&&h(n.value)&&h(V)||ie(n)&&""===n.value||""===V||Array.isArray(V)&&!V.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(V)||!V.length:l&&(!M&&(N||u(V))||se(V)&&!V||B&&!fe(o).isValid||U&&!ye(o).isValid)){const{value:e,message:t}=oe(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(!(N||u(m)&&u(y))){let e,t;const s=he(y),a=he(m);if(u(V)||isNaN(V)){const r=n.valueAsDate||new Date(V),i=e=>new Date((new Date).toDateString()+" "+e),o="time"==n.type,u="week"==n.type;W(s.value)&&V&&(e=o?i(V)>i(s.value):u?V>s.value:r>new Date(s.value)),W(a.value)&&V&&(t=o?i(V)<i(a.value):u?V<a.value:r<new Date(a.value))}else{const r=n.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,w,k),!r))return S(T[v].message),T}if((d||f)&&!N&&(W(V)||a&&Array.isArray(V))){const e=he(d),t=he(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 S(T[v].message),T}if(p&&!N&&W(V)){const{value:e,message:t}=he(p);if(le(e)&&!V.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 _(V,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(!L(e)&&!r)break;const a=pe(await _[s](V,t),F,s);a&&(e={...a,...R(s,a.message)},S(a.message),r&&(T[v]=e))}if(!L(e)&&(T[v]={ref:F,...e},!r))return T}return S(!0),T};function _e(e,t){return[...e,...N(t)]}var ve=e=>Array.isArray(e)?e.map((()=>{})):void 0;function be(e,t,r){return[...e.slice(0,t),...N(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 xe(e,t){return[...N(t),...N(e)]}var Ve=(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,N(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)&&L(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=>u(e)||!l(e);function Ce(e,t){if(De(e)||De(t))return e===t;if(o(e)&&o(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(o(r)&&o(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])):u(e[r])||(t[r]=!0);return t}function Ue(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])}:Ue(e[s],u(t)?{}:t[s],r[s]):r[s]=!Ce(e[s],t[s]);return r}var Be=(e,t)=>Ue(e,t,Te(t)),Le=(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 Me(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return ae(t)?t.files:ue(t)?ye(e.refs).value:je(t)?[...t.selectedOptions].map((({value:e})=>e)):i(t)?fe(e.refs).value:Le(h(t.value)?e.ref.value:t.value,e)}var Ne=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:V,reValidateMode:x,shouldFocusError:!0};function qe(e={},t){let r,s={...Pe,...e},a={submitCount:0,isDirty:!1,isLoading:!0,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},x={mount:new Set,unMount:new Set,array:new Set,watch:new Set},V=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},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?L((await M()).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:Me(a._f)):I(e,n),A.mount&&O()}},U=(e,t,r,s,n)=>{let i=!1,o=!1;const u={name:e};if(!r||s){F.isDirty&&(o=a.isDirty,a.isDirty=u.isDirty=P(),i=o!==u.isDirty);const r=Ce(g(l,e),t);o=g(a.dirtyFields,e),r?Se(a.dirtyFields,e):z(a.dirtyFields,e,!0),u.dirtyFields=a.dirtyFields,i=i||F.dirtyFields&&o!==!r}if(r){const t=g(a.touchedFields,e);t||(z(a.touchedFields,e,r),u.touchedFields=a.touchedFields,i=i||F.touchedFields&&t!==r)}return i&&n&&w.state.next(u),i?u:{}},B=(t,s,n,i)=>{const o=g(a.errors,t),u=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(V),V=setTimeout(l,e)},r(e.delayError)):(clearTimeout(V),r=null,n?z(a.errors,t,n):Se(a.errors,t)),(n?!Ce(o,n):o)||!L(i)||u){const e={...i,...u&&se(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=g(t,r);e&&z(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||x.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=x.array.has(e.name),o=await ge(i,b,j,s.shouldUseNativeValidation&&!t,n);if(o[e.name]&&(r.valid=!1,t))break;!t&&(g(o,e.name)?n?re(a.errors,o,e.name):z(a.errors,e.name,o[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,x,{...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,Le(t,r)),a=ie(r.ref)&&u(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)&&U(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}`,u=g(n,i);!x.array.has(e)&&De(a)&&(!u||u._f)||o(a)?I(i,a,r):H(i,a,r)}},J=(e,r,s={})=>{const i=g(n,e),o=x.array.has(e),c=y(r);z(b,e,c),o?(w.array.next({name:e,values:{...b}}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&w.state.next({name:e,dirtyFields:Be(l,b),isDirty:P(e,c)})):!i||i._f||u(c)?I(e,c,s):H(e,c,s),te(e,x)&&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,o=!0;const u=g(n,i);if(u){let c,f;const m=t.type?Me(u._f):d(e),y=e.type===_||e.type===v,p=!((l=u._f).mount&&(l.required||l.min||l.max||l.maxLength||l.minLength||l.pattern||l.validate)||s.resolver||g(a.errors,i)||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,g(a.touchedFields,i),a.isSubmitted,C,D),h=te(i,x,y);z(b,i,m),y?(u._f.onBlur&&u._f.onBlur(e),r&&r(0)):u._f.onChange&&u._f.onChange(e);const A=U(i,m,y,!1),V=!L(A)||h;if(!y&&w.values.next({name:i,type:e.type,values:{...b}}),p)return F.isValid&&O(),V&&w.state.next({name:i,...h?{}:A});if(!y&&h&&w.state.next({...a}),E(!0),s.resolver){const{errors:e}=await M([i]),t=Re(a.errors,n,i),r=Re(e,n,t.name||i);c=r.error,i=r.name,f=L(e)}else c=(await ge(u,b,j,s.shouldUseNativeValidation))[i],o=m===g(b,i,m),o&&(c?f=!1:F.isValid&&(f=await R(n,!0)));o&&(u._f.deps&&K(u._f.deps),B(i,f,c,A))}var l},K=async(e,t={})=>{let r,i;const o=N(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=g(t,r);e?z(a.errors,r,e):Se(a.errors,r)}else a.errors=t;return t})(h(e)?e:o);r=L(t),i=e?!o.some((e=>g(t,e))):r}else e?(i=(await Promise.all(o.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?o:x.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()},oe=(e,t={})=>{for(const r of e?N(e):x.mount)x.mount.delete(r),x.array.delete(r),g(n,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}}),x.mount.add(e),r?a&&z(b,e,t.disabled?void 0:g(b,e,Me(r._f))):T(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.shouldUseNativeValidation||s.progressive?{required:!!t.required,min:Ne(t.min),max:Ne(t.max),minLength:Ne(t.minLength),maxLength:Ne(t.maxLength),pattern:Ne(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,o=(e=>ue(e)||i(e))(s),u=r._f.refs||[];if(o?u.find((e=>e===s)):s===r._f.ref)return;z(n,e,{_f:{...r._f,...o?{refs:[...u.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(x.array,e)||!A.action)&&x.unMount.add(e)}}},ce=()=>s.shouldFocusError&&X(n,(e=>e&&g(a.errors,e)),x.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 M();a.errors=e,i=t}else await R(n);Se(a.errors,"root"),L(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:L(a.errors),submitCount:a.submitCount+1,errors:a.errors})},fe=(r,s={})=>{const i=r||l,o=y(i),u=r&&!L(r)?o:l;if(s.keepDefaultValues||(l=i),!s.keepValues){if(s.keepDirtyValues||k)for(const e of x.mount)g(a.dirtyFields,e)?z(u,e,g(b,e)):J(e,g(u,e));else{if(m&&h(r))for(const e of x.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):{}:o,w.array.next({values:{...u}}),w.values.next({values:{...u}})}x={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!A.mount&&t(),A.mount=!F.isValid||!!s.keepIsValid,A.watch=!!e.shouldUnregister,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?Be(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 ne(s.defaultValues)&&s.defaultValues().then((e=>{me(e,s.resetOptions),w.state.next({isLoading:!1})})),{control:{register:le,unregister:oe,getFieldState:Y,handleSubmit:de,setError:Z,_executeSchema:M,_getWatch:q,_getDirty:P,_updateValid:O,_removeUnmounted:()=>{for(const e of x.unMount){const t=g(n,e);t&&(t._f.refs?t._f.refs.every((e=>!Oe(e))):!Oe(t._f.ref))&&oe(e)}x.unMount=new Set},_updateFieldArray:(e,t=[],r,s,i=!0,o=!0)=>{if(s&&r){if(A.action=!0,o&&Array.isArray(g(n,e))){const t=r(g(n,e),s.argA,s.argB);i&&z(n,e,t)}if(o&&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&&o&&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=Be(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,_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 x},set _names(e){x=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&&N(e).forEach((e=>Se(a.errors,e))),w.state.next({errors:e?a.errors:{}})},unregister:oe,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=U(),[r,s]=n.useState(!1),{control:a=t.control,onSubmit:i,children:o,action:u,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,n=JSON.stringify(e);if(a._names.mount.forEach((t=>s.append(t,g(e,t)))),i&&i(e),u)try{if(h)await h(u,{method:l,values:e,event:t,formData:s,formDataJson:n});else{const e=c&&c["Content-Type"].includes("json"),t=await fetch(u,{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:u,method:l,encType:d,onSubmit:v,..._},o)},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=U(),{control:r=t.control,name:s,keyName:n="id",shouldUnregister:i}=e,[o,u]=a.default.useState(r._getFieldArray(s)),l=a.default.useRef(r._getFieldArray(s).map(Y)),c=a.default.useRef(o),d=a.default.useRef(s),f=a.default.useRef(!1);d.current=s,c.current=o,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)&&(u(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&&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=>!L(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()}),[o,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),u(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),u(a),r._updateFieldArray(s,a,Ae,{argA:e,argB:t},!1)}),[m,s,r]),prepend:a.default.useCallback(((e,t)=>{const a=N(y(e)),n=xe(r._getFieldArray(s),a);r._names.focus=Z(s,0,t),l.current=xe(l.current,a.map(Y)),m(n),u(n),r._updateFieldArray(s,n,xe,{argA:ve(e)})}),[m,s,r]),append:a.default.useCallback(((e,t)=>{const a=N(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),u(n),r._updateFieldArray(s,n,_e,{argA:ve(e)})}),[m,s,r]),remove:a.default.useCallback((e=>{const t=Ve(r._getFieldArray(s),e);l.current=Ve(l.current,e),m(t),u(t),r._updateFieldArray(s,t,Ve,{argA:e})}),[m,s,r]),insert:a.default.useCallback(((e,t,a)=>{const n=N(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),u(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),u([...n]),r._updateFieldArray(s,n,we,{argA:e,argB:a},!0,!1)}),[m,s,r]),replace:a.default.useCallback((e=>{const t=N(y(e));l.current=t.map(Y),m([...t]),u([...t]),r._updateFieldArray(s,[...t],(e=>e),{},!0,!1)}),[m,s,r]),fields:a.default.useMemo((()=>o.map(((e,t)=>({...e,[n]:l.current[t]||Y()})))),[o,n])}},e.useForm=function(e={}){const t=a.default.useRef(),[r,s]=a.default.useState({isDirty:!1,isValidating:!1,isLoading:!0,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=>{M(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)}),[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=B(r,n),t.current},e.useFormContext=U,e.useFormState=q,e.useWatch=I,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -177,3 +177,3 @@ import { FieldValues } from './fields'; | ||
* type="button" | ||
* onClick={() => update([{ name: "data" }, { name: "data" }])} | ||
* onClick={() => replace([{ name: "data" }, { name: "data" }])} | ||
* > | ||
@@ -180,0 +180,0 @@ * Replace |
@@ -35,4 +35,4 @@ import React from 'react'; | ||
export type CriteriaMode = 'firstError' | 'all'; | ||
export type SubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event?: React.BaseSyntheticEvent) => any | Promise<any>; | ||
export type SubmitErrorHandler<TFieldValues extends FieldValues> = (errors: FieldErrors<TFieldValues>, event?: React.BaseSyntheticEvent) => any | Promise<any>; | ||
export type SubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>; | ||
export type SubmitErrorHandler<TFieldValues extends FieldValues> = (errors: FieldErrors<TFieldValues>, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>; | ||
export type SetValueConfig = Partial<{ | ||
@@ -475,3 +475,3 @@ shouldValidate: boolean; | ||
*/ | ||
export type UseFormHandleSubmit<TFieldValues extends FieldValues> = (onValid: SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; | ||
export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = (onValid: TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; | ||
/** | ||
@@ -496,3 +496,3 @@ * Reset a field state and reference. | ||
keepError: boolean; | ||
defaultValue: unknown; | ||
defaultValue: FieldPathValue<TFieldValues, TFieldName>; | ||
}>) => void; | ||
@@ -541,6 +541,6 @@ type ResetAction<TFieldValues> = (formValues: TFieldValues) => TFieldValues; | ||
export type Subjects<TFieldValues extends FieldValues = FieldValues> = { | ||
watch: Subject<{ | ||
values: Subject<{ | ||
name?: InternalFieldName; | ||
type?: EventType; | ||
values?: FieldValues; | ||
values: FieldValues; | ||
}>; | ||
@@ -568,5 +568,4 @@ array: Subject<{ | ||
_removeUnmounted: Noop; | ||
_focusError: Noop; | ||
_names: Names; | ||
_stateFlags: { | ||
_state: { | ||
mount: boolean; | ||
@@ -602,3 +601,3 @@ action: boolean; | ||
}) => void; | ||
export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any> = { | ||
export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined> = { | ||
watch: UseFormWatch<TFieldValues>; | ||
@@ -614,3 +613,3 @@ getValues: UseFormGetValues<TFieldValues>; | ||
reset: UseFormReset<TFieldValues>; | ||
handleSubmit: UseFormHandleSubmit<TFieldValues>; | ||
handleSubmit: UseFormHandleSubmit<TFieldValues, TTransformedValues>; | ||
unregister: UseFormUnregister<TFieldValues>; | ||
@@ -617,0 +616,0 @@ control: Control<TFieldValues, TContext>; |
@@ -31,3 +31,3 @@ import { FieldValues, UseFormProps, UseFormReturn } from './types'; | ||
*/ | ||
export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext = any>(props?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues, TContext>; | ||
export declare function useForm<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined>(props?: UseFormProps<TFieldValues, TContext>): UseFormReturn<TFieldValues, TContext, TTransformedValues>; | ||
//# sourceMappingURL=useForm.d.ts.map |
@@ -33,3 +33,3 @@ /// <reference types="react" /> | ||
*/ | ||
export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues, any>; | ||
export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues, any, undefined>; | ||
/** | ||
@@ -36,0 +36,0 @@ * 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}. |
@@ -1,3 +0,3 @@ | ||
declare const _default: <T>(obj: T, path: string, defaultValue?: unknown) => any; | ||
declare const _default: <T>(obj: T, path?: string, defaultValue?: unknown) => any; | ||
export default _default; | ||
//# sourceMappingURL=get.d.ts.map |
{ | ||
"name": "react-hook-form", | ||
"description": "Performant, flexible and extensible forms library for React Hooks", | ||
"version": "7.44.0-next.1", | ||
"version": "7.44.0-rc.0", | ||
"main": "dist/index.cjs.js", | ||
@@ -99,3 +99,2 @@ "module": "dist/index.esm.mjs", | ||
"jest-preview": "^0.3.1", | ||
"jest-watch-typeahead": "^2.2.1", | ||
"lint-staged": "^13.1.0", | ||
@@ -102,0 +101,0 @@ "msw": "^1.0.0", |
@@ -69,38 +69,17 @@ <div align="center"> | ||
<a | ||
target = _blank | ||
href = 'https://wantedlyinc.com' | ||
/> | ||
<img | ||
width = 94 | ||
src = 'https://images.opencollective.com/wantedly/d94e44e/logo/256.png' | ||
/> | ||
<a target="_blank" href='https://wantedlyinc.com'> | ||
<img width="94" src="https://images.opencollective.com/wantedly/d94e44e/logo/256.png" /> | ||
</a> | ||
<a | ||
target = _blank | ||
href = 'https://graphcms.com' | ||
/> | ||
<img | ||
width = 94 | ||
src = 'https://avatars.githubusercontent.com/u/31031438' | ||
/> | ||
<a target="_blank" href="https://graphcms.com"> | ||
<img width="94" src="https://avatars.githubusercontent.com/u/31031438" /> | ||
</a> | ||
<a | ||
target = _blank | ||
href = 'https://kanamekey.com' | ||
/> | ||
<img | ||
width = 94 | ||
src = 'https://images.opencollective.com/kaname/d15fd98/logo/256.png' | ||
/> | ||
<a target="_blank" href="https://www.beekai.com/"> | ||
<img width="94" src="https://www.beekai.com/marketing/logo/logo.svg" /> | ||
</a> | ||
<a | ||
target = _blank | ||
href = 'https://formcarry.com/' | ||
/> | ||
<img | ||
width = 94 | ||
src = 'https://images.opencollective.com/formcarry/a40a4ea/logo/256.png' | ||
/> | ||
<a target="_blank" href="https://kanamekey.com"> | ||
<img width="94" src="https://images.opencollective.com/kaname/d15fd98/logo/256.png" /> | ||
</a> | ||
<a target="_blank" href="https://formcarry.com/"> | ||
<img width="94" src="https://images.opencollective.com/formcarry/a40a4ea/logo/256.png" /> | ||
</a> | ||
@@ -107,0 +86,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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
854586
42
4860
100