react-hook-form
Advanced tools
Comparing version 7.40.0 to 7.41.0
@@ -45,4 +45,4 @@ /// <reference types="react" /> | ||
*/ | ||
declare const Controller: <TFieldValues extends FieldValues = FieldValues, TName extends import("./types").Path<TFieldValues> = import("./types").Path<TFieldValues>>(props: ControllerProps<TFieldValues, TName>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>; | ||
declare const Controller: <TFieldValues extends FieldValues = FieldValues, TName extends import("./types").Path<import("./types").UnPackAsyncDefaultValues<TFieldValues>> = import("./types").Path<import("./types").UnPackAsyncDefaultValues<TFieldValues>>>(props: ControllerProps<TFieldValues, TName>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>; | ||
export { Controller }; | ||
//# sourceMappingURL=controller.d.ts.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const n=e=>"object"==typeof e;var i=e=>!a(e)&&!Array.isArray(e)&&n(e)&&!s(e),o=e=>i(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,u=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>Array.isArray(e)?e.filter(Boolean):[],c=e=>void 0===e,d=(e,t,r)=>{if(!t||!i(e))return r;const s=l(t.split(/[,[\].]+?/)).reduce((e,t)=>a(e)?e:e[t],e);return c(s)||s===e?c(e[t])?r:e[t]:s};const f="blur",m="focusout",y="change",g="onBlur",h="onChange",p="onSubmit",_="onTouched",v="all",b="max",x="min",A="maxLength",V="minLength",F="pattern",S="required",w="validate",k=t.default.createContext(null),D=()=>t.default.useContext(k);var C=(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},E=e=>i(e)&&!Object.keys(e).length,j=(e,t,r)=>{const{name:s,...a}=e;return E(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(e=>t[e]===(!r||v))},O=e=>Array.isArray(e)?e:[e],U=(e,t,r)=>r&&t?e===t:!e||!t||e===t||O(e).some(e=>e&&(e.startsWith(t)||t.startsWith(e)));function B(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect(()=>{const t=!e.disabled&&r.current.subject.subscribe({next:r.current.callback});return()=>{t&&t.unsubscribe()}},[e.disabled])}function T(e){const r=D(),{control:s=r.control,disabled:a,name:n,exact:i}=e||{},[o,u]=t.default.useState(s._formState),l=t.default.useRef(!0),c=t.default.useRef({isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=t.default.useRef(n);return d.current=n,B({disabled:a,callback:t.default.useCallback(e=>l.current&&U(d.current,e.name,i)&&j(e,c.current)&&u({...s._formState,...e}),[s,i]),subject:s._subjects.state}),t.default.useEffect(()=>{l.current=!0;const e=s._proxyFormState.isDirty&&s._getDirty();return e!==s._formState.isDirty&&s._subjects.state.next({isDirty:e}),s._updateValid(),()=>{l.current=!1}},[s]),C(o,s,c.current,!1)}var M=e=>"string"==typeof e,N=(e,t,r,s)=>M(e)?(s&&t.watch.add(e),d(r,e)):Array.isArray(e)?e.map(e=>(s&&t.watch.add(e),d(r,e))):(s&&(t.watchAll=!0),r),L="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function R(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(L&&(e instanceof Blob||e instanceof FileList)||!r&&!i(e))return e;if(t=r?[]:{},Array.isArray(e)||(e=>{const t=e.constructor&&e.constructor.prototype;return i(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)t[r]=R(e[r]);else t=e}return t}function q(e){const r=D(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:o}=e||{},u=t.default.useRef(a);u.current=a,B({disabled:i,subject:s._subjects.watch,callback:e=>{if(U(u.current,e.name,o)){const t=N(u.current,s._names,e.values||s._formValues);d(c(t)?n:R(t))}}});const[l,d]=t.default.useState(c(n)?s._getWatch(a):n);return t.default.useEffect(()=>s._removeUnmounted()),l}function P(e){const r=D(),{name:s,control:a=r.control,shouldUnregister:n}=e,i=u(a._names.array,s),l=q({control:a,name:s,defaultValue:d(a._formValues,s,d(a._defaultValues,s,e.defaultValue)),exact:!0}),c=T({control:a,name:s}),m=t.default.useRef(a.register(s,{...e.rules,value:l}));return t.default.useEffect(()=>{const e=(e,t)=>{const r=d(a._fields,e);r&&(r._f.mount=t)};return e(s,!0),()=>{const t=a._options.shouldUnregister||n;(i?t&&!a._stateFlags.action:t)?a.unregister(s):e(s,!1)}},[s,a,i,n]),{field:{name:s,value:l,onChange:t.default.useCallback(e=>m.current.onChange({target:{value:o(e),name:s},type:y}),[s]),onBlur:t.default.useCallback(()=>m.current.onBlur({target:{value:d(a._formValues,s),name:s},type:f}),[s,a]),ref:e=>{const t=d(a._fields,s);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:c,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!d(c.errors,s)},isDirty:{enumerable:!0,get:()=>!!d(c.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!d(c.touchedFields,s)},error:{enumerable:!0,get:()=>d(c.errors,s)}})}}var W=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},$=e=>/^\w*$/.test(e),I=e=>l(e.replace(/["|']|\]/g,"").split(/\.|\[/));function H(e,t,r){let s=-1;const a=$(t)?[t]:I(t),n=a.length,o=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==o){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}const z=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=d(e,s);if(r){const{_f:e,...s}=r;if(e&&t(e.name)){if(e.ref.focus){e.ref.focus();break}if(e.refs&&e.refs[0].focus){e.refs[0].focus();break}}else i(s)&&z(s,t)}}};var G=()=>{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)})},J=(e,t,r={})=>r.shouldFocus||c(r.shouldFocus)?r.focusName||`${e}.${c(r.focusIndex)?t:r.focusIndex}.`:"",K=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))),Q=(e,t,r)=>{const s=l(d(e,r));return H(s,"root",t[r]),H(e,r,s),e},X=e=>"boolean"==typeof e,Y=e=>"file"===e.type,Z=e=>"function"==typeof e,ee=e=>M(e)||t.default.isValidElement(e),te=e=>"radio"===e.type,re=e=>e instanceof RegExp;const se={value:!1,isValid:!1},ae={value:!0,isValid:!0};var ne=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!c(e[0].attributes.value)?c(e[0].value)||""===e[0].value?ae:{value:e[0].value,isValid:!0}:ae:se}return se};const ie={isValid:!1,value:null};var oe=e=>Array.isArray(e)?e.reduce((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e,ie):ie;function ue(e,t,r="validate"){if(ee(e)||Array.isArray(e)&&e.every(ee)||X(e)&&!e)return{type:r,message:ee(e)?e:"",ref:t}}var le=e=>i(e)&&!re(e)?e:{value:e,message:""},ce=async(e,t,s,n,o)=>{const{ref:u,refs:l,required:c,maxLength:d,minLength:f,min:m,max:y,pattern:g,validate:h,name:p,valueAsNumber:_,mount:v,disabled:k}=e._f;if(!v||k)return{};const D=l?l[0]:u,C=e=>{n&&D.reportValidity&&(D.setCustomValidity(X(e)?"":e||""),D.reportValidity())},j={},O=te(u),U=r(u),B=O||U,T=(_||Y(u))&&!u.value||""===t||Array.isArray(t)&&!t.length,N=W.bind(null,p,s,j),L=(e,t,r,s=A,a=V)=>{const n=e?t:r;j[p]={type:e?s:a,message:n,ref:u,...N(e?s:a,n)}};if(o?!Array.isArray(t)||!t.length:c&&(!B&&(T||a(t))||X(t)&&!t||U&&!ne(l).isValid||O&&!oe(l).isValid)){const{value:e,message:t}=ee(c)?{value:!!c,message:c}:le(c);if(e&&(j[p]={type:S,message:t,ref:D,...N(S,t)},!s))return C(t),j}if(!(T||a(m)&&a(y))){let e,r;const n=le(y),i=le(m);if(a(t)||isNaN(t)){const s=u.valueAsDate||new Date(t),a=e=>new Date((new Date).toDateString()+" "+e),o="time"==u.type,l="week"==u.type;M(n.value)&&t&&(e=o?a(t)>a(n.value):l?t>n.value:s>new Date(n.value)),M(i.value)&&t&&(r=o?a(t)<a(i.value):l?t<i.value:s<new Date(i.value))}else{const s=u.valueAsNumber||(t?+t:t);a(n.value)||(e=s>n.value),a(i.value)||(r=s<i.value)}if((e||r)&&(L(!!e,n.message,i.message,b,x),!s))return C(j[p].message),j}if((d||f)&&!T&&(M(t)||o&&Array.isArray(t))){const e=le(d),r=le(f),n=!a(e.value)&&t.length>e.value,i=!a(r.value)&&t.length<r.value;if((n||i)&&(L(n,e.message,r.message),!s))return C(j[p].message),j}if(g&&!T&&M(t)){const{value:e,message:r}=le(g);if(re(e)&&!t.match(e)&&(j[p]={type:F,message:r,ref:u,...N(F,r)},!s))return C(r),j}if(h)if(Z(h)){const e=ue(await h(t),D);if(e&&(j[p]={...e,...N(w,e.message)},!s))return C(e.message),j}else if(i(h)){let e={};for(const r in h){if(!E(e)&&!s)break;const a=ue(await h[r](t),D,r);a&&(e={...a,...N(r,a.message)},C(a.message),s&&(j[p]=e))}if(!E(e)&&(j[p]={ref:D,...e},!s))return j}return C(!0),j};function de(e,t){return[...e,...O(t)]}var fe=e=>Array.isArray(e)?e.map(()=>{}):void 0,me=e=>({isOnSubmit:!e||e===p,isOnBlur:e===g,isOnChange:e===h,isOnAll:e===v,isOnTouch:e===_});function ye(e,t,r){return[...e.slice(0,t),...O(r),...e.slice(t)]}var ge=(e,t,r)=>Array.isArray(e)?(c(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function he(e,t){return[...O(t),...O(e)]}var pe=(e,t)=>c(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return l(s).length?s:[]}(e,O(t).sort((e,t)=>e-t)),_e=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function ve(e){for(const t in e)if(!c(e[t]))return!1;return!0}function be(e,t){const r=$(t)?[t]:I(t),s=1==r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=c(e)?s++:e[t[s++]];return e}(e,r),a=r[r.length-1];let n;s&&delete s[a];for(let t=0;t<r.slice(0,-1).length;t++){let s,a=-1;const o=r.slice(0,-(t+1)),u=o.length-1;for(t>0&&(n=e);++a<o.length;){const t=o[a];s=s?s[t]:e[t],u===a&&(i(s)&&E(s)||Array.isArray(s)&&ve(s))&&(n?delete n[t]:delete e[t]),n=s}}return e}var xe=(e,t,r)=>(e[t]=r,e);function Ae(){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 Ve=e=>a(e)||!n(e);function Fe(e,t){if(Ve(e)||Ve(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r){const r=e[n];if(!a.includes(n))return!1;if("ref"!==n){const e=t[n];if(s(r)&&s(e)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!Fe(r,e):r!==e)return!1}}return!0}var Se=e=>{const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},we=e=>"select-multiple"===e.type,ke=e=>Se(e)&&e.isConnected,De=e=>{for(const t in e)if(Z(e[t]))return!0;return!1};function Ce(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!De(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ce(e[r],t[r])):a(e[r])||(t[r]=!0);return t}var Ee=(e,t)=>function e(t,r,s){const n=Array.isArray(t);if(i(t)||n)for(const n in t)Array.isArray(t[n])||i(t[n])&&!De(t[n])?c(r)||Ve(s[n])?s[n]=Array.isArray(t[n])?Ce(t[n],[]):{...Ce(t[n])}:e(t[n],a(r)?{}:r[n],s[n]):Fe(t[n],r[n])?delete s[n]:s[n]=!0;return s}(e,t,Ce(t)),je=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>c(e)?e:t?""===e?NaN:e?+e:e:r&&M(e)?new Date(e):s?s(e):e;function Oe(e){const t=e.ref;if(!(e.refs?e.refs.every(e=>e.disabled):t.disabled))return Y(t)?t.files:te(t)?oe(e.refs).value:we(t)?[...t.selectedOptions].map(({value:e})=>e):r(t)?ne(e.refs).value:je(c(t.value)?e.ref.value:t.value,e)}var Ue=e=>c(e)?e:re(e)?e.source:i(e)?re(e.value)?e.value.source:e.value:e;function Be(e,t,r){const s=d(e,r);if(s||$(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=d(t,s),i=d(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 Te={mode:p,reValidateMode:h,shouldFocusError:!0};function Me(e={}){let t,n={...Te,...e},i={submitCount:0,isDirty:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},y={},g=R(n.defaultValues)||{},h=n.shouldUnregister?{}:R(g),p={action:!1,mount:!1,watch:!1},_={mount:new Set,unMount:new Set,array:new Set,watch:new Set},b=0;const x={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},A={watch:Ae(),array:Ae(),state:Ae()},V=me(n.mode),F=me(n.reValidateMode),S=n.criteriaMode===v,w=async()=>{if(x.isValid){const e=n.resolver?E((await U()).errors):await B(y,!0);e!==i.isValid&&(i.isValid=e,A.state.next({isValid:e}))}},k=e=>x.isValidating&&e!==i.isValidating&&A.state.next({isValidating:e}),D=(e,t,r,s)=>{const a=d(y,e);if(a){const n=d(h,e,c(r)?d(g,e):r);c(n)||s&&s.defaultChecked||t?H(h,e,t?n:Oe(a._f)):P(e,n),p.mount&&w()}},C=(e,t,r,s,a)=>{let n=!1,o=!1;const u={name:e};if((!r||s)&&(x.isDirty&&(o=i.isDirty,i.isDirty=u.isDirty=T(),n=o!==u.isDirty),x.dirtyFields)){o=d(i.dirtyFields,e);const r=Fe(d(g,e),t);r?be(i.dirtyFields,e):H(i.dirtyFields,e,!0),u.dirtyFields=i.dirtyFields,n=n||o!==!r}if(r){const t=d(i.touchedFields,e);t||(H(i.touchedFields,e,r),u.touchedFields=i.touchedFields,n=n||x.touchedFields&&t!==r)}return n&&a&&A.state.next(u),n?u:{}},j=(r,s,a,n)=>{const o=d(i.errors,r),u=x.isValid&&X(s)&&i.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{H(i.errors,e,t),A.state.next({errors:i.errors})})(r,a),t=e=>{clearTimeout(b),b=window.setTimeout(l,e)},t(e.delayError)):(clearTimeout(b),t=null,a?H(i.errors,r,a):be(i.errors,r)),(a?!Fe(o,a):o)||!E(n)||u){const e={...n,...u&&X(s)?{isValid:s}:{},errors:i.errors,name:r};i={...i,...e},A.state.next(e)}k(!1)},U=async e=>await n.resolver(h,n.context,((e,t,r,s)=>{const a={};for(const r of e){const e=d(t,r);e&&H(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||_.mount,y,n.criteriaMode,n.shouldUseNativeValidation)),B=async(e,t,r={valid:!0})=>{for(const s in e){const a=e[s];if(a){const{_f:e,...s}=a;if(e){const s=_.array.has(e.name),o=await ce(a,d(h,e.name),S,n.shouldUseNativeValidation,s);if(o[e.name]&&(r.valid=!1,t))break;!t&&(d(o,e.name)?s?Q(i.errors,o,e.name):H(i.errors,e.name,o[e.name]):be(i.errors,e.name))}s&&await B(s,t,r)}}return r.valid},T=(e,t)=>(e&&t&&H(h,e,t),!Fe(J(),g)),q=(e,t,r)=>N(e,_,{...p.mount?h:c(t)?g:M(e)?{[e]:t}:t},r),P=(e,t,s={})=>{const n=d(y,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&H(h,e,je(t,s)),i=L&&Se(s.ref)&&a(t)?"":t,we(s.ref)?[...s.ref.options].forEach(e=>e.selected=i.includes(e.value)):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach(e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(i)?!!i.find(t=>t===e.value):i===e.value)):s.refs[0]&&(s.refs[0].checked=!!i):s.refs.forEach(e=>e.checked=e.value===i):Y(s.ref)?s.ref.value="":(s.ref.value=i,s.ref.type||A.watch.next({name:e})))}(s.shouldDirty||s.shouldTouch)&&C(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&G(e)},W=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,o=d(y,i);!_.array.has(e)&&Ve(n)&&(!o||o._f)||s(n)?P(i,n,r):W(i,n,r)}},$=(e,t,r={})=>{const s=d(y,e),n=_.array.has(e),o=R(t);H(h,e,o),n?(A.array.next({name:e,values:h}),(x.isDirty||x.dirtyFields)&&r.shouldDirty&&(i.dirtyFields=Ee(g,h),A.state.next({name:e,dirtyFields:i.dirtyFields,isDirty:T(e,o)}))):!s||s._f||a(o)?P(e,o,r):W(e,o,r),K(e,_)&&A.state.next({}),A.watch.next({name:e})},I=async e=>{const r=e.target;let s=r.name;const a=d(y,s),u=()=>r.type?Oe(a._f):o(e);if(a){let r,o;const c=u(),g=e.type===f||e.type===m,p=!((l=a._f).mount&&(l.required||l.min||l.max||l.maxLength||l.minLength||l.pattern||l.validate)||n.resolver||d(i.errors,s)||a._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))(g,d(i.touchedFields,s),i.isSubmitted,F,V),v=K(s,_,g);H(h,s,c),g?(a._f.onBlur&&a._f.onBlur(e),t&&t(0)):a._f.onChange&&a._f.onChange(e);const b=C(s,c,g,!1),D=!E(b)||v;if(!g&&A.watch.next({name:s,type:e.type}),p)return x.isValid&&w(),D&&A.state.next({name:s,...v?{}:b});if(!g&&v&&A.state.next({}),k(!0),n.resolver){const{errors:e}=await U([s]),t=Be(i.errors,y,s),a=Be(e,y,t.name||s);r=a.error,s=a.name,o=E(e)}else r=(await ce(a,d(h,s),S,n.shouldUseNativeValidation))[s],r?o=!1:x.isValid&&(o=await B(y,!0));Ve(c)&&u()!==c?k(!1):(a._f.deps&&G(a._f.deps),j(s,o,r,b))}var l},G=async(e,t={})=>{let r,s;const a=O(e);if(k(!0),n.resolver){const t=await(async e=>{const{errors:t}=await U();if(e)for(const r of e){const e=d(t,r);e?H(i.errors,r,e):be(i.errors,r)}else i.errors=t;return t})(c(e)?e:a);r=E(t),s=e?!a.some(e=>d(t,e)):r}else e?(s=(await Promise.all(a.map(async e=>{const t=d(y,e);return await B(t&&t._f?{[e]:t}:t)}))).every(Boolean),(s||i.isValid)&&w()):s=r=await B(y);return A.state.next({...!M(e)||x.isValid&&r!==i.isValid?{}:{name:e},...n.resolver||!e?{isValid:r}:{},errors:i.errors,isValidating:!1}),t.shouldFocus&&!s&&z(y,e=>e&&d(i.errors,e),e?a:_.mount),s},J=e=>{const t={...g,...p.mount?h:{}};return c(e)?t:M(e)?d(t,e):e.map(e=>d(t,e))},ee=(e,t)=>({invalid:!!d((t||i).errors,e),isDirty:!!d((t||i).dirtyFields,e),isTouched:!!d((t||i).touchedFields,e),error:d((t||i).errors,e)}),re=(e,t={})=>{for(const r of e?O(e):_.mount)_.mount.delete(r),_.array.delete(r),d(y,r)&&(t.keepValue||(be(y,r),be(h,r)),!t.keepError&&be(i.errors,r),!t.keepDirty&&be(i.dirtyFields,r),!t.keepTouched&&be(i.touchedFields,r),!n.shouldUnregister&&!t.keepDefaultValue&&be(g,r));A.watch.next({}),A.state.next({...i,...t.keepDirty?{isDirty:T()}:{}}),!t.keepIsValid&&w()},se=(e,t={})=>{let s=d(y,e);const a=X(t.disabled);return H(y,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),_.mount.add(e),s?a&&H(h,e,t.disabled?void 0:d(h,e,Oe(s._f))):D(e,!0,t.value),{...a?{disabled:t.disabled}:{},...n.shouldUseNativeValidation?{required:!!t.required,min:Ue(t.min),max:Ue(t.max),minLength:Ue(t.minLength),maxLength:Ue(t.maxLength),pattern:Ue(t.pattern)}:{},name:e,onChange:I,onBlur:I,ref:a=>{if(a){se(e,t),s=d(y,e);const n=c(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,i=(e=>te(e)||r(e))(n),o=s._f.refs||[];if(i?o.find(e=>e===n):n===s._f.ref)return;H(y,e,{_f:{...s._f,...i?{refs:[...o.filter(ke),n,...Array.isArray(d(g,e))?[{}]:[]],ref:{type:n.type,name:e}}:{ref:n}}}),D(e,!1,void 0,n)}else s=d(y,e,{}),s._f&&(s._f.mount=!1),(n.shouldUnregister||t.shouldUnregister)&&(!u(_.array,e)||!p.action)&&_.unMount.add(e)}}},ae=()=>n.shouldFocusError&&z(y,e=>e&&d(i.errors,e),_.mount);return{control:{register:se,unregister:re,getFieldState:ee,_executeSchema:U,_focusError:ae,_getWatch:q,_getDirty:T,_updateValid:w,_removeUnmounted:()=>{for(const e of _.unMount){const t=d(y,e);t&&(t._f.refs?t._f.refs.every(e=>!ke(e)):!ke(t._f.ref))&&re(e)}_.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(p.action=!0,n&&Array.isArray(d(y,e))){const t=r(d(y,e),s.argA,s.argB);a&&H(y,e,t)}if(n&&Array.isArray(d(i.errors,e))){const t=r(d(i.errors,e),s.argA,s.argB);a&&H(i.errors,e,t),((e,t)=>{!l(d(e,t)).length&&be(e,t)})(i.errors,e)}if(x.touchedFields&&n&&Array.isArray(d(i.touchedFields,e))){const t=r(d(i.touchedFields,e),s.argA,s.argB);a&&H(i.touchedFields,e,t)}x.dirtyFields&&(i.dirtyFields=Ee(g,h)),A.state.next({name:e,isDirty:T(e,t),dirtyFields:i.dirtyFields,errors:i.errors,isValid:i.isValid})}else H(h,e,t)},_getFieldArray:t=>l(d(p.mount?h:g,t,e.shouldUnregister?d(g,t,[]):[])),_subjects:A,_proxyFormState:x,get _fields(){return y},get _formValues(){return h},get _stateFlags(){return p},set _stateFlags(e){p=e},get _defaultValues(){return g},get _names(){return _},set _names(e){_=e},get _formState(){return i},set _formState(e){i=e},get _options(){return n},set _options(e){n={...n,...e}}},trigger:G,register:se,handleSubmit:(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let s=!0,a=R(h);A.state.next({isSubmitting:!0});try{if(n.resolver){const{errors:e,values:t}=await U();i.errors=e,a=t}else await B(y);E(i.errors)?(A.state.next({errors:{},isSubmitting:!0}),await e(a,r)):(t&&await t({...i.errors},r),ae())}catch(e){throw s=!1,e}finally{i.isSubmitted=!0,A.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:E(i.errors)&&s,submitCount:i.submitCount+1,errors:i.errors})}},watch:(e,t)=>Z(e)?A.watch.subscribe({next:r=>e(q(void 0,t),r)}):q(e,t,!0),setValue:$,getValues:J,reset:(t,r)=>((t,r={})=>{const s=t||g,a=R(s),n=t&&!E(t)?a:g;if(r.keepDefaultValues||(g=s),!r.keepValues){if(r.keepDirtyValues)for(const e of _.mount)d(i.dirtyFields,e)?H(n,e,d(h,e)):$(e,d(n,e));else{if(L&&c(t))for(const e of _.mount){const t=d(y,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Se(e)){const t=e.closest("form");if(t){t.reset();break}}}}y={}}h=e.shouldUnregister?r.keepDefaultValues?R(g):{}:a,A.array.next({values:n}),A.watch.next({values:n})}_={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},p.mount=!x.isValid||!!r.keepIsValid,p.watch=!!e.shouldUnregister,A.state.next({submitCount:r.keepSubmitCount?i.submitCount:0,isDirty:r.keepDirty||r.keepDirtyValues?i.isDirty:!(!r.keepDefaultValues||Fe(t,g)),isSubmitted:!!r.keepIsSubmitted&&i.isSubmitted,dirtyFields:r.keepDirty||r.keepDirtyValues?i.dirtyFields:r.keepDefaultValues&&t?Ee(g,t):{},touchedFields:r.keepTouched?i.touchedFields:{},errors:r.keepErrors?i.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})})(Z(t)?t(h):t,r),resetField:(e,t={})=>{d(y,e)&&(c(t.defaultValue)?$(e,d(g,e)):($(e,t.defaultValue),H(g,e,t.defaultValue)),t.keepTouched||be(i.touchedFields,e),t.keepDirty||(be(i.dirtyFields,e),i.isDirty=t.defaultValue?T(e,d(g,e)):T()),t.keepError||(be(i.errors,e),x.isValid&&w()),A.state.next({...i}))},clearErrors:e=>{e?O(e).forEach(e=>be(i.errors,e)):i.errors={},A.state.next({errors:i.errors})},unregister:re,setError:(e,t,r)=>{const s=(d(y,e,{_f:{}})._f||{}).ref;H(i.errors,e,{...t,ref:s}),A.state.next({name:e,errors:i.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},setFocus:(e,t={})=>{const r=d(y,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ee}}exports.Controller=e=>e.render(P(e)),exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(k.Provider,{value:s},r)},exports.appendErrors=W,exports.get=d,exports.set=H,exports.useController=P,exports.useFieldArray=function(e){const r=D(),{control:s=r.control,name:a,keyName:n="id",shouldUnregister:i}=e,[o,u]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map(G)),c=t.default.useRef(o),f=t.default.useRef(a),m=t.default.useRef(!1);f.current=a,c.current=o,s._names.array.add(a),e.rules&&s.register(a,e.rules),B({callback:t.default.useCallback(({values:e,name:t})=>{if(t===f.current||!t){const t=d(e,f.current);Array.isArray(t)&&(u(t),l.current=t.map(G))}},[]),subject:s._subjects.array});const y=t.default.useCallback(e=>{m.current=!0,s._updateFieldArray(a,e)},[s,a]);return t.default.useEffect(()=>{if(s._stateFlags.action=!1,K(a,s._names)&&s._subjects.state.next({}),m.current&&(!me(s._options.mode).isOnSubmit||s._formState.isSubmitted))if(s._options.resolver)s._executeSchema([a]).then(e=>{const t=d(e.errors,a),r=d(s._formState.errors,a);(r?!t&&r.type:t&&t.type)&&(t?H(s._formState.errors,a,t):be(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))});else{const e=d(s._fields,a);e&&e._f&&ce(e,d(s._formValues,a),s._options.criteriaMode===v,s._options.shouldUseNativeValidation,!0).then(e=>!E(e)&&s._subjects.state.next({errors:Q(s._formState.errors,e,a)}))}s._subjects.watch.next({name:a,values:s._formValues}),s._names.focus&&z(s._fields,e=>!!e&&e.startsWith(s._names.focus||"")),s._names.focus="",s._proxyFormState.isValid&&s._updateValid()},[o,a,s]),t.default.useEffect(()=>(!d(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||i)&&s.unregister(a)}),[a,s,n,i]),{swap:t.default.useCallback((e,t)=>{const r=s._getFieldArray(a);_e(r,e,t),_e(l.current,e,t),y(r),u(r),s._updateFieldArray(a,r,_e,{argA:e,argB:t},!1)},[y,a,s]),move:t.default.useCallback((e,t)=>{const r=s._getFieldArray(a);ge(r,e,t),ge(l.current,e,t),y(r),u(r),s._updateFieldArray(a,r,ge,{argA:e,argB:t},!1)},[y,a,s]),prepend:t.default.useCallback((e,t)=>{const r=O(R(e)),n=he(s._getFieldArray(a),r);s._names.focus=J(a,0,t),l.current=he(l.current,r.map(G)),y(n),u(n),s._updateFieldArray(a,n,he,{argA:fe(e)})},[y,a,s]),append:t.default.useCallback((e,t)=>{const r=O(R(e)),n=de(s._getFieldArray(a),r);s._names.focus=J(a,n.length-1,t),l.current=de(l.current,r.map(G)),y(n),u(n),s._updateFieldArray(a,n,de,{argA:fe(e)})},[y,a,s]),remove:t.default.useCallback(e=>{const t=pe(s._getFieldArray(a),e);l.current=pe(l.current,e),y(t),u(t),s._updateFieldArray(a,t,pe,{argA:e})},[y,a,s]),insert:t.default.useCallback((e,t,r)=>{const n=O(R(t)),i=ye(s._getFieldArray(a),e,n);s._names.focus=J(a,e,r),l.current=ye(l.current,e,n.map(G)),y(i),u(i),s._updateFieldArray(a,i,ye,{argA:e,argB:fe(t)})},[y,a,s]),update:t.default.useCallback((e,t)=>{const r=R(t),n=xe(s._getFieldArray(a),e,r);l.current=[...n].map((t,r)=>t&&r!==e?l.current[r]:G()),y(n),u([...n]),s._updateFieldArray(a,n,xe,{argA:e,argB:r},!0,!1)},[y,a,s]),replace:t.default.useCallback(e=>{const t=O(R(e));l.current=t.map(G),y([...t]),u([...t]),s._updateFieldArray(a,[...t],e=>e,{},!0,!1)},[y,a,s]),fields:t.default.useMemo(()=>o.map((e,t)=>({...e,[n]:l.current[t]||G()})),[o,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),[s,a]=t.default.useState({isDirty:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:e.defaultValues});r.current||(r.current={...Me(e),formState:s});const n=r.current.control;return n._options=e,B({subject:n._subjects.state,callback:t.default.useCallback(e=>{j(e,n._proxyFormState,!0)&&(n._formState={...n._formState,...e},a({...n._formState}))},[n])}),t.default.useEffect(()=>{n._stateFlags.mount||(n._proxyFormState.isValid&&n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()}),t.default.useEffect(()=>{s.submitCount&&n._focusError()},[n,s.submitCount]),r.current.formState=C(s,n),r.current},exports.useFormContext=D,exports.useFormState=T,exports.useWatch=q; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const n=e=>"object"==typeof e;var i=e=>!a(e)&&!Array.isArray(e)&&n(e)&&!s(e),o=e=>i(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,u=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>Array.isArray(e)?e.filter(Boolean):[],c=e=>void 0===e,d=(e,t,r)=>{if(!t||!i(e))return r;const s=l(t.split(/[,[\].]+?/)).reduce(((e,t)=>a(e)?e:e[t]),e);return c(s)||s===e?c(e[t])?r:e[t]:s};const f="blur",m="focusout",y="change",g="onBlur",p="onChange",h="onSubmit",_="onTouched",v="all",b="max",x="min",A="maxLength",V="minLength",F="pattern",S="required",w="validate",k=t.default.createContext(null),D=()=>t.default.useContext(k);var C=(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},E=e=>i(e)&&!Object.keys(e).length,j=(e,t,r)=>{const{name:s,...a}=e;return E(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find((e=>t[e]===(!r||v)))},O=e=>Array.isArray(e)?e:[e],U=(e,t,r)=>r&&t?e===t:!e||!t||e===t||O(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function B(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect((()=>{const t=!e.disabled&&r.current.subject.subscribe({next:r.current.next});return()=>{t&&t.unsubscribe()}}),[e.disabled])}function L(e){const r=D(),{control:s=r.control,disabled:a,name:n,exact:i}=e||{},[o,u]=t.default.useState(s._formState),l=t.default.useRef(!0),c=t.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=t.default.useRef(n);return d.current=n,B({disabled:a,next:e=>l.current&&U(d.current,e.name,i)&&j(e,c.current)&&u({...s._formState,...e}),subject:s._subjects.state}),t.default.useEffect((()=>{l.current=!0;const e=s._proxyFormState.isDirty&&s._getDirty();return e!==s._formState.isDirty&&s._subjects.state.next({isDirty:e}),s._updateValid(),()=>{l.current=!1}}),[s]),C(o,s,c.current,!1)}var T=e=>"string"==typeof e,M=(e,t,r,s)=>T(e)?(s&&t.watch.add(e),d(r,e)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),d(r,e)))):(s&&(t.watchAll=!0),r),N="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function R(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(N&&(e instanceof Blob||e instanceof FileList)||!r&&!i(e))return e;if(t=r?[]:{},Array.isArray(e)||(e=>{const t=e.constructor&&e.constructor.prototype;return i(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)t[r]=R(e[r]);else t=e}return t}function q(e){const r=D(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:o}=e||{},u=t.default.useRef(a);u.current=a,B({disabled:i,subject:s._subjects.watch,next:e=>{if(U(u.current,e.name,o)){const t=M(u.current,s._names,e.values||s._formValues);d(c(t)?n:R(t))}}});const[l,d]=t.default.useState(s._getWatch(a,n));return t.default.useEffect((()=>s._removeUnmounted())),l}function P(e){const r=D(),{name:s,control:a=r.control,shouldUnregister:n}=e,i=u(a._names.array,s),l=q({control:a,name:s,defaultValue:d(a._formValues,s,d(a._defaultValues,s,e.defaultValue)),exact:!0}),c=L({control:a,name:s}),m=t.default.useRef(a.register(s,{...e.rules,value:l}));return t.default.useEffect((()=>{const e=(e,t)=>{const r=d(a._fields,e);r&&(r._f.mount=t)};return e(s,!0),()=>{const t=a._options.shouldUnregister||n;(i?t&&!a._stateFlags.action:t)?a.unregister(s):e(s,!1)}}),[s,a,i,n]),{field:{name:s,value:l,onChange:t.default.useCallback((e=>m.current.onChange({target:{value:o(e),name:s},type:y})),[s]),onBlur:t.default.useCallback((()=>m.current.onBlur({target:{value:d(a._formValues,s),name:s},type:f})),[s,a]),ref:e=>{const t=d(a._fields,s);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:c,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!d(c.errors,s)},isDirty:{enumerable:!0,get:()=>!!d(c.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!d(c.touchedFields,s)},error:{enumerable:!0,get:()=>d(c.errors,s)}})}}var W=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},$=e=>/^\w*$/.test(e),I=e=>l(e.replace(/["|']|\]/g,"").split(/\.|\[/));function H(e,t,r){let s=-1;const a=$(t)?[t]:I(t),n=a.length,o=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==o){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}const z=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=d(e,s);if(r){const{_f:e,...s}=r;if(e&&t(e.name)){if(e.ref.focus){e.ref.focus();break}if(e.refs&&e.refs[0].focus){e.refs[0].focus();break}}else i(s)&&z(s,t)}}};var G=()=>{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)}))},J=(e,t,r={})=>r.shouldFocus||c(r.shouldFocus)?r.focusName||`${e}.${c(r.focusIndex)?t:r.focusIndex}.`:"",K=e=>({isOnSubmit:!e||e===h,isOnBlur:e===g,isOnChange:e===p,isOnAll:e===v,isOnTouch:e===_}),Q=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length))))),X=(e,t,r)=>{const s=l(d(e,r));return H(s,"root",t[r]),H(e,r,s),e},Y=e=>"boolean"==typeof e,Z=e=>"file"===e.type,ee=e=>"function"==typeof e,te=e=>T(e)||t.default.isValidElement(e),re=e=>"radio"===e.type,se=e=>e instanceof RegExp;const ae={value:!1,isValid:!1},ne={value:!0,isValid:!0};var ie=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&&!c(e[0].attributes.value)?c(e[0].value)||""===e[0].value?ne:{value:e[0].value,isValid:!0}:ne:ae}return ae};const oe={isValid:!1,value:null};var ue=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),oe):oe;function le(e,t,r="validate"){if(te(e)||Array.isArray(e)&&e.every(te)||Y(e)&&!e)return{type:r,message:te(e)?e:"",ref:t}}var ce=e=>i(e)&&!se(e)?e:{value:e,message:""},de=async(e,t,s,n,o)=>{const{ref:u,refs:l,required:d,maxLength:f,minLength:m,min:y,max:g,pattern:p,validate:h,name:_,valueAsNumber:v,mount:k,disabled:D}=e._f;if(!k||D)return{};const C=l?l[0]:u,j=e=>{n&&C.reportValidity&&(C.setCustomValidity(Y(e)?"":e||""),C.reportValidity())},O={},U=re(u),B=r(u),L=U||B,M=(v||Z(u))&&c(u.value)&&c(t)||""===t||Array.isArray(t)&&!t.length,N=W.bind(null,_,s,O),R=(e,t,r,s=A,a=V)=>{const n=e?t:r;O[_]={type:e?s:a,message:n,ref:u,...N(e?s:a,n)}};if(o?!Array.isArray(t)||!t.length:d&&(!L&&(M||a(t))||Y(t)&&!t||B&&!ie(l).isValid||U&&!ue(l).isValid)){const{value:e,message:t}=te(d)?{value:!!d,message:d}:ce(d);if(e&&(O[_]={type:S,message:t,ref:C,...N(S,t)},!s))return j(t),O}if(!(M||a(y)&&a(g))){let e,r;const n=ce(g),i=ce(y);if(a(t)||isNaN(t)){const s=u.valueAsDate||new Date(t),a=e=>new Date((new Date).toDateString()+" "+e),o="time"==u.type,l="week"==u.type;T(n.value)&&t&&(e=o?a(t)>a(n.value):l?t>n.value:s>new Date(n.value)),T(i.value)&&t&&(r=o?a(t)<a(i.value):l?t<i.value:s<new Date(i.value))}else{const s=u.valueAsNumber||(t?+t:t);a(n.value)||(e=s>n.value),a(i.value)||(r=s<i.value)}if((e||r)&&(R(!!e,n.message,i.message,b,x),!s))return j(O[_].message),O}if((f||m)&&!M&&(T(t)||o&&Array.isArray(t))){const e=ce(f),r=ce(m),n=!a(e.value)&&t.length>e.value,i=!a(r.value)&&t.length<r.value;if((n||i)&&(R(n,e.message,r.message),!s))return j(O[_].message),O}if(p&&!M&&T(t)){const{value:e,message:r}=ce(p);if(se(e)&&!t.match(e)&&(O[_]={type:F,message:r,ref:u,...N(F,r)},!s))return j(r),O}if(h)if(ee(h)){const e=le(await h(t),C);if(e&&(O[_]={...e,...N(w,e.message)},!s))return j(e.message),O}else if(i(h)){let e={};for(const r in h){if(!E(e)&&!s)break;const a=le(await h[r](t),C,r);a&&(e={...a,...N(r,a.message)},j(a.message),s&&(O[_]=e))}if(!E(e)&&(O[_]={ref:C,...e},!s))return O}return j(!0),O};function fe(e,t){return[...e,...O(t)]}var me=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ye(e,t,r){return[...e.slice(0,t),...O(r),...e.slice(t)]}var ge=(e,t,r)=>Array.isArray(e)?(c(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function pe(e,t){return[...O(t),...O(e)]}var he=(e,t)=>c(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return l(s).length?s:[]}(e,O(t).sort(((e,t)=>e-t))),_e=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function ve(e){for(const t in e)if(!c(e[t]))return!1;return!0}function be(e,t){const r=$(t)?[t]:I(t),s=1==r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=c(e)?s++:e[t[s++]];return e}(e,r),a=r[r.length-1];let n;s&&delete s[a];for(let t=0;t<r.slice(0,-1).length;t++){let s,a=-1;const o=r.slice(0,-(t+1)),u=o.length-1;for(t>0&&(n=e);++a<o.length;){const t=o[a];s=s?s[t]:e[t],u===a&&(i(s)&&E(s)||Array.isArray(s)&&ve(s))&&(n?delete n[t]:delete e[t]),n=s}}return e}var xe=(e,t,r)=>(e[t]=r,e);function Ae(){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 Ve=e=>a(e)||!n(e);function Fe(e,t){if(Ve(e)||Ve(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r){const r=e[n];if(!a.includes(n))return!1;if("ref"!==n){const e=t[n];if(s(r)&&s(e)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!Fe(r,e):r!==e)return!1}}return!0}var Se=e=>{const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},we=e=>"select-multiple"===e.type,ke=e=>Se(e)&&e.isConnected,De=e=>{for(const t in e)if(ee(e[t]))return!0;return!1};function Ce(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!De(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ce(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function Ee(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!De(e[s])?c(t)||Ve(r[s])?r[s]=Array.isArray(e[s])?Ce(e[s],[]):{...Ce(e[s])}:Ee(e[s],a(t)?{}:t[s],r[s]):Fe(e[s],t[s])?delete r[s]:r[s]=!0;return r}var je=(e,t)=>Ee(e,t,Ce(t)),Oe=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>c(e)?e:t?""===e?NaN:e?+e:e:r&&T(e)?new Date(e):s?s(e):e;function Ue(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return Z(t)?t.files:re(t)?ue(e.refs).value:we(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?ie(e.refs).value:Oe(c(t.value)?e.ref.value:t.value,e)}var Be=e=>c(e)?e:se(e)?e.source:i(e)?se(e.value)?e.value.source:e.value:e;function Le(e,t,r){const s=d(e,r);if(s||$(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=d(t,s),i=d(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 Te={mode:h,reValidateMode:p,shouldFocusError:!0};function Me(e={},t){let n={...Te,...e};const y=e.resetOptions&&e.resetOptions.keepDirtyValues;let g,p={submitCount:0,isDirty:!1,isLoading:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},h={},_=i(n.defaultValues)&&R(n.defaultValues)||{},b=n.shouldUnregister?{}:R(_),x={action:!1,mount:!1,watch:!1},A={mount:new Set,unMount:new Set,array:new Set,watch:new Set},V=0;const F={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},S={watch:Ae(),array:Ae(),state:Ae()},w=K(n.mode),k=K(n.reValidateMode),D=n.criteriaMode===v,C=async()=>{if(F.isValid){const e=n.resolver?E((await q()).errors):await P(h,!0);e!==p.isValid&&(p.isValid=e,S.state.next({isValid:e}))}},j=e=>F.isValidating&&S.state.next({isValidating:e}),U=(e,t,r,s)=>{const a=d(h,e);if(a){const n=d(b,e,c(r)?d(_,e):r);c(n)||s&&s.defaultChecked||t?H(b,e,t?n:Ue(a._f)):I(e,n),x.mount&&C()}},B=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e};if(!r||s){F.isDirty&&(i=p.isDirty,p.isDirty=o.isDirty=W(),n=i!==o.isDirty);const r=Fe(d(_,e),t);i=d(p.dirtyFields,e),r?be(p.dirtyFields,e):H(p.dirtyFields,e,!0),o.dirtyFields=p.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=d(p.touchedFields,e);t||(H(p.touchedFields,e,r),o.touchedFields=p.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(o),n?o:{}},L=(t,r,s,a)=>{const n=d(p.errors,t),i=F.isValid&&Y(r)&&p.isValid!==r;var o;if(e.delayError&&s?(o=()=>((e,t)=>{H(p.errors,e,t),S.state.next({errors:p.errors})})(t,s),g=e=>{clearTimeout(V),V=window.setTimeout(o,e)},g(e.delayError)):(clearTimeout(V),g=null,s?H(p.errors,t,s):be(p.errors,t)),(s?!Fe(n,s):n)||!E(a)||i){const e={...a,...i&&Y(r)?{isValid:r}:{},errors:p.errors,name:t};p={...p,...e},S.state.next(e)}j(!1)},q=async e=>await n.resolver(b,n.context,((e,t,r,s)=>{const a={};for(const r of e){const e=d(t,r);e&&H(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||A.mount,h,n.criteriaMode,n.shouldUseNativeValidation)),P=async(e,t,r={valid:!0})=>{for(const s in e){const a=e[s];if(a){const{_f:e,...s}=a;if(e){const s=A.array.has(e.name),i=await de(a,d(b,e.name),D,n.shouldUseNativeValidation,s);if(i[e.name]&&(r.valid=!1,t))break;!t&&(d(i,e.name)?s?X(p.errors,i,e.name):H(p.errors,e.name,i[e.name]):be(p.errors,e.name))}s&&await P(s,t,r)}}return r.valid},W=(e,t)=>(e&&t&&H(b,e,t),!Fe(ae(),_)),$=(e,t,r)=>M(e,A,{...x.mount?b:c(t)?_:T(e)?{[e]:t}:t},r),I=(e,t,s={})=>{const n=d(h,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&H(b,e,Oe(t,s)),i=N&&Se(s.ref)&&a(t)?"":t,we(s.ref)?[...s.ref.options].forEach((e=>e.selected=i.includes(e.value))):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(i)?!!i.find((t=>t===e.value)):i===e.value))):s.refs[0]&&(s.refs[0].checked=!!i):s.refs.forEach((e=>e.checked=e.value===i)):Z(s.ref)?s.ref.value="":(s.ref.value=i,s.ref.type||S.watch.next({name:e})))}(s.shouldDirty||s.shouldTouch)&&B(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&se(e)},G=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,o=d(h,i);!A.array.has(e)&&Ve(n)&&(!o||o._f)||s(n)?I(i,n,r):G(i,n,r)}},J=(e,r,s={})=>{const n=d(h,e),i=A.array.has(e),o=R(r);H(b,e,o),i?(S.array.next({name:e,values:b}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&(p.dirtyFields=je(_,b),S.state.next({name:e,dirtyFields:p.dirtyFields,isDirty:W(e,o)}))):!n||n._f||a(o)?I(e,o,s):G(e,o,s),Q(e,A)&&S.state.next({}),S.watch.next({name:e}),!x.mount&&t()},te=async e=>{const t=e.target;let r=t.name;const s=d(h,r),a=()=>t.type?Ue(s._f):o(e);if(s){let t,o;const u=a(),l=e.type===f||e.type===m,c=!((i=s._f).mount&&(i.required||i.min||i.max||i.maxLength||i.minLength||i.pattern||i.validate)||n.resolver||d(p.errors,r)||s._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))(l,d(p.touchedFields,r),p.isSubmitted,k,w),y=Q(r,A,l);H(b,r,u),l?(s._f.onBlur&&s._f.onBlur(e),g&&g(0)):s._f.onChange&&s._f.onChange(e);const _=B(r,u,l,!1),v=!E(_)||y;if(!l&&S.watch.next({name:r,type:e.type}),c)return F.isValid&&C(),v&&S.state.next({name:r,...y?{}:_});if(!l&&y&&S.state.next({}),j(!0),n.resolver){const{errors:e}=await q([r]),s=Le(p.errors,h,r),a=Le(e,h,s.name||r);t=a.error,r=a.name,o=E(e)}else t=(await de(s,d(b,r),D,n.shouldUseNativeValidation))[r],t?o=!1:F.isValid&&(o=await P(h,!0));Ve(u)&&a()!==u?j(!1):(s._f.deps&&se(s._f.deps),L(r,o,t,_))}var i},se=async(e,t={})=>{let r,s;const a=O(e);if(j(!0),n.resolver){const t=await(async e=>{const{errors:t}=await q();if(e)for(const r of e){const e=d(t,r);e?H(p.errors,r,e):be(p.errors,r)}else p.errors=t;return t})(c(e)?e:a);r=E(t),s=e?!a.some((e=>d(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=d(h,e);return await P(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||p.isValid)&&C()):s=r=await P(h);return S.state.next({...!T(e)||F.isValid&&r!==p.isValid?{}:{name:e},...n.resolver||!e?{isValid:r}:{},errors:p.errors,isValidating:!1}),t.shouldFocus&&!s&&z(h,(e=>e&&d(p.errors,e)),e?a:A.mount),s},ae=e=>{const t={..._,...x.mount?b:{}};return c(e)?t:T(e)?d(t,e):e.map((e=>d(t,e)))},ne=(e,t)=>({invalid:!!d((t||p).errors,e),isDirty:!!d((t||p).dirtyFields,e),isTouched:!!d((t||p).touchedFields,e),error:d((t||p).errors,e)}),ie=(e,t={})=>{for(const r of e?O(e):A.mount)A.mount.delete(r),A.array.delete(r),d(h,r)&&(t.keepValue||(be(h,r),be(b,r)),!t.keepError&&be(p.errors,r),!t.keepDirty&&be(p.dirtyFields,r),!t.keepTouched&&be(p.touchedFields,r),!n.shouldUnregister&&!t.keepDefaultValue&&be(_,r));S.watch.next({}),S.state.next({...p,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&C()},oe=(e,t={})=>{let s=d(h,e);const a=Y(t.disabled);return H(h,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),A.mount.add(e),s?a&&H(b,e,t.disabled?void 0:d(b,e,Ue(s._f))):U(e,!0,t.value),{...a?{disabled:t.disabled}:{},...n.shouldUseNativeValidation?{required:!!t.required,min:Be(t.min),max:Be(t.max),minLength:Be(t.minLength),maxLength:Be(t.maxLength),pattern:Be(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:a=>{if(a){oe(e,t),s=d(h,e);const n=c(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,i=(e=>re(e)||r(e))(n),o=s._f.refs||[];if(i?o.find((e=>e===n)):n===s._f.ref)return;H(h,e,{_f:{...s._f,...i?{refs:[...o.filter(ke),n,...Array.isArray(d(_,e))?[{}]:[]],ref:{type:n.type,name:e}}:{ref:n}}}),U(e,!1,void 0,n)}else s=d(h,e,{}),s._f&&(s._f.mount=!1),(n.shouldUnregister||t.shouldUnregister)&&(!u(A.array,e)||!x.action)&&A.unMount.add(e)}}},ue=()=>n.shouldFocusError&&z(h,(e=>e&&d(p.errors,e)),A.mount),le=(r,s={})=>{const a=r||_,n=R(a),i=r&&!E(r)?n:_;if(s.keepDefaultValues||(_=a),!s.keepValues){if(s.keepDirtyValues||y)for(const e of A.mount)d(p.dirtyFields,e)?H(i,e,d(b,e)):J(e,d(i,e));else{if(N&&c(r))for(const e of A.mount){const t=d(h,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Se(e)){const t=e.closest("form");if(t){t.reset();break}}}}h={}}b=e.shouldUnregister?s.keepDefaultValues?R(_):{}:n,S.array.next({values:i}),S.watch.next({values:i})}A={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&t(),x.mount=!F.isValid||!!s.keepIsValid,x.watch=!!e.shouldUnregister,S.state.next({submitCount:s.keepSubmitCount?p.submitCount:0,isDirty:s.keepDirty||s.keepDirtyValues?p.isDirty:!(!s.keepDefaultValues||Fe(r,_)),isSubmitted:!!s.keepIsSubmitted&&p.isSubmitted,dirtyFields:s.keepDirty||s.keepDirtyValues?p.dirtyFields:s.keepDefaultValues&&r?je(_,r):{},touchedFields:s.keepTouched?p.touchedFields:{},errors:s.keepErrors?p.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},ce=(e,t)=>le(ee(e)?e(b):e,t);return ee(n.defaultValues)&&n.defaultValues().then((e=>{ce(e,n.resetOptions),S.state.next({isLoading:!1})})),{control:{register:oe,unregister:ie,getFieldState:ne,_executeSchema:q,_focusError:ue,_getWatch:$,_getDirty:W,_updateValid:C,_removeUnmounted:()=>{for(const e of A.unMount){const t=d(h,e);t&&(t._f.refs?t._f.refs.every((e=>!ke(e))):!ke(t._f.ref))&&ie(e)}A.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(x.action=!0,n&&Array.isArray(d(h,e))){const t=r(d(h,e),s.argA,s.argB);a&&H(h,e,t)}if(n&&Array.isArray(d(p.errors,e))){const t=r(d(p.errors,e),s.argA,s.argB);a&&H(p.errors,e,t),((e,t)=>{!l(d(e,t)).length&&be(e,t)})(p.errors,e)}if(F.touchedFields&&n&&Array.isArray(d(p.touchedFields,e))){const t=r(d(p.touchedFields,e),s.argA,s.argB);a&&H(p.touchedFields,e,t)}F.dirtyFields&&(p.dirtyFields=je(_,b)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:p.dirtyFields,errors:p.errors,isValid:p.isValid})}else H(b,e,t)},_getFieldArray:t=>l(d(x.mount?b:_,t,e.shouldUnregister?d(_,t,[]):[])),_reset:le,_subjects:S,_proxyFormState:F,get _fields(){return h},get _formValues(){return b},get _stateFlags(){return x},set _stateFlags(e){x=e},get _defaultValues(){return _},get _names(){return A},set _names(e){A=e},get _formState(){return p},set _formState(e){p=e},get _options(){return n},set _options(e){n={...n,...e}}},trigger:se,register:oe,handleSubmit:(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let s=!0,a=R(b);S.state.next({isSubmitting:!0});try{if(n.resolver){const{errors:e,values:t}=await q();p.errors=e,a=t}else await P(h);E(p.errors)?(S.state.next({errors:{},isSubmitting:!0}),await e(a,r)):(t&&await t({...p.errors},r),ue())}catch(e){throw s=!1,e}finally{p.isSubmitted=!0,S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:E(p.errors)&&s,submitCount:p.submitCount+1,errors:p.errors})}},watch:(e,t)=>ee(e)?S.watch.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:J,getValues:ae,reset:ce,resetField:(e,t={})=>{d(h,e)&&(c(t.defaultValue)?J(e,d(_,e)):(J(e,t.defaultValue),H(_,e,t.defaultValue)),t.keepTouched||be(p.touchedFields,e),t.keepDirty||(be(p.dirtyFields,e),p.isDirty=t.defaultValue?W(e,d(_,e)):W()),t.keepError||(be(p.errors,e),F.isValid&&C()),S.state.next({...p}))},clearErrors:e=>{e?O(e).forEach((e=>be(p.errors,e))):p.errors={},S.state.next({errors:p.errors})},unregister:ie,setError:(e,t,r)=>{const s=(d(h,e,{_f:{}})._f||{}).ref;H(p.errors,e,{...t,ref:s}),S.state.next({name:e,errors:p.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},setFocus:(e,t={})=>{const r=d(h,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ne}}exports.Controller=e=>e.render(P(e)),exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(k.Provider,{value:s},r)},exports.appendErrors=W,exports.get=d,exports.set=H,exports.useController=P,exports.useFieldArray=function(e){const r=D(),{control:s=r.control,name:a,keyName:n="id",shouldUnregister:i}=e,[o,u]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map(G)),c=t.default.useRef(o),f=t.default.useRef(a),m=t.default.useRef(!1);f.current=a,c.current=o,s._names.array.add(a),e.rules&&s.register(a,e.rules),B({next:({values:e,name:t})=>{if(t===f.current||!t){const t=d(e,f.current);Array.isArray(t)&&(u(t),l.current=t.map(G))}},subject:s._subjects.array});const y=t.default.useCallback((e=>{m.current=!0,s._updateFieldArray(a,e)}),[s,a]);return t.default.useEffect((()=>{if(s._stateFlags.action=!1,Q(a,s._names)&&s._subjects.state.next({}),m.current&&(!K(s._options.mode).isOnSubmit||s._formState.isSubmitted))if(s._options.resolver)s._executeSchema([a]).then((e=>{const t=d(e.errors,a),r=d(s._formState.errors,a);(r?!t&&r.type:t&&t.type)&&(t?H(s._formState.errors,a,t):be(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=d(s._fields,a);e&&e._f&&de(e,d(s._formValues,a),s._options.criteriaMode===v,s._options.shouldUseNativeValidation,!0).then((e=>!E(e)&&s._subjects.state.next({errors:X(s._formState.errors,e,a)})))}s._subjects.watch.next({name:a,values:s._formValues}),s._names.focus&&z(s._fields,(e=>!!e&&e.startsWith(s._names.focus||""))),s._names.focus="",s._proxyFormState.isValid&&s._updateValid()}),[o,a,s]),t.default.useEffect((()=>(!d(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||i)&&s.unregister(a)})),[a,s,n,i]),{swap:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);_e(r,e,t),_e(l.current,e,t),y(r),u(r),s._updateFieldArray(a,r,_e,{argA:e,argB:t},!1)}),[y,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);ge(r,e,t),ge(l.current,e,t),y(r),u(r),s._updateFieldArray(a,r,ge,{argA:e,argB:t},!1)}),[y,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=O(R(e)),n=pe(s._getFieldArray(a),r);s._names.focus=J(a,0,t),l.current=pe(l.current,r.map(G)),y(n),u(n),s._updateFieldArray(a,n,pe,{argA:me(e)})}),[y,a,s]),append:t.default.useCallback(((e,t)=>{const r=O(R(e)),n=fe(s._getFieldArray(a),r);s._names.focus=J(a,n.length-1,t),l.current=fe(l.current,r.map(G)),y(n),u(n),s._updateFieldArray(a,n,fe,{argA:me(e)})}),[y,a,s]),remove:t.default.useCallback((e=>{const t=he(s._getFieldArray(a),e);l.current=he(l.current,e),y(t),u(t),s._updateFieldArray(a,t,he,{argA:e})}),[y,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=O(R(t)),i=ye(s._getFieldArray(a),e,n);s._names.focus=J(a,e,r),l.current=ye(l.current,e,n.map(G)),y(i),u(i),s._updateFieldArray(a,i,ye,{argA:e,argB:me(t)})}),[y,a,s]),update:t.default.useCallback(((e,t)=>{const r=R(t),n=xe(s._getFieldArray(a),e,r);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:G())),y(n),u([...n]),s._updateFieldArray(a,n,xe,{argA:e,argB:r},!0,!1)}),[y,a,s]),replace:t.default.useCallback((e=>{const t=O(R(e));l.current=t.map(G),y([...t]),u([...t]),s._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,s]),fields:t.default.useMemo((()=>o.map(((e,t)=>({...e,[n]:l.current[t]||G()})))),[o,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),[s,a]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:!0,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:ee(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Me(e,(()=>a((e=>({...e}))))),formState:s});const n=r.current.control;return n._options=e,B({subject:n._subjects.state,next:e=>{j(e,n._proxyFormState,!0)&&(n._formState={...n._formState,...e},a({...n._formState}))}}),t.default.useEffect((()=>{n._stateFlags.mount||(n._proxyFormState.isValid&&n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()})),t.default.useEffect((()=>{e.values&&!Fe(e.values,n._defaultValues)&&n._reset(e.values,n._options.resetOptions)}),[e.values,n]),t.default.useEffect((()=>{s.submitCount&&n._focusError()}),[n,s.submitCount]),r.current.formState=C(s,n),r.current},exports.useFormContext=D,exports.useFormState=L,exports.useWatch=q; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookForm={},e.React)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(t),a=e=>"checkbox"===e.type,n=e=>e instanceof Date,i=e=>null==e;const o=e=>"object"==typeof e;var u=e=>!i(e)&&!Array.isArray(e)&&o(e)&&!n(e),l=e=>u(e)&&e.target?a(e.target)?e.target.checked:e.target.value:e,c=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),d=e=>Array.isArray(e)?e.filter(Boolean):[],f=e=>void 0===e,m=(e,t,r)=>{if(!t||!u(e))return r;const s=d(t.split(/[,[\].]+?/)).reduce((e,t)=>i(e)?e:e[t],e);return f(s)||s===e?f(e[t])?r:e[t]:s};const y="blur",g="focusout",h="change",p="onBlur",_="onChange",b="onSubmit",v="onTouched",A="all",x="max",V="min",F="maxLength",S="minLength",w="pattern",k="required",D="validate",C=s.default.createContext(null),j=()=>s.default.useContext(C);var E=(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},O=e=>u(e)&&!Object.keys(e).length,T=(e,t,r)=>{const{name:s,...a}=e;return O(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(e=>t[e]===(!r||A))},U=e=>Array.isArray(e)?e:[e],B=(e,t,r)=>r&&t?e===t:!e||!t||e===t||U(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.callback});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,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=s.default.useRef(n);return d.current=n,M({disabled:a,callback:s.default.useCallback(e=>l.current&&B(d.current,e.name,i)&&T(e,c.current)&&u({...r._formState,...e}),[r,i]),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}),r._updateValid(),()=>{l.current=!1}},[r]),E(o,r,c.current,!1)}var L=e=>"string"==typeof e,R=(e,t,r,s)=>L(e)?(s&&t.watch.add(e),m(r,e)):Array.isArray(e)?e.map(e=>(s&&t.watch.add(e),m(r,e))):(s&&(t.watchAll=!0),r),q="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function P(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&&!u(e))return e;if(t=r?[]:{},Array.isArray(e)||(e=>{const t=e.constructor&&e.constructor.prototype;return u(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)t[r]=P(e[r]);else t=e}return t}function W(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,callback:e=>{if(B(u.current,e.name,o)){const t=R(u.current,r._names,e.values||r._formValues);c(f(t)?n:P(t))}}});const[l,c]=s.default.useState(f(n)?r._getWatch(a):n);return s.default.useEffect(()=>r._removeUnmounted()),l}function $(e){const t=j(),{name:r,control:a=t.control,shouldUnregister:n}=e,i=c(a._names.array,r),o=W({control:a,name:r,defaultValue:m(a._formValues,r,m(a._defaultValues,r,e.defaultValue)),exact:!0}),u=N({control:a,name:r}),d=s.default.useRef(a.register(r,{...e.rules,value:o}));return s.default.useEffect(()=>{const e=(e,t)=>{const r=m(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=>d.current.onChange({target:{value:l(e),name:r},type:h}),[r]),onBlur:s.default.useCallback(()=>d.current.onBlur({target:{value:m(a._formValues,r),name:r},type:y}),[r,a]),ref:e=>{const t=m(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:()=>!!m(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!m(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!m(u.touchedFields,r)},error:{enumerable:!0,get:()=>m(u.errors,r)}})}}var I=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},H=e=>/^\w*$/.test(e),z=e=>d(e.replace(/["|']|\]/g,"").split(/\.|\[/));function G(e,t,r){let s=-1;const a=H(t)?[t]:z(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=u(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}const J=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=m(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 u(s)&&J(s,t)}}};var K=()=>{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)})},Q=(e,t,r={})=>r.shouldFocus||f(r.shouldFocus)?r.focusName||`${e}.${f(r.focusIndex)?t:r.focusIndex}.`:"",X=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some(t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))),Y=(e,t,r)=>{const s=d(m(e,r));return G(s,"root",t[r]),G(e,r,s),e},Z=e=>"boolean"==typeof e,ee=e=>"file"===e.type,te=e=>"function"==typeof e,re=e=>L(e)||s.default.isValidElement(e),se=e=>"radio"===e.type,ae=e=>e instanceof RegExp;const ne={value:!1,isValid:!1},ie={value:!0,isValid:!0};var oe=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&&!f(e[0].attributes.value)?f(e[0].value)||""===e[0].value?ie:{value:e[0].value,isValid:!0}:ie:ne}return ne};const ue={isValid:!1,value:null};var le=e=>Array.isArray(e)?e.reduce((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e,ue):ue;function ce(e,t,r="validate"){if(re(e)||Array.isArray(e)&&e.every(re)||Z(e)&&!e)return{type:r,message:re(e)?e:"",ref:t}}var de=e=>u(e)&&!ae(e)?e:{value:e,message:""},fe=async(e,t,r,s,n)=>{const{ref:o,refs:l,required:c,maxLength:d,minLength:f,min:m,max:y,pattern:g,validate:h,name:p,valueAsNumber:_,mount:b,disabled:v}=e._f;if(!b||v)return{};const A=l?l[0]:o,C=e=>{s&&A.reportValidity&&(A.setCustomValidity(Z(e)?"":e||""),A.reportValidity())},j={},E=se(o),T=a(o),U=E||T,B=(_||ee(o))&&!o.value||""===t||Array.isArray(t)&&!t.length,M=I.bind(null,p,r,j),N=(e,t,r,s=F,a=S)=>{const n=e?t:r;j[p]={type:e?s:a,message:n,ref:o,...M(e?s:a,n)}};if(n?!Array.isArray(t)||!t.length:c&&(!U&&(B||i(t))||Z(t)&&!t||T&&!oe(l).isValid||E&&!le(l).isValid)){const{value:e,message:t}=re(c)?{value:!!c,message:c}:de(c);if(e&&(j[p]={type:k,message:t,ref:A,...M(k,t)},!r))return C(t),j}if(!(B||i(m)&&i(y))){let e,s;const a=de(y),n=de(m);if(i(t)||isNaN(t)){const r=o.valueAsDate||new Date(t),i=e=>new Date((new Date).toDateString()+" "+e),u="time"==o.type,l="week"==o.type;L(a.value)&&t&&(e=u?i(t)>i(a.value):l?t>a.value:r>new Date(a.value)),L(n.value)&&t&&(s=u?i(t)<i(n.value):l?t<n.value:r<new Date(n.value))}else{const r=o.valueAsNumber||(t?+t:t);i(a.value)||(e=r>a.value),i(n.value)||(s=r<n.value)}if((e||s)&&(N(!!e,a.message,n.message,x,V),!r))return C(j[p].message),j}if((d||f)&&!B&&(L(t)||n&&Array.isArray(t))){const e=de(d),s=de(f),a=!i(e.value)&&t.length>e.value,n=!i(s.value)&&t.length<s.value;if((a||n)&&(N(a,e.message,s.message),!r))return C(j[p].message),j}if(g&&!B&&L(t)){const{value:e,message:s}=de(g);if(ae(e)&&!t.match(e)&&(j[p]={type:w,message:s,ref:o,...M(w,s)},!r))return C(s),j}if(h)if(te(h)){const e=ce(await h(t),A);if(e&&(j[p]={...e,...M(D,e.message)},!r))return C(e.message),j}else if(u(h)){let e={};for(const s in h){if(!O(e)&&!r)break;const a=ce(await h[s](t),A,s);a&&(e={...a,...M(s,a.message)},C(a.message),r&&(j[p]=e))}if(!O(e)&&(j[p]={ref:A,...e},!r))return j}return C(!0),j};function me(e,t){return[...e,...U(t)]}var ye=e=>Array.isArray(e)?e.map(()=>{}):void 0,ge=e=>({isOnSubmit:!e||e===b,isOnBlur:e===p,isOnChange:e===_,isOnAll:e===A,isOnTouch:e===v});function he(e,t,r){return[...e.slice(0,t),...U(r),...e.slice(t)]}var pe=(e,t,r)=>Array.isArray(e)?(f(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function _e(e,t){return[...U(t),...U(e)]}var be=(e,t)=>f(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return d(s).length?s:[]}(e,U(t).sort((e,t)=>e-t)),ve=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function Ae(e){for(const t in e)if(!f(e[t]))return!1;return!0}function xe(e,t){const r=H(t)?[t]:z(t),s=1==r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=f(e)?s++:e[t[s++]];return e}(e,r),a=r[r.length-1];let n;s&&delete s[a];for(let t=0;t<r.slice(0,-1).length;t++){let s,a=-1;const i=r.slice(0,-(t+1)),o=i.length-1;for(t>0&&(n=e);++a<i.length;){const t=i[a];s=s?s[t]:e[t],o===a&&(u(s)&&O(s)||Array.isArray(s)&&Ae(s))&&(n?delete n[t]:delete e[t]),n=s}}return e}var Ve=(e,t,r)=>(e[t]=r,e);function Fe(){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 Se=e=>i(e)||!o(e);function we(e,t){if(Se(e)||Se(t))return e===t;if(n(e)&&n(t))return e.getTime()===t.getTime();const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const a of r){const r=e[a];if(!s.includes(a))return!1;if("ref"!==a){const e=t[a];if(n(r)&&n(e)||u(r)&&u(e)||Array.isArray(r)&&Array.isArray(e)?!we(r,e):r!==e)return!1}}return!0}var ke=e=>{const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},De=e=>"select-multiple"===e.type,Ce=e=>ke(e)&&e.isConnected,je=e=>{for(const t in e)if(te(e[t]))return!0;return!1};function Ee(e,t={}){const r=Array.isArray(e);if(u(e)||r)for(const r in e)Array.isArray(e[r])||u(e[r])&&!je(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ee(e[r],t[r])):i(e[r])||(t[r]=!0);return t}var Oe=(e,t)=>function e(t,r,s){const a=Array.isArray(t);if(u(t)||a)for(const a in t)Array.isArray(t[a])||u(t[a])&&!je(t[a])?f(r)||Se(s[a])?s[a]=Array.isArray(t[a])?Ee(t[a],[]):{...Ee(t[a])}:e(t[a],i(r)?{}:r[a],s[a]):we(t[a],r[a])?delete s[a]:s[a]=!0;return s}(e,t,Ee(t)),Te=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>f(e)?e:t?""===e?NaN:e?+e:e:r&&L(e)?new Date(e):s?s(e):e;function Ue(e){const t=e.ref;if(!(e.refs?e.refs.every(e=>e.disabled):t.disabled))return ee(t)?t.files:se(t)?le(e.refs).value:De(t)?[...t.selectedOptions].map(({value:e})=>e):a(t)?oe(e.refs).value:Te(f(t.value)?e.ref.value:t.value,e)}var Be=e=>f(e)?e:ae(e)?e.source:u(e)?ae(e.value)?e.value.source:e.value:e;function Me(e,t,r){const s=m(e,r);if(s||H(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=m(t,s),i=m(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 Ne={mode:b,reValidateMode:_,shouldFocusError:!0};function Le(e={}){let t,r={...Ne,...e},s={submitCount:0,isDirty:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},o={},u=P(r.defaultValues)||{},h=r.shouldUnregister?{}:P(u),p={action:!1,mount:!1,watch:!1},_={mount:new Set,unMount:new Set,array:new Set,watch:new Set},b=0;const v={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},x={watch:Fe(),array:Fe(),state:Fe()},V=ge(r.mode),F=ge(r.reValidateMode),S=r.criteriaMode===A,w=async()=>{if(v.isValid){const e=r.resolver?O((await E()).errors):await T(o,!0);e!==s.isValid&&(s.isValid=e,x.state.next({isValid:e}))}},k=e=>v.isValidating&&e!==s.isValidating&&x.state.next({isValidating:e}),D=(e,t,r,s)=>{const a=m(o,e);if(a){const n=m(h,e,f(r)?m(u,e):r);f(n)||s&&s.defaultChecked||t?G(h,e,t?n:Ue(a._f)):N(e,n),p.mount&&w()}},C=(e,t,r,a,n)=>{let i=!1,o=!1;const l={name:e};if((!r||a)&&(v.isDirty&&(o=s.isDirty,s.isDirty=l.isDirty=B(),i=o!==l.isDirty),v.dirtyFields)){o=m(s.dirtyFields,e);const r=we(m(u,e),t);r?xe(s.dirtyFields,e):G(s.dirtyFields,e,!0),l.dirtyFields=s.dirtyFields,i=i||o!==!r}if(r){const t=m(s.touchedFields,e);t||(G(s.touchedFields,e,r),l.touchedFields=s.touchedFields,i=i||v.touchedFields&&t!==r)}return i&&n&&x.state.next(l),i?l:{}},j=(r,a,n,i)=>{const o=m(s.errors,r),u=v.isValid&&Z(a)&&s.isValid!==a;var l;if(e.delayError&&n?(l=()=>((e,t)=>{G(s.errors,e,t),x.state.next({errors:s.errors})})(r,n),t=e=>{clearTimeout(b),b=window.setTimeout(l,e)},t(e.delayError)):(clearTimeout(b),t=null,n?G(s.errors,r,n):xe(s.errors,r)),(n?!we(o,n):o)||!O(i)||u){const e={...i,...u&&Z(a)?{isValid:a}:{},errors:s.errors,name:r};s={...s,...e},x.state.next(e)}k(!1)},E=async e=>await r.resolver(h,r.context,((e,t,r,s)=>{const a={};for(const r of e){const e=m(t,r);e&&G(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||_.mount,o,r.criteriaMode,r.shouldUseNativeValidation)),T=async(e,t,a={valid:!0})=>{for(const n in e){const i=e[n];if(i){const{_f:e,...n}=i;if(e){const n=_.array.has(e.name),o=await fe(i,m(h,e.name),S,r.shouldUseNativeValidation,n);if(o[e.name]&&(a.valid=!1,t))break;!t&&(m(o,e.name)?n?Y(s.errors,o,e.name):G(s.errors,e.name,o[e.name]):xe(s.errors,e.name))}n&&await T(n,t,a)}}return a.valid},B=(e,t)=>(e&&t&&G(h,e,t),!we(z(),u)),M=(e,t,r)=>R(e,_,{...p.mount?h:f(t)?u:L(e)?{[e]:t}:t},r),N=(e,t,r={})=>{const s=m(o,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&G(h,e,Te(t,r)),n=q&&ke(r.ref)&&i(t)?"":t,De(r.ref)?[...r.ref.options].forEach(e=>e.selected=n.includes(e.value)):r.refs?a(r.ref)?r.refs.length>1?r.refs.forEach(e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(n)?!!n.find(t=>t===e.value):n===e.value)):r.refs[0]&&(r.refs[0].checked=!!n):r.refs.forEach(e=>e.checked=e.value===n):ee(r.ref)?r.ref.value="":(r.ref.value=n,r.ref.type||x.watch.next({name:e})))}(r.shouldDirty||r.shouldTouch)&&C(e,n,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&H(e)},W=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,u=m(o,i);!_.array.has(e)&&Se(a)&&(!u||u._f)||n(a)?N(i,a,r):W(i,a,r)}},$=(e,t,r={})=>{const a=m(o,e),n=_.array.has(e),l=P(t);G(h,e,l),n?(x.array.next({name:e,values:h}),(v.isDirty||v.dirtyFields)&&r.shouldDirty&&(s.dirtyFields=Oe(u,h),x.state.next({name:e,dirtyFields:s.dirtyFields,isDirty:B(e,l)}))):!a||a._f||i(l)?N(e,l,r):W(e,l,r),X(e,_)&&x.state.next({}),x.watch.next({name:e})},I=async e=>{const a=e.target;let n=a.name;const i=m(o,n),u=()=>a.type?Ue(i._f):l(e);if(i){let a,l;const d=u(),f=e.type===y||e.type===g,p=!((c=i._f).mount&&(c.required||c.min||c.max||c.maxLength||c.minLength||c.pattern||c.validate)||r.resolver||m(s.errors,n)||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))(f,m(s.touchedFields,n),s.isSubmitted,F,V),b=X(n,_,f);G(h,n,d),f?(i._f.onBlur&&i._f.onBlur(e),t&&t(0)):i._f.onChange&&i._f.onChange(e);const A=C(n,d,f,!1),D=!O(A)||b;if(!f&&x.watch.next({name:n,type:e.type}),p)return v.isValid&&w(),D&&x.state.next({name:n,...b?{}:A});if(!f&&b&&x.state.next({}),k(!0),r.resolver){const{errors:e}=await E([n]),t=Me(s.errors,o,n),r=Me(e,o,t.name||n);a=r.error,n=r.name,l=O(e)}else a=(await fe(i,m(h,n),S,r.shouldUseNativeValidation))[n],a?l=!1:v.isValid&&(l=await T(o,!0));Se(d)&&u()!==d?k(!1):(i._f.deps&&H(i._f.deps),j(n,l,a,A))}var c},H=async(e,t={})=>{let a,n;const i=U(e);if(k(!0),r.resolver){const t=await(async e=>{const{errors:t}=await E();if(e)for(const r of e){const e=m(t,r);e?G(s.errors,r,e):xe(s.errors,r)}else s.errors=t;return t})(f(e)?e:i);a=O(t),n=e?!i.some(e=>m(t,e)):a}else e?(n=(await Promise.all(i.map(async e=>{const t=m(o,e);return await T(t&&t._f?{[e]:t}:t)}))).every(Boolean),(n||s.isValid)&&w()):n=a=await T(o);return x.state.next({...!L(e)||v.isValid&&a!==s.isValid?{}:{name:e},...r.resolver||!e?{isValid:a}:{},errors:s.errors,isValidating:!1}),t.shouldFocus&&!n&&J(o,e=>e&&m(s.errors,e),e?i:_.mount),n},z=e=>{const t={...u,...p.mount?h:{}};return f(e)?t:L(e)?m(t,e):e.map(e=>m(t,e))},K=(e,t)=>({invalid:!!m((t||s).errors,e),isDirty:!!m((t||s).dirtyFields,e),isTouched:!!m((t||s).touchedFields,e),error:m((t||s).errors,e)}),Q=(e,t={})=>{for(const a of e?U(e):_.mount)_.mount.delete(a),_.array.delete(a),m(o,a)&&(t.keepValue||(xe(o,a),xe(h,a)),!t.keepError&&xe(s.errors,a),!t.keepDirty&&xe(s.dirtyFields,a),!t.keepTouched&&xe(s.touchedFields,a),!r.shouldUnregister&&!t.keepDefaultValue&&xe(u,a));x.watch.next({}),x.state.next({...s,...t.keepDirty?{isDirty:B()}:{}}),!t.keepIsValid&&w()},re=(e,t={})=>{let s=m(o,e);const n=Z(t.disabled);return G(o,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),_.mount.add(e),s?n&&G(h,e,t.disabled?void 0:m(h,e,Ue(s._f))):D(e,!0,t.value),{...n?{disabled:t.disabled}:{},...r.shouldUseNativeValidation?{required:!!t.required,min:Be(t.min),max:Be(t.max),minLength:Be(t.minLength),maxLength:Be(t.maxLength),pattern:Be(t.pattern)}:{},name:e,onChange:I,onBlur:I,ref:n=>{if(n){re(e,t),s=m(o,e);const r=f(n.value)&&n.querySelectorAll&&n.querySelectorAll("input,select,textarea")[0]||n,i=(e=>se(e)||a(e))(r),l=s._f.refs||[];if(i?l.find(e=>e===r):r===s._f.ref)return;G(o,e,{_f:{...s._f,...i?{refs:[...l.filter(Ce),r,...Array.isArray(m(u,e))?[{}]:[]],ref:{type:r.type,name:e}}:{ref:r}}}),D(e,!1,void 0,r)}else s=m(o,e,{}),s._f&&(s._f.mount=!1),(r.shouldUnregister||t.shouldUnregister)&&(!c(_.array,e)||!p.action)&&_.unMount.add(e)}}},ae=()=>r.shouldFocusError&&J(o,e=>e&&m(s.errors,e),_.mount);return{control:{register:re,unregister:Q,getFieldState:K,_executeSchema:E,_focusError:ae,_getWatch:M,_getDirty:B,_updateValid:w,_removeUnmounted:()=>{for(const e of _.unMount){const t=m(o,e);t&&(t._f.refs?t._f.refs.every(e=>!Ce(e)):!Ce(t._f.ref))&&Q(e)}_.unMount=new Set},_updateFieldArray:(e,t=[],r,a,n=!0,i=!0)=>{if(a&&r){if(p.action=!0,i&&Array.isArray(m(o,e))){const t=r(m(o,e),a.argA,a.argB);n&&G(o,e,t)}if(i&&Array.isArray(m(s.errors,e))){const t=r(m(s.errors,e),a.argA,a.argB);n&&G(s.errors,e,t),((e,t)=>{!d(m(e,t)).length&&xe(e,t)})(s.errors,e)}if(v.touchedFields&&i&&Array.isArray(m(s.touchedFields,e))){const t=r(m(s.touchedFields,e),a.argA,a.argB);n&&G(s.touchedFields,e,t)}v.dirtyFields&&(s.dirtyFields=Oe(u,h)),x.state.next({name:e,isDirty:B(e,t),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else G(h,e,t)},_getFieldArray:t=>d(m(p.mount?h:u,t,e.shouldUnregister?m(u,t,[]):[])),_subjects:x,_proxyFormState:v,get _fields(){return o},get _formValues(){return h},get _stateFlags(){return p},set _stateFlags(e){p=e},get _defaultValues(){return u},get _names(){return _},set _names(e){_=e},get _formState(){return s},set _formState(e){s=e},get _options(){return r},set _options(e){r={...r,...e}}},trigger:H,register:re,handleSubmit:(e,t)=>async a=>{a&&(a.preventDefault&&a.preventDefault(),a.persist&&a.persist());let n=!0,i=P(h);x.state.next({isSubmitting:!0});try{if(r.resolver){const{errors:e,values:t}=await E();s.errors=e,i=t}else await T(o);O(s.errors)?(x.state.next({errors:{},isSubmitting:!0}),await e(i,a)):(t&&await t({...s.errors},a),ae())}catch(e){throw n=!1,e}finally{s.isSubmitted=!0,x.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:O(s.errors)&&n,submitCount:s.submitCount+1,errors:s.errors})}},watch:(e,t)=>te(e)?x.watch.subscribe({next:r=>e(M(void 0,t),r)}):M(e,t,!0),setValue:$,getValues:z,reset:(t,r)=>((t,r={})=>{const a=t||u,n=P(a),i=t&&!O(t)?n:u;if(r.keepDefaultValues||(u=a),!r.keepValues){if(r.keepDirtyValues)for(const e of _.mount)m(s.dirtyFields,e)?G(i,e,m(h,e)):$(e,m(i,e));else{if(q&&f(t))for(const e of _.mount){const t=m(o,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(ke(e)){const t=e.closest("form");if(t){t.reset();break}}}}o={}}h=e.shouldUnregister?r.keepDefaultValues?P(u):{}:n,x.array.next({values:i}),x.watch.next({values:i})}_={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},p.mount=!v.isValid||!!r.keepIsValid,p.watch=!!e.shouldUnregister,x.state.next({submitCount:r.keepSubmitCount?s.submitCount:0,isDirty:r.keepDirty||r.keepDirtyValues?s.isDirty:!(!r.keepDefaultValues||we(t,u)),isSubmitted:!!r.keepIsSubmitted&&s.isSubmitted,dirtyFields:r.keepDirty||r.keepDirtyValues?s.dirtyFields:r.keepDefaultValues&&t?Oe(u,t):{},touchedFields:r.keepTouched?s.touchedFields:{},errors:r.keepErrors?s.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})})(te(t)?t(h):t,r),resetField:(e,t={})=>{m(o,e)&&(f(t.defaultValue)?$(e,m(u,e)):($(e,t.defaultValue),G(u,e,t.defaultValue)),t.keepTouched||xe(s.touchedFields,e),t.keepDirty||(xe(s.dirtyFields,e),s.isDirty=t.defaultValue?B(e,m(u,e)):B()),t.keepError||(xe(s.errors,e),v.isValid&&w()),x.state.next({...s}))},clearErrors:e=>{e?U(e).forEach(e=>xe(s.errors,e)):s.errors={},x.state.next({errors:s.errors})},unregister:Q,setError:(e,t,r)=>{const a=(m(o,e,{_f:{}})._f||{}).ref;G(s.errors,e,{...t,ref:a}),x.state.next({name:e,errors:s.errors,isValid:!1}),r&&r.shouldFocus&&a&&a.focus&&a.focus()},setFocus:(e,t={})=>{const r=m(o,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:K}}e.Controller=e=>e.render($(e)),e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(C.Provider,{value:r},t)},e.appendErrors=I,e.get=m,e.set=G,e.useController=$,e.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(K)),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({callback:s.default.useCallback(({values:e,name:t})=>{if(t===d.current||!t){const t=m(e,d.current);Array.isArray(t)&&(u(t),l.current=t.map(K))}},[]),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._stateFlags.action=!1,X(a,r._names)&&r._subjects.state.next({}),f.current&&(!ge(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then(e=>{const t=m(e.errors,a),s=m(r._formState.errors,a);(s?!t&&s.type:t&&t.type)&&(t?G(r._formState.errors,a,t):xe(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))});else{const e=m(r._fields,a);e&&e._f&&fe(e,m(r._formValues,a),r._options.criteriaMode===A,r._options.shouldUseNativeValidation,!0).then(e=>!O(e)&&r._subjects.state.next({errors:Y(r._formState.errors,e,a)}))}r._subjects.watch.next({name:a,values:r._formValues}),r._names.focus&&J(r._fields,e=>!!e&&e.startsWith(r._names.focus||"")),r._names.focus="",r._proxyFormState.isValid&&r._updateValid()},[o,a,r]),s.default.useEffect(()=>(!m(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);pe(s,e,t),pe(l.current,e,t),y(s),u(s),r._updateFieldArray(a,s,pe,{argA:e,argB:t},!1)},[y,a,r]),prepend:s.default.useCallback((e,t)=>{const s=U(P(e)),n=_e(r._getFieldArray(a),s);r._names.focus=Q(a,0,t),l.current=_e(l.current,s.map(K)),y(n),u(n),r._updateFieldArray(a,n,_e,{argA:ye(e)})},[y,a,r]),append:s.default.useCallback((e,t)=>{const s=U(P(e)),n=me(r._getFieldArray(a),s);r._names.focus=Q(a,n.length-1,t),l.current=me(l.current,s.map(K)),y(n),u(n),r._updateFieldArray(a,n,me,{argA:ye(e)})},[y,a,r]),remove:s.default.useCallback(e=>{const t=be(r._getFieldArray(a),e);l.current=be(l.current,e),y(t),u(t),r._updateFieldArray(a,t,be,{argA:e})},[y,a,r]),insert:s.default.useCallback((e,t,s)=>{const n=U(P(t)),i=he(r._getFieldArray(a),e,n);r._names.focus=Q(a,e,s),l.current=he(l.current,e,n.map(K)),y(i),u(i),r._updateFieldArray(a,i,he,{argA:e,argB:ye(t)})},[y,a,r]),update:s.default.useCallback((e,t)=>{const s=P(t),n=Ve(r._getFieldArray(a),e,s);l.current=[...n].map((t,r)=>t&&r!==e?l.current[r]:K()),y(n),u([...n]),r._updateFieldArray(a,n,Ve,{argA:e,argB:s},!0,!1)},[y,a,r]),replace:s.default.useCallback(e=>{const t=U(P(e));l.current=t.map(K),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]||K()})),[o,n])}},e.useForm=function(e={}){const t=s.default.useRef(),[r,a]=s.default.useState({isDirty:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:e.defaultValues});t.current||(t.current={...Le(e),formState:r});const n=t.current.control;return n._options=e,M({subject:n._subjects.state,callback:s.default.useCallback(e=>{T(e,n._proxyFormState,!0)&&(n._formState={...n._formState,...e},a({...n._formState}))},[n])}),s.default.useEffect(()=>{n._stateFlags.mount||(n._proxyFormState.isValid&&n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()}),s.default.useEffect(()=>{r.submitCount&&n._focusError()},[n,r.submitCount]),t.current.formState=E(r,n),t.current},e.useFormContext=j,e.useFormState=N,e.useWatch=W,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookForm={},e.React)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(t),a=e=>"checkbox"===e.type,n=e=>e instanceof Date,i=e=>null==e;const o=e=>"object"==typeof e;var u=e=>!i(e)&&!Array.isArray(e)&&o(e)&&!n(e),l=e=>u(e)&&e.target?a(e.target)?e.target.checked:e.target.value:e,c=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),d=e=>Array.isArray(e)?e.filter(Boolean):[],f=e=>void 0===e,m=(e,t,r)=>{if(!t||!u(e))return r;const s=d(t.split(/[,[\].]+?/)).reduce(((e,t)=>i(e)?e:e[t]),e);return f(s)||s===e?f(e[t])?r:e[t]:s};const y="blur",g="focusout",h="change",p="onBlur",_="onChange",v="onSubmit",b="onTouched",A="all",x="max",V="min",F="maxLength",S="minLength",w="pattern",k="required",D="validate",C=s.default.createContext(null),E=()=>s.default.useContext(C);var j=(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},O=e=>u(e)&&!Object.keys(e).length,T=(e,t,r)=>{const{name:s,...a}=e;return O(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find((e=>t[e]===(!r||A)))},U=e=>Array.isArray(e)?e:[e],B=(e,t,r)=>r&&t?e===t:!e||!t||e===t||U(e).some((e=>e&&(e.startsWith(t)||t.startsWith(e))));function L(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 M(e){const t=E(),{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,L({disabled:a,next:e=>l.current&&B(d.current,e.name,i)&&T(e,c.current)&&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}),r._updateValid(),()=>{l.current=!1}}),[r]),j(o,r,c.current,!1)}var N=e=>"string"==typeof e,R=(e,t,r,s)=>N(e)?(s&&t.watch.add(e),m(r,e)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),m(r,e)))):(s&&(t.watchAll=!0),r),q="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function P(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&&!u(e))return e;if(t=r?[]:{},Array.isArray(e)||(e=>{const t=e.constructor&&e.constructor.prototype;return u(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)t[r]=P(e[r]);else t=e}return t}function W(e){const t=E(),{control:r=t.control,name:a,defaultValue:n,disabled:i,exact:o}=e||{},u=s.default.useRef(a);u.current=a,L({disabled:i,subject:r._subjects.watch,next:e=>{if(B(u.current,e.name,o)){const t=R(u.current,r._names,e.values||r._formValues);c(f(t)?n:P(t))}}});const[l,c]=s.default.useState(r._getWatch(a,n));return s.default.useEffect((()=>r._removeUnmounted())),l}function $(e){const t=E(),{name:r,control:a=t.control,shouldUnregister:n}=e,i=c(a._names.array,r),o=W({control:a,name:r,defaultValue:m(a._formValues,r,m(a._defaultValues,r,e.defaultValue)),exact:!0}),u=M({control:a,name:r}),d=s.default.useRef(a.register(r,{...e.rules,value:o}));return s.default.useEffect((()=>{const e=(e,t)=>{const r=m(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=>d.current.onChange({target:{value:l(e),name:r},type:h})),[r]),onBlur:s.default.useCallback((()=>d.current.onBlur({target:{value:m(a._formValues,r),name:r},type:y})),[r,a]),ref:e=>{const t=m(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:()=>!!m(u.errors,r)},isDirty:{enumerable:!0,get:()=>!!m(u.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!m(u.touchedFields,r)},error:{enumerable:!0,get:()=>m(u.errors,r)}})}}var I=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},H=e=>/^\w*$/.test(e),z=e=>d(e.replace(/["|']|\]/g,"").split(/\.|\[/));function G(e,t,r){let s=-1;const a=H(t)?[t]:z(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=u(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}const J=(e,t,r)=>{for(const s of r||Object.keys(e)){const r=m(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 u(s)&&J(s,t)}}};var K=()=>{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)}))},Q=(e,t,r={})=>r.shouldFocus||f(r.shouldFocus)?r.focusName||`${e}.${f(r.focusIndex)?t:r.focusIndex}.`:"",X=e=>({isOnSubmit:!e||e===v,isOnBlur:e===p,isOnChange:e===_,isOnAll:e===A,isOnTouch:e===b}),Y=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length))))),Z=(e,t,r)=>{const s=d(m(e,r));return G(s,"root",t[r]),G(e,r,s),e},ee=e=>"boolean"==typeof e,te=e=>"file"===e.type,re=e=>"function"==typeof e,se=e=>N(e)||s.default.isValidElement(e),ae=e=>"radio"===e.type,ne=e=>e instanceof RegExp;const ie={value:!1,isValid:!1},oe={value:!0,isValid:!0};var ue=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&&!f(e[0].attributes.value)?f(e[0].value)||""===e[0].value?oe:{value:e[0].value,isValid:!0}:oe:ie}return ie};const le={isValid:!1,value:null};var ce=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),le):le;function de(e,t,r="validate"){if(se(e)||Array.isArray(e)&&e.every(se)||ee(e)&&!e)return{type:r,message:se(e)?e:"",ref:t}}var fe=e=>u(e)&&!ne(e)?e:{value:e,message:""},me=async(e,t,r,s,n)=>{const{ref:o,refs:l,required:c,maxLength:d,minLength:m,min:y,max:g,pattern:h,validate:p,name:_,valueAsNumber:v,mount:b,disabled:A}=e._f;if(!b||A)return{};const C=l?l[0]:o,E=e=>{s&&C.reportValidity&&(C.setCustomValidity(ee(e)?"":e||""),C.reportValidity())},j={},T=ae(o),U=a(o),B=T||U,L=(v||te(o))&&f(o.value)&&f(t)||""===t||Array.isArray(t)&&!t.length,M=I.bind(null,_,r,j),R=(e,t,r,s=F,a=S)=>{const n=e?t:r;j[_]={type:e?s:a,message:n,ref:o,...M(e?s:a,n)}};if(n?!Array.isArray(t)||!t.length:c&&(!B&&(L||i(t))||ee(t)&&!t||U&&!ue(l).isValid||T&&!ce(l).isValid)){const{value:e,message:t}=se(c)?{value:!!c,message:c}:fe(c);if(e&&(j[_]={type:k,message:t,ref:C,...M(k,t)},!r))return E(t),j}if(!(L||i(y)&&i(g))){let e,s;const a=fe(g),n=fe(y);if(i(t)||isNaN(t)){const r=o.valueAsDate||new Date(t),i=e=>new Date((new Date).toDateString()+" "+e),u="time"==o.type,l="week"==o.type;N(a.value)&&t&&(e=u?i(t)>i(a.value):l?t>a.value:r>new Date(a.value)),N(n.value)&&t&&(s=u?i(t)<i(n.value):l?t<n.value:r<new Date(n.value))}else{const r=o.valueAsNumber||(t?+t:t);i(a.value)||(e=r>a.value),i(n.value)||(s=r<n.value)}if((e||s)&&(R(!!e,a.message,n.message,x,V),!r))return E(j[_].message),j}if((d||m)&&!L&&(N(t)||n&&Array.isArray(t))){const e=fe(d),s=fe(m),a=!i(e.value)&&t.length>e.value,n=!i(s.value)&&t.length<s.value;if((a||n)&&(R(a,e.message,s.message),!r))return E(j[_].message),j}if(h&&!L&&N(t)){const{value:e,message:s}=fe(h);if(ne(e)&&!t.match(e)&&(j[_]={type:w,message:s,ref:o,...M(w,s)},!r))return E(s),j}if(p)if(re(p)){const e=de(await p(t),C);if(e&&(j[_]={...e,...M(D,e.message)},!r))return E(e.message),j}else if(u(p)){let e={};for(const s in p){if(!O(e)&&!r)break;const a=de(await p[s](t),C,s);a&&(e={...a,...M(s,a.message)},E(a.message),r&&(j[_]=e))}if(!O(e)&&(j[_]={ref:C,...e},!r))return j}return E(!0),j};function ye(e,t){return[...e,...U(t)]}var ge=e=>Array.isArray(e)?e.map((()=>{})):void 0;function he(e,t,r){return[...e.slice(0,t),...U(r),...e.slice(t)]}var pe=(e,t,r)=>Array.isArray(e)?(f(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function _e(e,t){return[...U(t),...U(e)]}var ve=(e,t)=>f(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return d(s).length?s:[]}(e,U(t).sort(((e,t)=>e-t))),be=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function Ae(e){for(const t in e)if(!f(e[t]))return!1;return!0}function xe(e,t){const r=H(t)?[t]:z(t),s=1==r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=f(e)?s++:e[t[s++]];return e}(e,r),a=r[r.length-1];let n;s&&delete s[a];for(let t=0;t<r.slice(0,-1).length;t++){let s,a=-1;const i=r.slice(0,-(t+1)),o=i.length-1;for(t>0&&(n=e);++a<i.length;){const t=i[a];s=s?s[t]:e[t],o===a&&(u(s)&&O(s)||Array.isArray(s)&&Ae(s))&&(n?delete n[t]:delete e[t]),n=s}}return e}var Ve=(e,t,r)=>(e[t]=r,e);function Fe(){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 Se=e=>i(e)||!o(e);function we(e,t){if(Se(e)||Se(t))return e===t;if(n(e)&&n(t))return e.getTime()===t.getTime();const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const a of r){const r=e[a];if(!s.includes(a))return!1;if("ref"!==a){const e=t[a];if(n(r)&&n(e)||u(r)&&u(e)||Array.isArray(r)&&Array.isArray(e)?!we(r,e):r!==e)return!1}}return!0}var ke=e=>{const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},De=e=>"select-multiple"===e.type,Ce=e=>ke(e)&&e.isConnected,Ee=e=>{for(const t in e)if(re(e[t]))return!0;return!1};function je(e,t={}){const r=Array.isArray(e);if(u(e)||r)for(const r in e)Array.isArray(e[r])||u(e[r])&&!Ee(e[r])?(t[r]=Array.isArray(e[r])?[]:{},je(e[r],t[r])):i(e[r])||(t[r]=!0);return t}function Oe(e,t,r){const s=Array.isArray(e);if(u(e)||s)for(const s in e)Array.isArray(e[s])||u(e[s])&&!Ee(e[s])?f(t)||Se(r[s])?r[s]=Array.isArray(e[s])?je(e[s],[]):{...je(e[s])}:Oe(e[s],i(t)?{}:t[s],r[s]):we(e[s],t[s])?delete r[s]:r[s]=!0;return r}var Te=(e,t)=>Oe(e,t,je(t)),Ue=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>f(e)?e:t?""===e?NaN:e?+e:e:r&&N(e)?new Date(e):s?s(e):e;function Be(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return te(t)?t.files:ae(t)?ce(e.refs).value:De(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ue(e.refs).value:Ue(f(t.value)?e.ref.value:t.value,e)}var Le=e=>f(e)?e:ne(e)?e.source:u(e)?ne(e.value)?e.value.source:e.value:e;function Me(e,t,r){const s=m(e,r);if(s||H(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=m(t,s),i=m(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 Ne={mode:v,reValidateMode:_,shouldFocusError:!0};function Re(e={},t){let r={...Ne,...e};const s=e.resetOptions&&e.resetOptions.keepDirtyValues;let o,h={submitCount:0,isDirty:!1,isLoading:!0,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},p={},_=u(r.defaultValues)&&P(r.defaultValues)||{},v=r.shouldUnregister?{}:P(_),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:Fe(),array:Fe(),state:Fe()},w=X(r.mode),k=X(r.reValidateMode),D=r.criteriaMode===A,C=async()=>{if(F.isValid){const e=r.resolver?O((await L()).errors):await M(p,!0);e!==h.isValid&&(h.isValid=e,S.state.next({isValid:e}))}},E=e=>F.isValidating&&S.state.next({isValidating:e}),j=(e,t,r,s)=>{const a=m(p,e);if(a){const n=m(v,e,f(r)?m(_,e):r);f(n)||s&&s.defaultChecked||t?G(v,e,t?n:Be(a._f)):I(e,n),b.mount&&C()}},T=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e};if(!r||s){F.isDirty&&(i=h.isDirty,h.isDirty=o.isDirty=W(),n=i!==o.isDirty);const r=we(m(_,e),t);i=m(h.dirtyFields,e),r?xe(h.dirtyFields,e):G(h.dirtyFields,e,!0),o.dirtyFields=h.dirtyFields,n=n||F.dirtyFields&&i!==!r}if(r){const t=m(h.touchedFields,e);t||(G(h.touchedFields,e,r),o.touchedFields=h.touchedFields,n=n||F.touchedFields&&t!==r)}return n&&a&&S.state.next(o),n?o:{}},B=(t,r,s,a)=>{const n=m(h.errors,t),i=F.isValid&&ee(r)&&h.isValid!==r;var u;if(e.delayError&&s?(u=()=>((e,t)=>{G(h.errors,e,t),S.state.next({errors:h.errors})})(t,s),o=e=>{clearTimeout(V),V=window.setTimeout(u,e)},o(e.delayError)):(clearTimeout(V),o=null,s?G(h.errors,t,s):xe(h.errors,t)),(s?!we(n,s):n)||!O(a)||i){const e={...a,...i&&ee(r)?{isValid:r}:{},errors:h.errors,name:t};h={...h,...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=m(t,r);e&&G(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||x.mount,p,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 me(n,m(v,e.name),D,r.shouldUseNativeValidation,a);if(i[e.name]&&(s.valid=!1,t))break;!t&&(m(i,e.name)?a?Z(h.errors,i,e.name):G(h.errors,e.name,i[e.name]):xe(h.errors,e.name))}a&&await M(a,t,s)}}return s.valid},W=(e,t)=>(e&&t&&G(v,e,t),!we(se(),_)),$=(e,t,r)=>R(e,x,{...b.mount?v:f(t)?_:N(e)?{[e]:t}:t},r),I=(e,t,r={})=>{const s=m(p,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&G(v,e,Ue(t,r)),n=q&&ke(r.ref)&&i(t)?"":t,De(r.ref)?[...r.ref.options].forEach((e=>e.selected=n.includes(e.value))):r.refs?a(r.ref)?r.refs.length>1?r.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(n)?!!n.find((t=>t===e.value)):n===e.value))):r.refs[0]&&(r.refs[0].checked=!!n):r.refs.forEach((e=>e.checked=e.value===n)):te(r.ref)?r.ref.value="":(r.ref.value=n,r.ref.type||S.watch.next({name:e})))}(r.shouldDirty||r.shouldTouch)&&T(e,n,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&Q(e)},H=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,o=m(p,i);!x.array.has(e)&&Se(a)&&(!o||o._f)||n(a)?I(i,a,r):H(i,a,r)}},z=(e,r,s={})=>{const a=m(p,e),n=x.array.has(e),o=P(r);G(v,e,o),n?(S.array.next({name:e,values:v}),(F.isDirty||F.dirtyFields)&&s.shouldDirty&&(h.dirtyFields=Te(_,v),S.state.next({name:e,dirtyFields:h.dirtyFields,isDirty:W(e,o)}))):!a||a._f||i(o)?I(e,o,s):H(e,o,s),Y(e,x)&&S.state.next({}),S.watch.next({name:e}),!b.mount&&t()},K=async e=>{const t=e.target;let s=t.name;const a=m(p,s),n=()=>t.type?Be(a._f):l(e);if(a){let t,u;const l=n(),c=e.type===y||e.type===g,d=!((i=a._f).mount&&(i.required||i.min||i.max||i.maxLength||i.minLength||i.pattern||i.validate)||r.resolver||m(h.errors,s)||a._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))(c,m(h.touchedFields,s),h.isSubmitted,k,w),f=Y(s,x,c);G(v,s,l),c?(a._f.onBlur&&a._f.onBlur(e),o&&o(0)):a._f.onChange&&a._f.onChange(e);const _=T(s,l,c,!1),b=!O(_)||f;if(!c&&S.watch.next({name:s,type:e.type}),d)return F.isValid&&C(),b&&S.state.next({name:s,...f?{}:_});if(!c&&f&&S.state.next({}),E(!0),r.resolver){const{errors:e}=await L([s]),r=Me(h.errors,p,s),a=Me(e,p,r.name||s);t=a.error,s=a.name,u=O(e)}else t=(await me(a,m(v,s),D,r.shouldUseNativeValidation))[s],t?u=!1:F.isValid&&(u=await M(p,!0));Se(l)&&n()!==l?E(!1):(a._f.deps&&Q(a._f.deps),B(s,u,t,_))}var i},Q=async(e,t={})=>{let s,a;const n=U(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=m(t,r);e?G(h.errors,r,e):xe(h.errors,r)}else h.errors=t;return t})(f(e)?e:n);s=O(t),a=e?!n.some((e=>m(t,e))):s}else e?(a=(await Promise.all(n.map((async e=>{const t=m(p,e);return await M(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||h.isValid)&&C()):a=s=await M(p);return S.state.next({...!N(e)||F.isValid&&s!==h.isValid?{}:{name:e},...r.resolver||!e?{isValid:s}:{},errors:h.errors,isValidating:!1}),t.shouldFocus&&!a&&J(p,(e=>e&&m(h.errors,e)),e?n:x.mount),a},se=e=>{const t={..._,...b.mount?v:{}};return f(e)?t:N(e)?m(t,e):e.map((e=>m(t,e)))},ne=(e,t)=>({invalid:!!m((t||h).errors,e),isDirty:!!m((t||h).dirtyFields,e),isTouched:!!m((t||h).touchedFields,e),error:m((t||h).errors,e)}),ie=(e,t={})=>{for(const s of e?U(e):x.mount)x.mount.delete(s),x.array.delete(s),m(p,s)&&(t.keepValue||(xe(p,s),xe(v,s)),!t.keepError&&xe(h.errors,s),!t.keepDirty&&xe(h.dirtyFields,s),!t.keepTouched&&xe(h.touchedFields,s),!r.shouldUnregister&&!t.keepDefaultValue&&xe(_,s));S.watch.next({}),S.state.next({...h,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&C()},oe=(e,t={})=>{let s=m(p,e);const n=ee(t.disabled);return G(p,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),x.mount.add(e),s?n&&G(v,e,t.disabled?void 0:m(v,e,Be(s._f))):j(e,!0,t.value),{...n?{disabled:t.disabled}:{},...r.shouldUseNativeValidation?{required:!!t.required,min:Le(t.min),max:Le(t.max),minLength:Le(t.minLength),maxLength:Le(t.maxLength),pattern:Le(t.pattern)}:{},name:e,onChange:K,onBlur:K,ref:n=>{if(n){oe(e,t),s=m(p,e);const r=f(n.value)&&n.querySelectorAll&&n.querySelectorAll("input,select,textarea")[0]||n,i=(e=>ae(e)||a(e))(r),o=s._f.refs||[];if(i?o.find((e=>e===r)):r===s._f.ref)return;G(p,e,{_f:{...s._f,...i?{refs:[...o.filter(Ce),r,...Array.isArray(m(_,e))?[{}]:[]],ref:{type:r.type,name:e}}:{ref:r}}}),j(e,!1,void 0,r)}else s=m(p,e,{}),s._f&&(s._f.mount=!1),(r.shouldUnregister||t.shouldUnregister)&&(!c(x.array,e)||!b.action)&&x.unMount.add(e)}}},ue=()=>r.shouldFocusError&&J(p,(e=>e&&m(h.errors,e)),x.mount),le=(r,a={})=>{const n=r||_,i=P(n),o=r&&!O(r)?i:_;if(a.keepDefaultValues||(_=n),!a.keepValues){if(a.keepDirtyValues||s)for(const e of x.mount)m(h.dirtyFields,e)?G(o,e,m(v,e)):z(e,m(o,e));else{if(q&&f(r))for(const e of x.mount){const t=m(p,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(ke(e)){const t=e.closest("form");if(t){t.reset();break}}}}p={}}v=e.shouldUnregister?a.keepDefaultValues?P(_):{}: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?h.submitCount:0,isDirty:a.keepDirty||a.keepDirtyValues?h.isDirty:!(!a.keepDefaultValues||we(r,_)),isSubmitted:!!a.keepIsSubmitted&&h.isSubmitted,dirtyFields:a.keepDirty||a.keepDirtyValues?h.dirtyFields:a.keepDefaultValues&&r?Te(_,r):{},touchedFields:a.keepTouched?h.touchedFields:{},errors:a.keepErrors?h.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},ce=(e,t)=>le(re(e)?e(v):e,t);return re(r.defaultValues)&&r.defaultValues().then((e=>{ce(e,r.resetOptions),S.state.next({isLoading:!1})})),{control:{register:oe,unregister:ie,getFieldState:ne,_executeSchema:L,_focusError:ue,_getWatch:$,_getDirty:W,_updateValid:C,_removeUnmounted:()=>{for(const e of x.unMount){const t=m(p,e);t&&(t._f.refs?t._f.refs.every((e=>!Ce(e))):!Ce(t._f.ref))&&ie(e)}x.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(b.action=!0,n&&Array.isArray(m(p,e))){const t=r(m(p,e),s.argA,s.argB);a&&G(p,e,t)}if(n&&Array.isArray(m(h.errors,e))){const t=r(m(h.errors,e),s.argA,s.argB);a&&G(h.errors,e,t),((e,t)=>{!d(m(e,t)).length&&xe(e,t)})(h.errors,e)}if(F.touchedFields&&n&&Array.isArray(m(h.touchedFields,e))){const t=r(m(h.touchedFields,e),s.argA,s.argB);a&&G(h.touchedFields,e,t)}F.dirtyFields&&(h.dirtyFields=Te(_,v)),S.state.next({name:e,isDirty:W(e,t),dirtyFields:h.dirtyFields,errors:h.errors,isValid:h.isValid})}else G(v,e,t)},_getFieldArray:t=>d(m(b.mount?v:_,t,e.shouldUnregister?m(_,t,[]):[])),_reset:le,_subjects:S,_proxyFormState:F,get _fields(){return p},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 h},set _formState(e){h=e},get _options(){return r},set _options(e){r={...r,...e}}},trigger:Q,register:oe,handleSubmit:(e,t)=>async s=>{s&&(s.preventDefault&&s.preventDefault(),s.persist&&s.persist());let a=!0,n=P(v);S.state.next({isSubmitting:!0});try{if(r.resolver){const{errors:e,values:t}=await L();h.errors=e,n=t}else await M(p);O(h.errors)?(S.state.next({errors:{},isSubmitting:!0}),await e(n,s)):(t&&await t({...h.errors},s),ue())}catch(e){throw a=!1,e}finally{h.isSubmitted=!0,S.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:O(h.errors)&&a,submitCount:h.submitCount+1,errors:h.errors})}},watch:(e,t)=>re(e)?S.watch.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:z,getValues:se,reset:ce,resetField:(e,t={})=>{m(p,e)&&(f(t.defaultValue)?z(e,m(_,e)):(z(e,t.defaultValue),G(_,e,t.defaultValue)),t.keepTouched||xe(h.touchedFields,e),t.keepDirty||(xe(h.dirtyFields,e),h.isDirty=t.defaultValue?W(e,m(_,e)):W()),t.keepError||(xe(h.errors,e),F.isValid&&C()),S.state.next({...h}))},clearErrors:e=>{e?U(e).forEach((e=>xe(h.errors,e))):h.errors={},S.state.next({errors:h.errors})},unregister:ie,setError:(e,t,r)=>{const s=(m(p,e,{_f:{}})._f||{}).ref;G(h.errors,e,{...t,ref:s}),S.state.next({name:e,errors:h.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},setFocus:(e,t={})=>{const r=m(p,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ne}}e.Controller=e=>e.render($(e)),e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(C.Provider,{value:r},t)},e.appendErrors=I,e.get=m,e.set=G,e.useController=$,e.useFieldArray=function(e){const t=E(),{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(K)),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),L({next:({values:e,name:t})=>{if(t===d.current||!t){const t=m(e,d.current);Array.isArray(t)&&(u(t),l.current=t.map(K))}},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._stateFlags.action=!1,Y(a,r._names)&&r._subjects.state.next({}),f.current&&(!X(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=m(e.errors,a),s=m(r._formState.errors,a);(s?!t&&s.type:t&&t.type)&&(t?G(r._formState.errors,a,t):xe(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=m(r._fields,a);e&&e._f&&me(e,m(r._formValues,a),r._options.criteriaMode===A,r._options.shouldUseNativeValidation,!0).then((e=>!O(e)&&r._subjects.state.next({errors:Z(r._formState.errors,e,a)})))}r._subjects.watch.next({name:a,values:r._formValues}),r._names.focus&&J(r._fields,(e=>!!e&&e.startsWith(r._names.focus||""))),r._names.focus="",r._proxyFormState.isValid&&r._updateValid()}),[o,a,r]),s.default.useEffect((()=>(!m(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);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]),move:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);pe(s,e,t),pe(l.current,e,t),y(s),u(s),r._updateFieldArray(a,s,pe,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=U(P(e)),n=_e(r._getFieldArray(a),s);r._names.focus=Q(a,0,t),l.current=_e(l.current,s.map(K)),y(n),u(n),r._updateFieldArray(a,n,_e,{argA:ge(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=U(P(e)),n=ye(r._getFieldArray(a),s);r._names.focus=Q(a,n.length-1,t),l.current=ye(l.current,s.map(K)),y(n),u(n),r._updateFieldArray(a,n,ye,{argA:ge(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=ve(r._getFieldArray(a),e);l.current=ve(l.current,e),y(t),u(t),r._updateFieldArray(a,t,ve,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=U(P(t)),i=he(r._getFieldArray(a),e,n);r._names.focus=Q(a,e,s),l.current=he(l.current,e,n.map(K)),y(i),u(i),r._updateFieldArray(a,i,he,{argA:e,argB:ge(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=P(t),n=Ve(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:K())),y(n),u([...n]),r._updateFieldArray(a,n,Ve,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=U(P(e));l.current=t.map(K),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]||K()})))),[o,n])}},e.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:re(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Re(e,(()=>a((e=>({...e}))))),formState:r});const n=t.current.control;return n._options=e,L({subject:n._subjects.state,next:e=>{T(e,n._proxyFormState,!0)&&(n._formState={...n._formState,...e},a({...n._formState}))}}),s.default.useEffect((()=>{n._stateFlags.mount||(n._proxyFormState.isValid&&n._updateValid(),n._stateFlags.mount=!0),n._stateFlags.watch&&(n._stateFlags.watch=!1,n._subjects.state.next({})),n._removeUnmounted()})),s.default.useEffect((()=>{e.values&&!we(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=j(r,n),t.current},e.useFormContext=E,e.useFormState=M,e.useWatch=W,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,3 +0,26 @@ | ||
import { FieldValues, UseFormProps, UseFormReturn } from '../types'; | ||
export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any>(props?: UseFormProps<TFieldValues, TContext>): Omit<UseFormReturn<TFieldValues, TContext>, 'formState'>; | ||
import { DeepPartial, FieldValues, UseFormReturn } from '../types'; | ||
export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any>(props: Partial<{ | ||
mode: keyof import("../types").ValidationMode; | ||
reValidateMode: "onSubmit" | "onChange" | "onBlur"; | ||
defaultValues: DeepPartial<TFieldValues> | ((payload?: unknown) => Promise<TFieldValues>); | ||
values: TFieldValues; | ||
resetOptions: Partial<{ | ||
keepDirtyValues: boolean; | ||
keepErrors: boolean; | ||
keepDirty: boolean; | ||
keepValues: boolean; | ||
keepDefaultValues: boolean; | ||
keepIsSubmitted: boolean; | ||
keepTouched: boolean; | ||
keepIsValid: boolean; | ||
keepSubmitCount: boolean; | ||
}> | undefined; | ||
resolver: import("../types").Resolver<TFieldValues, TContext>; | ||
context: TContext; | ||
shouldFocusError: boolean; | ||
shouldUnregister: boolean; | ||
shouldUseNativeValidation: boolean; | ||
criteriaMode: import("../types").CriteriaMode; | ||
delayError: number; | ||
}> | undefined, flushRootRender: () => void): Omit<UseFormReturn<TFieldValues, TContext>, 'formState'>; | ||
//# sourceMappingURL=createFormControl.d.ts.map |
import { FieldError, FieldErrors, FieldValues, InternalFieldName } from '../types'; | ||
declare const _default: <T extends FieldValues = FieldValues>(errors: Partial<import("../types").FieldErrorsImpl<import("../types").DeepRequired<T>>>, error: Partial<Record<string, FieldError>>, name: InternalFieldName) => Partial<import("../types").FieldErrorsImpl<import("../types").DeepRequired<T>>>; | ||
declare const _default: <T extends FieldValues = FieldValues>(errors: Partial<import("../types").FieldErrorsImpl<import("../types").DeepRequired<import("../types").UnPackAsyncDefaultValues<T>>>>, error: Partial<Record<string, FieldError>>, name: InternalFieldName) => Partial<import("../types").FieldErrorsImpl<import("../types").DeepRequired<import("../types").UnPackAsyncDefaultValues<T>>>>; | ||
export default _default; | ||
//# sourceMappingURL=updateFieldArrayRootError.d.ts.map |
import { FieldValues, InternalFieldName, Ref } from './fields'; | ||
import { BrowserNativeObject, IsAny, LiteralUnion, Merge } from './utils'; | ||
import { BrowserNativeObject, IsAny, LiteralUnion, Merge, UnPackAsyncDefaultValues } from './utils'; | ||
import { RegisterOptions, ValidateResult } from './validator'; | ||
@@ -28,4 +28,4 @@ export type Message = string; | ||
}; | ||
export type FieldErrors<T extends FieldValues = FieldValues> = Partial<FieldValues extends IsAny<FieldValues> ? any : FieldErrorsImpl<DeepRequired<T>>>; | ||
export type FieldErrors<T extends FieldValues = FieldValues> = Partial<FieldValues extends IsAny<FieldValues> ? any : FieldErrorsImpl<DeepRequired<UnPackAsyncDefaultValues<T>>>>; | ||
export type InternalFieldErrors = Partial<Record<InternalFieldName, FieldError>>; | ||
//# sourceMappingURL=errors.d.ts.map |
@@ -9,3 +9,3 @@ import React from 'react'; | ||
import { Resolver } from './resolvers'; | ||
import { DeepMap, DeepPartial, Noop } from './utils'; | ||
import { DeepMap, DeepPartial, Noop, UnPackAsyncDefaultValues } from './utils'; | ||
import { RegisterOptions } from './validator'; | ||
@@ -51,6 +51,9 @@ declare const $NestedValue: unique symbol; | ||
export type DelayCallback = (wait: number) => void; | ||
export type UseFormProps<TFieldValues extends FieldValues = FieldValues, TContext = any> = Partial<{ | ||
type AsyncDefaultValues<TFieldValues> = (payload?: unknown) => Promise<TFieldValues>; | ||
export type UseFormProps<TFieldValues extends UnPackAsyncDefaultValues<FieldValues> = UnPackAsyncDefaultValues<FieldValues>, TContext = any> = Partial<{ | ||
mode: Mode; | ||
reValidateMode: Exclude<Mode, 'onTouched' | 'all'>; | ||
defaultValues: DefaultValues<TFieldValues>; | ||
defaultValues: DefaultValues<TFieldValues> | AsyncDefaultValues<TFieldValues>; | ||
values: TFieldValues; | ||
resetOptions: Parameters<UseFormReset<TFieldValues>>[1]; | ||
resolver: Resolver<TFieldValues, TContext>; | ||
@@ -78,2 +81,3 @@ context: TContext; | ||
isDirty: boolean; | ||
isLoading: boolean; | ||
isSubmitted: boolean; | ||
@@ -85,5 +89,5 @@ isSubmitSuccessful: boolean; | ||
submitCount: number; | ||
defaultValues?: Readonly<DeepPartial<TFieldValues>> | TFieldValues; | ||
dirtyFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>; | ||
touchedFields: Partial<Readonly<FieldNamesMarkedBoolean<TFieldValues>>>; | ||
defaultValues?: UnPackAsyncDefaultValues<TFieldValues> | undefined | Readonly<DeepPartial<TFieldValues>>; | ||
dirtyFields: Partial<Readonly<FieldNamesMarkedBoolean<UnPackAsyncDefaultValues<TFieldValues>>>>; | ||
touchedFields: Partial<Readonly<FieldNamesMarkedBoolean<UnPackAsyncDefaultValues<TFieldValues>>>>; | ||
errors: FieldErrors<TFieldValues>; | ||
@@ -576,2 +580,3 @@ }; | ||
}; | ||
_reset: UseFormReset<TFieldValues>; | ||
_options: UseFormProps<TFieldValues, TContext>; | ||
@@ -598,3 +603,2 @@ _getDirty: GetIsDirty; | ||
type?: EventType; | ||
value?: unknown; | ||
}) => void; | ||
@@ -601,0 +605,0 @@ export type UseFormReturn<TFieldValues extends FieldValues = FieldValues, TContext = any> = { |
import { FieldValues } from '../fields'; | ||
import { BrowserNativeObject, Primitive } from '../utils'; | ||
import { BrowserNativeObject, Primitive, UnPackAsyncDefaultValues } from '../utils'; | ||
import { ArrayKey, IsTuple, TupleKeys } from './common'; | ||
@@ -25,3 +25,3 @@ /** | ||
*/ | ||
export type FieldPath<TFieldValues extends FieldValues> = Path<TFieldValues>; | ||
export type FieldPath<TFieldValues extends FieldValues> = Path<UnPackAsyncDefaultValues<TFieldValues>>; | ||
/** | ||
@@ -49,3 +49,3 @@ * Helper type for recursively constructing paths through a type. | ||
*/ | ||
export type FieldArrayPath<TFieldValues extends FieldValues> = ArrayPath<TFieldValues>; | ||
export type FieldArrayPath<TFieldValues extends FieldValues> = ArrayPath<UnPackAsyncDefaultValues<TFieldValues>>; | ||
/** | ||
@@ -65,7 +65,7 @@ * Type to evaluate the type which the given path points to. | ||
*/ | ||
export type FieldPathValue<TFieldValues extends FieldValues, TFieldPath extends FieldPath<TFieldValues>> = PathValue<TFieldValues, TFieldPath>; | ||
export type FieldPathValue<TFieldValues extends FieldValues, TFieldPath extends FieldPath<TFieldValues>> = PathValue<UnPackAsyncDefaultValues<TFieldValues>, TFieldPath>; | ||
/** | ||
* See {@link PathValue} | ||
*/ | ||
export type FieldArrayPathValue<TFieldValues extends FieldValues, TFieldArrayPath extends FieldArrayPath<TFieldValues>> = PathValue<TFieldValues, TFieldArrayPath>; | ||
export type FieldArrayPathValue<TFieldValues extends FieldValues, TFieldArrayPath extends FieldArrayPath<TFieldValues>> = PathValue<UnPackAsyncDefaultValues<TFieldValues>, TFieldArrayPath>; | ||
/** | ||
@@ -72,0 +72,0 @@ * Type to evaluate the type which the given paths point to. |
@@ -29,2 +29,3 @@ import { NestedValue } from './form'; | ||
}; | ||
export type UnPackAsyncDefaultValues<TFieldValues> = TFieldValues extends () => Promise<infer U> ? U : TFieldValues; | ||
/** | ||
@@ -31,0 +32,0 @@ * Checks whether the type is any |
@@ -10,3 +10,3 @@ import { Message } from './errors'; | ||
}; | ||
export type ValidateResult = Message | Message[] | boolean | undefined; | ||
export type ValidateResult = Message | boolean | undefined; | ||
export type Validate<TFieldValue> = (value: TFieldValue) => ValidateResult | Promise<ValidateResult>; | ||
@@ -13,0 +13,0 @@ export type RegisterOptions<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Partial<{ |
@@ -0,1 +1,2 @@ | ||
/// <reference types="react" /> | ||
import { FieldValues, FormProviderProps, UseFormReturn } from './types'; | ||
@@ -2,0 +3,0 @@ /** |
@@ -5,3 +5,3 @@ import { Subject } from './utils/createSubject'; | ||
subject: Subject<T>; | ||
callback: (value: T) => void; | ||
next: (value: T) => void; | ||
}; | ||
@@ -8,0 +8,0 @@ export declare function useSubscribe<T>(props: Props<T>): void; |
{ | ||
"name": "react-hook-form", | ||
"description": "Performant, flexible and extensible forms library for React Hooks", | ||
"version": "7.40.0", | ||
"version": "7.41.0", | ||
"main": "dist/index.cjs.js", | ||
@@ -28,4 +28,5 @@ "module": "dist/index.esm.mjs", | ||
"clean": "rimraf dist", | ||
"prebuild": "yarn clean", | ||
"build": "yarn build:modern", | ||
"prebuild": "pnpm clean", | ||
"build": "pnpm build:modern", | ||
"build:watch": "pnpm build:modern -w", | ||
"postbuild": "rimraf dist/__tests__ && node ./scripts/rollup/assert-esm-exports.mjs && node ./scripts/rollup/assert-cjs-exports.cjs", | ||
@@ -36,22 +37,19 @@ "build:modern": "rollup -c ./scripts/rollup/rollup.config.js", | ||
"lint": "eslint '**/*.{js,ts,tsx}'", | ||
"lint:fix": "yarn lint -- --fix", | ||
"lint:fix": "pnpm lint --fix", | ||
"type": "tsc --noEmit", | ||
"coverage": "jest --coverage --coverageReporters=text-lcov", | ||
"jest-preview": "jest-preview", | ||
"test": "jest --config ./scripts/jest/jest.config.js", | ||
"test:coverage": "yarn test -- --coverage", | ||
"test:watch": "yarn test -- --onlyChanged --watch", | ||
"test:web": "TEST_ENV=web yarn test", | ||
"test:server": "TEST_ENV=server yarn test", | ||
"test:native": "TEST_ENV=native yarn test", | ||
"tsd": "tsd src/__typetest__", | ||
"test:coverage": "pnpm test -- --coverage", | ||
"test:watch": "pnpm test -- --onlyChanged --watch", | ||
"test:web": "TEST_ENV=web pnpm test", | ||
"test:type": "tsd src/__typetest__", | ||
"e2e": "cypress run", | ||
"e2e:watch": "cypress open", | ||
"api-extractor": "api-extractor run --local", | ||
"api-extractor:build": "yarn build:esm && yarn api-extractor", | ||
"api-extractor:build": "pnpm build:esm && pnpm api-extractor", | ||
"api-extractor:ci": "node scripts/apiExtractor.js", | ||
"postversion": "git push && git push origin v$npm_package_version", | ||
"prepublishOnly": "yarn && yarn lint:fix && yarn type && yarn test && yarn build", | ||
"bundlewatch": "yarn build:modern && bundlewatch", | ||
"start": "yarn build:esm && yarn link && yarn --cwd node_modules/react link && yarn --cwd ./app link react react-hook-form && yarn --cwd ./app && yarn --cwd ./app run dev" | ||
"prepublishOnly": "pnpm install && pnpm lint:fix && pnpm type && pnpm test && pnpm build", | ||
"bundlewatch": "pnpm build:modern && bundlewatch", | ||
"start": "pnpm build:esm && pnpm --dir ./app install && pnpm --dir ./app run dev" | ||
}, | ||
@@ -86,2 +84,4 @@ "keywords": [ | ||
"@types/react": "^18.0.21", | ||
"@types/react-dom": "^18.0.9", | ||
"@types/testing-library__jest-dom": "^5.14.5", | ||
"@typescript-eslint/eslint-plugin": "^5.39.0", | ||
@@ -130,4 +130,4 @@ "@typescript-eslint/parser": "^5.39.0", | ||
"*.{js,ts,tsx}": [ | ||
"yarn lint:fix", | ||
"yarn prettier:fix" | ||
"pnpm lint:fix", | ||
"pnpm prettier:fix" | ||
], | ||
@@ -150,3 +150,3 @@ "*.{md,json,yml}": [ | ||
}, | ||
"packageManager": "yarn@1.22.15" | ||
"packageManager": "pnpm@7.18.0" | ||
} |
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
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
819765
295
4666
41