react-hook-form 6.9.2 → 6.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=e=>e instanceof HTMLElement;const t="blur",n="change",s="input",c="onBlur",u="onChange",i="onSubmit",a="onTouched",o="all",l="max",f="min",d="maxLength",g="minLength",b="pattern",m="required",h="validate";var y=e=>null==e,v=e=>Array.isArray(e);const p=e=>"object"==typeof e;var O=e=>!y(e)&&!v(e)&&p(e)&&!(e instanceof Date),j=e=>!v(e)&&(/^\w*$/.test(e)||!/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/.test(e)),R=e=>{const r=[];return e.replace(/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,(e,t,n,s)=>{r.push(n?s.replace(/\\(\\)?/g,"$1"):t||e)}),r};function F(e,r,t){let n=-1;const s=j(r)?[r]:R(r),c=s.length,u=c-1;for(;++n<c;){const r=s[n];let c=t;if(n!==u){const t=e[r];c=O(t)||v(t)?t:isNaN(+s[n+1])?{}:[]}e[r]=c,e=e[r]}return e}var V=e=>Object.entries(e).reduce((e,[r,t])=>j(r)?Object.assign(Object.assign({},e),{[r]:t}):(F(e,r,t),e),{}),x=e=>void 0===e,C=e=>e.filter(Boolean),S=(e,r,t)=>{const n=C(r.split(/[,[\].]+?/)).reduce((e,r)=>y(e)?e:e[r],e);return x(n)||n===e?x(e[r])?t:e[r]:n},k=(e,c)=>{r(e)&&e.removeEventListener&&(e.removeEventListener(s,c),e.removeEventListener(n,c),e.removeEventListener(t,c))};const w={isValid:!1,value:""};var E=e=>v(e)?e.reduce((e,r)=>r&&r.ref.checked?{isValid:!0,value:r.ref.value}:e,w):w,D=e=>"radio"===e.type,A=e=>"file"===e.type,B=e=>"checkbox"===e.type,W=e=>"select-multiple"===e.type;const L={value:!1,isValid:!1},N={value:!0,isValid:!0};var T=e=>{if(v(e)){if(e.length>1){const r=e.filter(e=>e&&e.ref.checked).map(({ref:{value:e}})=>e);return{value:r,isValid:!!r.length}}const{checked:r,value:t,attributes:n}=e[0].ref;return r?n&&!x(n.value)?x(t)||""===t?N:{value:t,isValid:!0}:N:L}return L};function M(e,r,t,n){const s=e.current[r];if(s){const{ref:{value:e,disabled:r},ref:t}=s;if(r&&n)return;return A(t)?t.files:D(t)?E(s.options).value:W(t)?(c=t.options,[...c].filter(({selected:e})=>e).map(({value:e})=>e)):B(t)?T(s.options).value:e}var c;if(t)return S(t.current,r)}function P(e){return!e||e instanceof HTMLElement&&e.nodeType!==Node.DOCUMENT_NODE&&P(e.parentNode)}var $=e=>O(e)&&!Object.keys(e).length,I=e=>"boolean"==typeof e;function H(e,r){const t=j(r)?[r]:R(r),n=1==t.length?e:function(e,r){const t=r.slice(0,-1).length;let n=0;for(;n<t;)e=x(e)?n++:e[r[n++]];return e}(e,t),s=t[t.length-1];let c=void 0;n&&delete n[s];for(let r=0;r<t.slice(0,-1).length;r++){let n=-1,s=void 0;const u=t.slice(0,-(r+1)),i=u.length-1;for(r>0&&(c=e);++n<u.length;){const r=u[n];s=s?s[r]:e[r],i===n&&(O(s)&&$(s)||v(s)&&!s.filter(e=>O(e)&&!$(e)||I(e)).length)&&(c?delete c[r]:delete e[r]),c=s}}return e}const U=(e,r)=>e&&e.ref===r;var q=e=>"string"==typeof e,_=e=>y(e)||!p(e);var z=(e,r,t,n)=>{const s={};for(const r in e.current)(x(n)||(q(n)?r.startsWith(n):v(n)&&n.find(e=>r.startsWith(e))))&&(s[r]=M(e,r,void 0,t));return function e(r,t){if(_(r)||_(t))return t;for(const n in t){const s=r[n],c=t[n];try{O(s)&&O(c)||v(s)&&v(c)?r[n]=e(s,c):r[n]=c}catch(e){}}return r}(V(Object.assign({},(r||{}).current||{})),V(s))};function G(e=[],r=[],t){const n=Object.keys(e),s=Object.keys(r);if(n.length!==s.length)return!1;for(const s of n)if(!t||!["ref","context"].includes(s)){const n=e[s],c=r[s];if((O(n)||v(n))&&(O(c)||v(c))?!G(n,c,t):n!==c)return!1}return!0}var J=e=>e instanceof RegExp;var K=e=>{return O(r=e)&&!J(r)?e:{value:e,message:""};var r},Q=e=>"function"==typeof e,X=r=>q(r)||O(r)&&e.isValidElement(r);function Y(e,r,t="validate"){if(X(e)||I(e)&&!e)return{type:t,message:X(e)?e:"",ref:r}}var Z=(e,r,t,n,s)=>{if(r){const r=t[e];return Object.assign(Object.assign({},r),{types:Object.assign(Object.assign({},r&&r.types?r.types:{}),{[n]:s||!0})})}return{}},ee=async(e,r,{ref:t,ref:{type:n,value:s},options:c,required:u,maxLength:i,minLength:a,min:o,max:v,pattern:p,validate:j},R)=>{const F=e.current,V=t.name,x={},C=D(t),S=B(t),k=C||S,w=""===s,A=Z.bind(null,V,r,x),W=(e,r,n,s=d,c=g)=>{const u=e?r:n;x[V]=Object.assign({type:e?s:c,message:u,ref:t},A(e?s:c,u))};if(u&&(!C&&!S&&(w||y(s))||I(s)&&!s||S&&!T(c).isValid||C&&!E(c).isValid)){const{value:e,message:n}=X(u)?{value:!!u,message:u}:K(u);if(e&&(x[V]=Object.assign({type:m,message:n,ref:k?((F[V].options||[])[0]||{}).ref:t},A(m,n)),!r))return x}if(!y(o)||!y(v)){let e,c;const{value:u,message:i}=K(v),{value:a,message:d}=K(o);if("number"===n||!n&&!isNaN(s)){const r=t.valueAsNumber||parseFloat(s);y(u)||(e=r>u),y(a)||(c=r<a)}else{const r=t.valueAsDate||new Date(s);q(u)&&(e=r>new Date(u)),q(a)&&(c=r<new Date(a))}if((e||c)&&(W(!!e,i,d,l,f),!r))return x}if(q(s)&&!w&&(i||a)){const{value:e,message:t}=K(i),{value:n,message:c}=K(a),u=s.toString().length,o=!y(e)&&u>e,l=!y(n)&&u<n;if((o||l)&&(W(!!o,t,c),!r))return x}if(p&&!w){const{value:e,message:n}=K(p);if(J(e)&&!e.test(s)&&(x[V]=Object.assign({type:b,message:n,ref:t},A(b,n)),!r))return x}if(j){const n=M(e,V,R),s=k&&c?c[0].ref:t;if(Q(j)){const e=Y(await j(n),s);if(e&&(x[V]=Object.assign(Object.assign({},e),A(h,e.message)),!r))return x}else if(O(j)){let e={};for(const[t,c]of Object.entries(j)){if(!$(e)&&!r)break;const u=Y(await c(n),s,t);u&&(e=Object.assign(Object.assign({},u),A(t,u.message)),r&&(x[V]=e))}if(!$(e)&&(x[V]=Object.assign({ref:s},e),!r))return x}}return x};const re=(e,r)=>Object.entries(r).map(([t,n])=>((r,t,n)=>{const s=n?`${e}.${r}`:`${e}[${r}]`;return _(t)?s:re(s,t)})(t,n,O(r))).flat(1/0);var te=(e,r,t,n,s)=>{let c;return t.add(r),$(e)?c=void 0:(c=S(e,r),(O(c)||v(c))&&re(r,c).forEach(e=>t.add(e))),x(c)?s?n:S(n,r):c},ne=({isOnBlur:e,isOnChange:r,isOnTouch:t,isTouched:n,isReValidateOnBlur:s,isReValidateOnChange:c,isBlurEvent:u,isSubmitted:i,isOnAll:a})=>!a&&(!i&&t?!(n||u):(i?s:e)?!u:!(i?c:r)||u),se=e=>e.substring(0,e.indexOf("["));const ce=(e,r)=>RegExp(`^${r}[\\d+]`.replace(/\[/g,"\\[").replace(/\]/g,"\\]")).test(e);var ue=(e,r)=>[...e].some(e=>ce(r,e));var ie=e=>({isOnSubmit:!e||e===i,isOnBlur:e===c,isOnChange:e===u,isOnAll:e===o,isOnTouch:e===a}),ae=e=>D(e)||B(e);const oe="undefined"==typeof window,le="undefined"!=typeof document&&!oe&&!x(window.HTMLElement),fe=le?"Proxy"in window:"undefined"!=typeof Proxy;function de(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(t[n[s]]=e[n[s]])}return t}const ge=e.createContext(null);ge.displayName="RHFContext";const be=()=>e.useContext(ge);var me=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){const t=(16*Math.random()+e)%16|0;return("x"==r?t:3&t|8).toString(16)}))};var he=(e,r)=>x(r)?[]:v(r)?function(e,r){let t=-1;for(;++t<e.length;)r.indexOf(t)>=0&&delete e[t];return C(e)}(e,r):((e,r)=>[...e.slice(0,r),...e.slice(r+1)])(e,r),ye=(e,r,t)=>v(e)?(x(e[t])&&(e[t]=void 0),e.splice(t,0,e.splice(r,1)[0]),e):[],ve=(e,r,t)=>{const n=[e[t],e[r]];e[r]=n[0],e[t]=n[1]};function pe(e,r){return[...v(r)?r:[r||void 0],...e]}function Oe(e,r,t){return[...e.slice(0,r),...v(t)?t:[t||void 0],...e.slice(r)]}var je=e=>v(e)?Array(e.length).fill(void 0):void 0;function Re(e){if(O(e)){const r={};for(const t in e)r[t]=!0;return[r]}return[!0]}var Fe=e=>(v(e)?e:[e]).map(Re).flat();const Ve=(e,r)=>Object.assign({[r]:me()},e),xe=(e,r)=>(v(e)?e:[]).map(e=>Ve(e,r));exports.Controller=r=>{var{name:t,rules:n,as:s,render:c,defaultValue:u,control:i,onFocus:a}=r,o=de(r,["name","rules","as","render","defaultValue","control","onFocus"]);const l=be(),{defaultValuesRef:f,setValue:d,register:g,unregister:b,trigger:m,mode:h,reValidateMode:{isReValidateOnBlur:y,isReValidateOnChange:v},formStateRef:{current:{isSubmitted:p,touched:j}},updateFormState:R,readFormStateRef:V,fieldsRef:C,fieldArrayNamesRef:k,shallowFieldsStateRef:w}=i||l.control,E=!ue(k.current,t),D=()=>!x(S(w.current,t))&&E?S(w.current,t):x(u)?S(f.current,t):u,[A,B]=e.useState(D()),W=e.useRef(A),L=e.useRef(a),N=e=>!ne(Object.assign({isBlurEvent:e,isReValidateOnBlur:y,isReValidateOnChange:v,isSubmitted:p,isTouched:!!S(j,t)},h)),T=([e])=>{const r=(e=>_(e)||!O(e.target)||O(e.target)&&!e.type?e:x(e.target.value)?e.target.checked:e.target.value)(e);return B(r),W.current=r,r},M=e.useCallback(()=>{C.current[t]?C.current[t]=Object.assign({ref:C.current[t].ref},n):(g(Object.defineProperty({name:t,focus:L.current},"value",{set(e){B(e),W.current=e},get:()=>W.current}),n),E&&!S(f.current,t)&&B(D()))},[n,t,g]);e.useEffect(()=>()=>{!ue(k.current,t)&&b(t)},[b,t,k]),e.useEffect(()=>{M()},[M]),e.useEffect(()=>{C.current[t]||(M(),E&&B(D()))});const P=()=>{V.current.touched&&!S(j,t)&&(F(j,t,!0),R({touched:j})),N(!0)&&m(t)},$=(...e)=>d(t,T(e),{shouldValidate:N(),shouldDirty:!0}),I=Object.assign(Object.assign({},o),{onChange:$,onBlur:P,name:t,value:A});return s?e.isValidElement(s)?e.cloneElement(s,I):e.createElement(s,I):c?c({onChange:$,onBlur:P,value:A,name:t}):null},exports.FormProvider=r=>{var{children:t}=r,n=de(r,["children"]);return e.createElement(ge.Provider,{value:Object.assign({},n)},t)},exports.appendErrors=Z,exports.get=S,exports.transformToNestObject=V,exports.useFieldArray=({control:r,name:t,keyName:n="id"})=>{const s=be(),c=e.useRef(-1),{isWatchAllRef:u,resetFieldArrayFunctionRef:i,fieldArrayNamesRef:a,fieldsRef:o,defaultValuesRef:l,removeFieldEventListener:f,formStateRef:d,formStateRef:{current:{dirtyFields:g,touched:b}},shallowFieldsStateRef:m,updateFormState:h,readFormStateRef:y,watchFieldsRef:p,validFieldsRef:O,fieldsWithValidationRef:j,fieldArrayDefaultValuesRef:R,validateResolver:V,renderWatchedInputs:k,getValues:w,shouldUnregister:E}=r||s.control,D=se(t),A=e.useRef([...S(R.current,D)?S(R.current,t,[]):S(E?l.current:m.current,t,[])]),[B,W]=e.useState(xe(A.current,n)),L=e.useRef(B),N=()=>S(w()||{},t,L.current).map((e,r)=>Object.assign(Object.assign({},L.current[r]),e));L.current=B,a.current.add(t),S(R.current,D)||F(R.current,D,S(l.current,D));const T=e=>e.map(e=>Ve(e,n)),M=e=>{if(W(e),y.current.isValid&&V){const r=w();F(r,t,e),V(r)}},P=e=>(y.current.isDirty||y.current.dirtyFields)&&(x(e)||!G(e.map((e={})=>{var r=n;e[r];return de(e,["symbol"==typeof r?r:r+""])}),S(l.current,t))),$=()=>{for(const e in o.current)ce(e,t)&&o.current[e]&&f(o.current[e],!0)},I=e=>!C(S(e,t,[])).length&&H(e,t),U=(e,r,n=!0,s=!0,c=!1)=>{if(S(m.current,t)){const n=e(S(m.current,t),r.argA,r.argB);s&&F(m.current,t,n)}if(S(R.current,t)){const n=e(S(R.current,t),r.argA,r.argB);s&&F(R.current,t,n),I(R.current)}if(v(S(d.current.errors,t))){const n=e(S(d.current.errors,t),r.argA,r.argB);s&&F(d.current.errors,t,n),I(d.current.errors)}if(y.current.touched&&S(b,t)){const n=e(S(b,t),r.argA,r.argB);s&&F(b,t,n),I(b)}if(y.current.dirtyFields||y.current.isDirty){const n=e(S(g,t,[]),r.argC,r.argD);s&&F(g,t,n),I(g)}c&&y.current.isValid&&!V&&(F(O.current,t,e(S(O.current,t,[]),r.argA)),I(O.current),F(j.current,t,e(S(j.current,t,[]),r.argA)),I(j.current)),h({errors:d.current.errors,dirtyFields:g,isDirty:n,touched:b})},q=e=>{$(),!e&&H(R.current,t),H(m.current,t),A.current=S(e||l.current,t),W(xe(A.current,n))};return e.useEffect(()=>{const e=S(R.current,t);if(e&&B.length<e.length&&(e.pop(),F(R.current,t,e)),u.current)h();else if(p){let e=!0;for(const r of p.current)if(r.startsWith(t)){h(),e=!1;break}e&&k(t)}if(c.current>-1)for(const e in o.current){const r=o.current[e];if(e.startsWith(`${t}[${c.current}]`)&&r.ref.focus){r.ref.focus();break}}c.current=-1},[B,t]),e.useEffect(()=>{const e=i.current,r=a.current;return se(t)||(e[t]=q),()=>{$(),delete e[t],r.delete(t)}},[]),{swap:e.useCallback((e,r)=>{const t=N();ve(t,e,r),$(),M([...t]),U(ve,{argA:e,argB:r,argC:e,argD:r},P(t),!1)},[t]),move:e.useCallback((e,r)=>{const t=N();ye(t,e,r),$(),M([...t]),U(ye,{argA:e,argB:r,argC:e,argD:r},P(t),!1)},[t]),prepend:e.useCallback((e,r=!0)=>{const t=je(e);M(pe(N(),v(e)?T(e):[Ve(e,n)])),$(),U(pe,{argA:t,argC:Fe(e)}),c.current=r?0:-1},[t]),append:e.useCallback((e,r=!0)=>{if(M([...L.current,...v(e)?T(e):[Ve(e,n)]]),y.current.dirtyFields||y.current.isDirty){const r=S(g,t,[]);F(g,t,[...L.current.length>r.length?(je(L.current)||[]).map((e,t)=>r[t]):r,...Fe(e)]),h({isDirty:!0,dirtyFields:g})}E||(m.current[t]=[...m.current[t]||[],e]),c.current=r?L.current.length:-1},[t]),remove:e.useCallback(e=>{const r=N();M(he(r,e)),$(),U(he,{argA:e,argC:e},P(he(r,e)),!0,!0)},[t]),insert:e.useCallback((e,r,t=!0)=>{const s=je(r),u=N();M(Oe(u,e,v(r)?T(r):[Ve(r,n)])),$(),U(Oe,{argA:e,argB:s,argC:e,argD:Fe(r)},P(Oe(u,e))),c.current=t?e:-1},[t]),fields:B}},exports.useForm=function({mode:c=i,reValidateMode:a=u,resolver:l,context:f,defaultValues:d={},shouldFocusError:g=!0,shouldUnregister:b=!0,criteriaMode:m}={}){const h=e.useRef({}),p=e.useRef({}),R=e.useRef(new Set),w=e.useRef({}),E=e.useRef({}),L=e.useRef({}),N=e.useRef({}),T=e.useRef(d),I=e.useRef({}),J=e.useRef(!1),K=e.useRef(!1),X=e.useRef(),Y=e.useRef(b?{}:Object.assign({},d)),Z=e.useRef({}),ce=e.useRef(f),de=e.useRef(l),ge=e.useRef(new Set),be=e.useRef(ie(c)),{isOnSubmit:me,isOnTouch:he}=be.current,ye=m===o,[ve,pe]=e.useState({isDirty:!1,dirtyFields:{},isSubmitted:!1,submitCount:0,touched:{},isSubmitting:!1,isSubmitSuccessful:!1,isValid:!me,errors:{}}),Oe=e.useRef({isDirty:!fe,dirtyFields:!fe,touched:!fe||he,isSubmitting:!fe,isValid:!fe}),je=e.useRef(ve),Re=e.useRef(),{isOnBlur:Fe,isOnChange:Ve}=e.useRef(ie(a)).current;ce.current=f,de.current=l,je.current=ve;const xe=e.useCallback((e={})=>!J.current&&pe(Object.assign(Object.assign({},je.current),e)),[]),Ce=e.useCallback((e,r,t=!1,n={},s)=>{let c=t||function({errors:e,name:r,error:t,validFields:n,fieldsWithValidation:s}){const c=x(t),u=S(e,r);return c&&!!u||!c&&!G(u,t,!0)||c&&S(s,r)&&!S(n,r)}({errors:je.current.errors,error:r,name:e,validFields:N.current,fieldsWithValidation:L.current});const u=S(je.current.errors,e);r?(H(N.current,e),c=c||!u||!G(u,r,!0),F(je.current.errors,e,r)):((S(L.current,e)||de.current)&&(F(N.current,e,!0),c=c||u),H(je.current.errors,e)),(c&&!y(t)||!$(n))&&xe(Object.assign(Object.assign(Object.assign({},n),{errors:je.current.errors}),de.current?{isValid:!!s}:{}))},[]),Se=e.useCallback((e,t)=>{const{ref:n,options:s}=h.current[e],c=le&&r(n)&&y(t)?"":t;D(n)&&s?s.forEach(({ref:e})=>e.checked=e.value===c):A(n)&&!q(c)?n.files=c:W(n)?[...n.options].forEach(e=>e.selected=c.includes(e.value)):B(n)&&s?s.length>1?s.forEach(({ref:e})=>e.checked=v(c)?!!c.find(r=>r===e.value):c===e.value):s[0].ref.checked=!!c:n.value=c},[]),ke=()=>!G(Me(),$(T.current)?I.current:T.current)||!$(je.current.dirtyFields),we=e.useCallback((e,r=!0)=>{if(Oe.current.isDirty||Oe.current.dirtyFields){const t=S(I.current,e)!==M(h,e,Y),n=S(je.current.dirtyFields,e),s=je.current.isDirty;t?F(je.current.dirtyFields,e,!0):H(je.current.dirtyFields,e);const c={isDirty:ke(),dirtyFields:je.current.dirtyFields},u=Oe.current.isDirty&&s!==c.isDirty||Oe.current.dirtyFields&&n!==S(je.current.dirtyFields,e);return u&&r&&(je.current=Object.assign(Object.assign({},je.current),c),xe(Object.assign({},c))),u?c:{}}return{}},[]),Ee=e.useCallback(async(e,r)=>{if(h.current[e]){const t=(await ee(h,ye,h.current[e],Y))[e];return Ce(e,t,r),x(t)}return!1},[Ce,ye]),De=e.useCallback(async e=>{const{errors:r}=await de.current(Me(),ce.current,ye),t=je.current.isValid;if(v(e)){const t=e.map(e=>{const t=S(r,e);return t?F(je.current.errors,e,t):H(je.current.errors,e),!t}).every(Boolean);return xe({isValid:$(r),errors:je.current.errors}),t}{const n=S(r,e);return Ce(e,n,t!==$(r),{},$(r)),!n}},[Ce,ye]),Ae=e.useCallback(async e=>{const r=e||Object.keys(h.current);if(de.current)return De(r);if(v(r)){const e=await Promise.all(r.map(async e=>await Ee(e,null)));return xe(),e.every(Boolean)}return await Ee(r,Oe.current.isValid)},[De,Ee]),Be=e.useCallback((e,r,{shouldDirty:t,shouldValidate:n})=>{const s={};F(s,e,r);for(const c of re(e,r))h.current[c]&&(Se(c,S(s,c)),t&&we(c),n&&Ae(c))},[Ae,Se,we]),We=e.useCallback((e,r,t={})=>{h.current[e]?(Se(e,r),t.shouldDirty&&we(e)):_(r)||(Be(e,r,t),ge.current.has(e)&&(p.current[e]=r,Z.current[e]({[e]:r}),(Oe.current.isDirty||Oe.current.dirtyFields)&&(F(je.current.dirtyFields,e,function e(r,t,n,s,c){let u=-1;for(;++u<r.length;){for(const s in r[u])v(r[u][s])?(!n[u]&&(n[u]={}),n[u][s]=[],e(r[u][s],S(t[u]||{},s,[]),n[u][s],n[u],s)):S(t[u]||{},s)===r[u][s]?F(n[u]||{},s):n[u]=Object.assign(Object.assign({},n[u]),{[s]:!0});!n.length&&s&&delete s[c]}return n.length?n:void 0}(r,S(T.current,e,[]),S(je.current.dirtyFields,e,[]))),xe({isDirty:!G(Object.assign(Object.assign({},Me()),{[e]:r}),T.current),dirtyFields:je.current.dirtyFields})))),!b&&F(Y.current,e,r)},[we,Se,Be]),Le=e=>K.current||R.current.has(e)||R.current.has((e.match(/\w+/)||[])[0]),Ne=(e,r=!0)=>{if(!$(w.current))for(const t in w.current)e&&w.current[t].size&&!w.current[t].has(e)&&!w.current[t].has(se(e))||(E.current[t](),r=!1);return r};function Te(e){if(!b)for(const r of ge.current)j(r)&&!e[r]&&(e=Object.assign(Object.assign({},e),{[r]:[]}));return e}function Me(e){if(q(e))return M(h,e,Y);if(v(e)){const r={};for(const t of e)F(r,t,M(h,t,Y));return r}return Te(z(h,Y))}X.current=X.current?X.current:async({type:e,target:r})=>{const n=r.name,s=h.current[n];let c,u;if(s){const r=e===t,i=ne(Object.assign({isBlurEvent:r,isReValidateOnChange:Ve,isReValidateOnBlur:Fe,isTouched:!!S(je.current.touched,n),isSubmitted:je.current.isSubmitted},be.current));let a=we(n,!1),o=!$(a)||Le(n);if(r&&!S(je.current.touched,n)&&Oe.current.touched&&(F(je.current.touched,n,!0),a=Object.assign(Object.assign({},a),{touched:je.current.touched})),i)return Ne(n),(!$(a)||o&&$(a))&&xe(a);if(de.current){const{errors:e}=await de.current(Me(),ce.current,ye),r=je.current.isValid;c=S(e,n),u=$(e),r!==u&&(o=!0)}else c=(await ee(h,ye,s,Y))[n];Ne(n),Ce(n,c,o,a,u)}};const Pe=e.useCallback(async(e={})=>{const{errors:r}=await de.current(Object.assign(Object.assign(Object.assign({},T.current),Me()),e),ce.current,ye),t=$(r);je.current.isValid!==t&&xe({isValid:t})},[ye]),$e=e.useCallback((e,r)=>function(e,r,t,n,s,c){const{ref:u,ref:{name:i,type:a}}=t,o=e.current[i];if(!s){const r=M(e,i,n);x(r)||F(n.current,i,r)}if(a)if((D(u)||B(u))&&o){const{options:t}=o;v(t)&&t.length?(C(t).forEach((e,n)=>{const{ref:s}=e;(s&&P(s)&&U(e,s)||c)&&(k(s,r),H(t,`[${n}]`))}),t&&!C(t).length&&delete e.current[i]):delete e.current[i]}else(P(u)&&U(o,u)||c)&&(k(u,r),delete e.current[i]);else delete e.current[i]}(h,X.current,e,Y,b,r),[b]),Ie=e.useCallback((e,r)=>{e&&($e(e,r),b&&!C(e.options||[]).length&&(H(I.current,e.ref.name),H(N.current,e.ref.name),H(L.current,e.ref.name),H(je.current.errors,e.ref.name),F(je.current.dirtyFields,e.ref.name,!0),xe({errors:je.current.errors,isDirty:ke(),dirtyFields:je.current.dirtyFields}),de.current&&Pe()))},[Pe,$e]),He=e.useCallback((e,r,t)=>{const n=t?w.current[t]:R.current,s=x(r)?T.current:r,c=z(h,Y,!1,e);return q(e)?te(c,e,n,x(r)?S(s,e):r,!0):v(e)?e.reduce((e,r)=>Object.assign(Object.assign({},e),{[r]:te(c,r,n,s)}),{}):(K.current=x(t),V(!$(c)&&c||s))},[]);function Ue(e,c={}){const{name:u,type:i,value:a}=e,o=Object.assign({ref:e},c),l=h.current,f=ae(e),d=ue(ge.current,u),g=t=>le&&(!r(e)||t===e);let b,m=l[u],y=!0;if(m&&(f?v(m.options)&&C(m.options).find(e=>a===e.ref.value&&g(e.ref)):g(m.ref)))return void(l[u]=Object.assign(Object.assign({},m),c));m=i?f?Object.assign({options:[...C(m&&m.options||[]),{ref:e}],ref:{type:i,name:u}},c):Object.assign({},o):o,l[u]=m;const p=x(S(Y.current,u));if($(T.current)&&p||(b=S(p?T.current:Y.current,u),y=x(b),y||d||Se(u,b)),$(c)||(F(L.current,u,!0),!me&&Oe.current.isValid&&ee(h,ye,m,Y).then(e=>{const r=je.current.isValid;$(e)?F(N.current,u,!0):H(N.current,u),r!==$(e)&&xe()})),!(I.current[u]||d&&y)){const e=M(h,u,Y);F(I.current,u,y?O(e)?Object.assign({},e):e:b),!d&&H(je.current.dirtyFields,u)}i&&function({ref:e},c,u){r(e)&&u&&(e.addEventListener(c?n:s,u),e.addEventListener(t,u))}(f&&m.options?m.options[m.options.length-1]:m,f||"select-one"===e.type,X.current)}const qe=e.useCallback((e,r)=>async t=>{t&&t.preventDefault&&(t.preventDefault(),t.persist());let n={},s=Te(z(h,Y,!0));Oe.current.isSubmitting&&xe({isSubmitting:!0});try{if(de.current){const{errors:e,values:r}=await de.current(s,ce.current,ye);je.current.errors=e,n=e,s=r}else for(const e of Object.values(h.current))if(e){const{ref:{name:r}}=e,t=await ee(h,ye,e,Y);t[r]?(F(n,r,t[r]),H(N.current,r)):S(L.current,r)&&(H(je.current.errors,r),F(N.current,r,!0))}$(n)&&Object.keys(je.current.errors).every(e=>e in h.current)?(xe({errors:{},isSubmitting:!0}),await e(s,t)):(je.current.errors=Object.assign(Object.assign({},je.current.errors),n),r&&await r(n,t),g&&((e,r)=>{for(const t in e)if(S(r,t)){const r=e[t];if(r){if(r.ref.focus){r.ref.focus();break}if(r.options){r.options[0].ref.focus();break}}}})(h.current,n))}finally{xe({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:$(je.current.errors),errors:je.current.errors,submitCount:je.current.submitCount+1})}},[g,ye]);Re.current=Re.current||!le?Re.current:function(e,r){const t=new MutationObserver(()=>{for(const t of Object.values(e.current))if(t&&t.options)for(const e of t.options)e&&e.ref&&P(e.ref)&&r(t);else t&&P(t.ref)&&r(t)});return t.observe(window.document,{childList:!0,subtree:!0}),t}(h,Ie),e.useEffect(()=>(J.current=!1,l&&Oe.current.isValid&&Pe(),()=>{J.current=!0,Re.current&&Re.current.disconnect(),Y.current={},h.current&&Object.values(h.current).forEach(e=>Ie(e,!0))}),[Ie]),!l&&Oe.current.isValid&&(ve.isValid=G(N.current,L.current)&&$(je.current.errors));const _e={trigger:Ae,setValue:e.useCallback((function(e,r,t){We(e,r,t),Le(e)&&xe(),Ne(e),(t||{}).shouldValidate&&Ae(e)}),[We,Ae]),getValues:e.useCallback(Me,[]),register:e.useCallback((function(e,r){if(!oe)if(q(e))Ue({name:e},r);else{if(!O(e)||!("name"in e))return r=>r&&Ue(r,e);Ue(e,r)}}),[T.current]),unregister:e.useCallback((function(e){for(const r of v(e)?e:[e])Ie(h.current[r],!0)}),[])},ze=Object.assign({renderWatchedInputs:Ne,shouldUnregister:b,removeFieldEventListener:$e,watchInternal:He,mode:be.current,reValidateMode:{isReValidateOnBlur:Fe,isReValidateOnChange:Ve},fieldsRef:h,isWatchAllRef:K,watchFieldsRef:R,resetFieldArrayFunctionRef:Z,useWatchFieldsRef:w,useWatchRenderFunctionsRef:E,fieldArrayDefaultValuesRef:p,validFieldsRef:N,fieldsWithValidationRef:L,fieldArrayNamesRef:ge,readFormStateRef:Oe,formStateRef:je,defaultValuesRef:T,shallowFieldsStateRef:Y,updateFormState:xe,validateResolver:l?Pe:void 0},_e);return Object.assign({watch:function(e,r){return He(e,r)},control:ze,formState:fe?new Proxy(ve,{get:(e,r)=>{if(r in e)return Oe.current[r]=!0,e[r]}}):ve,handleSubmit:qe,reset:e.useCallback((e,t={})=>{if(le)for(const e of Object.values(h.current))if(e){const{ref:t,options:n}=e,s=ae(t)&&v(n)?n[0].ref:t;if(r(s))try{s.closest("form").reset();break}catch(e){}}h.current={},T.current=Object.assign({},e||T.current),e&&Ne(""),Y.current=b?{}:Object.assign({},e)||{},Object.values(Z.current).forEach(e=>Q(e)&&e()),(({errors:e,isDirty:r,isSubmitted:t,touched:n,isValid:s,submitCount:c,dirtyFields:u})=>{s||(N.current={},L.current={}),I.current={},p.current={},R.current=new Set,K.current=!1,xe({submitCount:c?je.current.submitCount:0,isDirty:!!r&&je.current.isDirty,isSubmitted:!!t&&je.current.isSubmitted,isValid:!!s&&je.current.isValid,dirtyFields:u?je.current.dirtyFields:{},touched:n?je.current.touched:{},errors:e?je.current.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})})(t)},[]),clearErrors:e.useCallback((function(e){e&&(v(e)?e:[e]).forEach(e=>h.current[e]?j(e)?delete je.current.errors[e]:F(je.current.errors,e,void 0):H(je.current.errors,e)),xe({errors:e?je.current.errors:{}})}),[]),setError:e.useCallback((function(e,r){const t=(h.current[e]||{}).ref;F(je.current.errors,e,Object.assign(Object.assign({},r),{ref:t})),xe({isValid:!1,errors:je.current.errors}),r.shouldFocus&&t&&t.focus&&t.focus()}),[]),errors:ve.errors},_e)},exports.useFormContext=be,exports.useWatch=function({control:r,name:t,defaultValue:n}){const s=be(),{useWatchFieldsRef:c,useWatchRenderFunctionsRef:u,watchInternal:i,defaultValuesRef:a}=r||s.control,[o,l]=e.useState(x(n)?q(t)?S(a.current,t):v(t)?t.reduce((e,r)=>Object.assign(Object.assign({},e),{[r]:S(a.current,r)}),{}):a.current:n),f=e.useRef(),d=e.useRef(n),g=e.useCallback(()=>{const e=i(t,d.current,f.current);l(O(e)?Object.assign({},e):v(e)?[...e]:e)},[l,i,d,t,f]);return e.useEffect(()=>{const e=f.current=me(),r=u.current,n=c.current;return n[e]=new Set,r[e]=g,i(t,d.current,e),()=>{delete n[e],delete r[e]}},[t,g,u,c,i,d]),x(o)?n:o};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=e=>e instanceof HTMLElement;const t="blur",n="change",s="input",c="onBlur",u="onChange",i="onSubmit",a="onTouched",o="all",l="max",f="min",d="maxLength",y="minLength",g="pattern",b="required",m="validate";var h=e=>null==e;const v=e=>"object"==typeof e;var p=e=>!h(e)&&!Array.isArray(e)&&v(e)&&!(e instanceof Date),O=e=>!Array.isArray(e)&&(/^\w*$/.test(e)||!/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/.test(e)),A=e=>e.filter(Boolean),j=e=>A(e.replace(/["|']/g,"").replace(/\[/g,".").replace(/\]/g,"").split("."));function R(e,r,t){let n=-1;const s=O(r)?[r]:j(r),c=s.length,u=c-1;for(;++n<c;){const r=s[n];let c=t;if(n!==u){const t=e[r];c=p(t)||Array.isArray(t)?t:isNaN(+s[n+1])?{}:[]}e[r]=c,e=e[r]}return e}var F=(e,r={})=>{for(const t in e)O(t)?r[t]=e[t]:R(r,t,e[t]);return r},V=e=>void 0===e,x=(e,r,t)=>{const n=A(r.split(/[,[\].]+?/)).reduce(((e,r)=>h(e)?e:e[r]),e);return V(n)||n===e?V(e[r])?t:e[r]:n},C=(e,c)=>{r(e)&&e.removeEventListener&&(e.removeEventListener(s,c),e.removeEventListener(n,c),e.removeEventListener(t,c))};const S={isValid:!1,value:""};var k=e=>Array.isArray(e)?e.reduce(((e,r)=>r&&r.ref.checked?{isValid:!0,value:r.ref.value}:e),S):S,w=e=>"radio"===e.type,E=e=>"file"===e.type,D=e=>"checkbox"===e.type,B=e=>"select-multiple"===e.type;const L={value:!1,isValid:!1},N={value:!0,isValid:!0};var W=e=>{if(Array.isArray(e)){if(e.length>1){const r=e.filter((e=>e&&e.ref.checked)).map((({ref:{value:e}})=>e));return{value:r,isValid:!!r.length}}const{checked:r,value:t,attributes:n}=e[0].ref;return r?n&&!V(n.value)?V(t)||""===t?N:{value:t,isValid:!0}:N:L}return L};function T(e,r,t,n){const s=e.current[r];if(s){const{ref:{value:e,disabled:r},ref:t}=s;if(r&&n)return;return E(t)?t.files:w(t)?k(s.options).value:B(t)?(c=t.options,[...c].filter((({selected:e})=>e)).map((({value:e})=>e))):D(t)?W(s.options).value:e}var c;if(t)return x(t.current,r)}function $(e){return!e||e instanceof HTMLElement&&e.nodeType!==Node.DOCUMENT_NODE&&$(e.parentNode)}var M=e=>p(e)&&!Object.keys(e).length,P=e=>"boolean"==typeof e;function H(e,r){const t=O(r)?[r]:j(r),n=1==t.length?e:function(e,r){const t=r.slice(0,-1).length;let n=0;for(;n<t;)e=V(e)?n++:e[r[n++]];return e}(e,t),s=t[t.length-1];let c=void 0;n&&delete n[s];for(let r=0;r<t.slice(0,-1).length;r++){let n=-1,s=void 0;const u=t.slice(0,-(r+1)),i=u.length-1;for(r>0&&(c=e);++n<u.length;){const r=u[n];s=s?s[r]:e[r],i===n&&(p(s)&&M(s)||Array.isArray(s)&&!s.filter((e=>p(e)&&!M(e)||P(e))).length)&&(c?delete c[r]:delete e[r]),c=s}}return e}const U=(e,r)=>e&&e.ref===r;function q(e,r,t,n,s){let c=-1;for(;++c<e.length;){for(const n in e[c])Array.isArray(e[c][n])?(!t[c]&&(t[c]={}),t[c][n]=[],q(e[c][n],x(r[c]||{},n,[]),t[c][n],t[c],n)):x(r[c]||{},n)===e[c][n]?R(t[c]||{},n):t[c]=Object.assign(Object.assign({},t[c]),{[n]:!0});!t.length&&n&&delete n[s]}return t.length?t:void 0}var I=e=>"string"==typeof e,_=e=>h(e)||!v(e);function z(e,r){if(_(e)||_(r))return r;for(const t in r){const n=e[t],s=r[t];try{e[t]=p(n)&&p(s)||Array.isArray(n)&&Array.isArray(s)?z(n,s):s}catch(e){}}return e}var G=(e,r,t,n)=>{const s={};for(const r in e.current)(V(n)||(I(n)?r.startsWith(n):Array.isArray(n)&&n.find((e=>r.startsWith(e)))))&&(s[r]=T(e,r,void 0,t));return z(F(Object.assign({},(r||{}).current||{})),F(s))};function J(e=[],r=[],t){const n=Object.keys(e),s=Object.keys(r);if(n.length!==s.length)return!1;for(const s of n)if(!t||!["ref","context"].includes(s)){const n=e[s],c=r[s];if((p(n)||Array.isArray(n))&&(p(c)||Array.isArray(c))?!J(n,c,t):n!==c)return!1}return!0}var K=e=>e instanceof RegExp;var Q=e=>{return p(r=e)&&!K(r)?e:{value:e,message:""};var r},X=e=>"function"==typeof e,Y=r=>I(r)||p(r)&&e.isValidElement(r);function Z(e,r,t="validate"){if(Y(e)||P(e)&&!e)return{type:t,message:Y(e)?e:"",ref:r}}var ee=(e,r,t,n,s)=>{if(r){const r=t[e];return Object.assign(Object.assign({},r),{types:Object.assign(Object.assign({},r&&r.types?r.types:{}),{[n]:s||!0})})}return{}},re=async(e,r,{ref:t,ref:{type:n,value:s},options:c,required:u,maxLength:i,minLength:a,min:o,max:v,pattern:O,validate:A},j)=>{const R=e.current,F=t.name,V={},x=w(t),C=D(t),S=x||C,E=""===s,B=ee.bind(null,F,r,V),L=(e,r,n,s=d,c=y)=>{const u=e?r:n;V[F]=Object.assign({type:e?s:c,message:u,ref:t},B(e?s:c,u))};if(u&&(!x&&!C&&(E||h(s))||P(s)&&!s||C&&!W(c).isValid||x&&!k(c).isValid)){const{value:e,message:n}=Y(u)?{value:!!u,message:u}:Q(u);if(e&&(V[F]=Object.assign({type:b,message:n,ref:S?((R[F].options||[])[0]||{}).ref:t},B(b,n)),!r))return V}if(!h(o)||!h(v)){let e,c;const{value:u,message:i}=Q(v),{value:a,message:d}=Q(o);if("number"===n||!n&&!isNaN(s)){const r=t.valueAsNumber||parseFloat(s);h(u)||(e=r>u),h(a)||(c=r<a)}else{const r=t.valueAsDate||new Date(s);I(u)&&(e=r>new Date(u)),I(a)&&(c=r<new Date(a))}if((e||c)&&(L(!!e,i,d,l,f),!r))return V}if(I(s)&&!E&&(i||a)){const{value:e,message:t}=Q(i),{value:n,message:c}=Q(a),u=s.toString().length,o=!h(e)&&u>e,l=!h(n)&&u<n;if((o||l)&&(L(!!o,t,c),!r))return V}if(O&&!E){const{value:e,message:n}=Q(O);if(K(e)&&!e.test(s)&&(V[F]=Object.assign({type:g,message:n,ref:t},B(g,n)),!r))return V}if(A){const n=T(e,F,j),s=S&&c?c[0].ref:t;if(X(A)){const e=Z(await A(n),s);if(e&&(V[F]=Object.assign(Object.assign({},e),B(m,e.message)),!r))return V}else if(p(A)){let e={};for(const[t,c]of Object.entries(A)){if(!M(e)&&!r)break;const u=Z(await c(n),s,t);u&&(e=Object.assign(Object.assign({},u),B(t,u.message)),r&&(V[F]=e))}if(!M(e)&&(V[F]=Object.assign({ref:s},e),!r))return V}}return V};const te=(e,r)=>Object.entries(r).map((([t,n])=>((r,t,n)=>{const s=n?`${e}.${r}`:`${e}[${r}]`;return _(t)?s:te(s,t)})(t,n,p(r)))).flat(1/0);var ne=(e,r,t,n,s)=>{let c;return t.add(r),M(e)?c=void 0:(c=x(e,r),(p(c)||Array.isArray(c))&&te(r,c).forEach((e=>t.add(e)))),V(c)?s?n:x(n,r):c},se=({isOnBlur:e,isOnChange:r,isOnTouch:t,isTouched:n,isReValidateOnBlur:s,isReValidateOnChange:c,isBlurEvent:u,isSubmitted:i,isOnAll:a})=>!a&&(!i&&t?!(n||u):(i?s:e)?!u:!(i?c:r)||u),ce=e=>e.substring(0,e.indexOf("["));const ue=(e,r)=>RegExp(`^${r}[\\d+]`.replace(/\[/g,"\\[").replace(/\]/g,"\\]")).test(e);var ie=(e,r)=>[...e].some((e=>ue(r,e)));function ae(e){let r;if(_(e))return e;if(e instanceof Date)return r=new Date(e.getTime()),r;r=Array.isArray(e)?[]:{};for(const t in e)r[t]=ae(e[t]);return r}var oe=e=>({isOnSubmit:!e||e===i,isOnBlur:e===c,isOnChange:e===u,isOnAll:e===o,isOnTouch:e===a}),le=e=>w(e)||D(e);const fe="undefined"==typeof window,de="undefined"!=typeof document&&!fe&&!V(window.HTMLElement),ye=de?"Proxy"in window:"undefined"!=typeof Proxy;function ge(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(t[n[s]]=e[n[s]])}return t}const be=e.createContext(null);be.displayName="RHFContext";const me=()=>e.useContext(be);var he=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){const t=(16*Math.random()+e)%16|0;return("x"==r?t:3&t|8).toString(16)}))};var ve=(e,r)=>V(r)?[]:Array.isArray(r)?function(e,r){let t=-1;for(;++t<e.length;)r.indexOf(t)>=0&&delete e[t];return A(e)}(e,r):((e,r)=>[...e.slice(0,r),...e.slice(r+1)])(e,r),pe=(e,r,t)=>Array.isArray(e)?(V(e[t])&&(e[t]=void 0),e.splice(t,0,e.splice(r,1)[0]),e):[],Oe=(e,r,t)=>{const n=[e[t],e[r]];e[r]=n[0],e[t]=n[1]};function Ae(e,r){return[...Array.isArray(r)?r:[r||void 0],...e]}function je(e,r,t){return[...e.slice(0,r),...Array.isArray(t)?t:[t||void 0],...e.slice(r)]}var Re=e=>Array.isArray(e)?Array(e.length).fill(void 0):void 0;function Fe(e){if(p(e)){const r={};for(const t in e)r[t]=!0;return[r]}return[!0]}var Ve=e=>(Array.isArray(e)?e:[e]).map(Fe).flat();const xe=(e,r)=>e.map((e=>Object.assign({[r]:he()},e)));exports.Controller=r=>{var{name:t,rules:n,as:s,render:c,defaultValue:u,control:i,onFocus:a}=r,o=ge(r,["name","rules","as","render","defaultValue","control","onFocus"]);const l=me(),{defaultValuesRef:f,setValue:d,register:y,unregister:g,trigger:b,mode:m,reValidateMode:{isReValidateOnBlur:h,isReValidateOnChange:v},formStateRef:{current:{isSubmitted:O,touched:A}},updateFormState:j,readFormStateRef:F,fieldsRef:C,fieldArrayNamesRef:S,shallowFieldsStateRef:k}=i||l.control,w=!ie(S.current,t),E=()=>!V(x(k.current,t))&&w?x(k.current,t):V(u)?x(f.current,t):u,[D,B]=e.useState(E()),L=e.useRef(D),N=e.useRef(a),W=e=>!se(Object.assign({isBlurEvent:e,isReValidateOnBlur:h,isReValidateOnChange:v,isSubmitted:O,isTouched:!!x(A,t)},m)),T=([e])=>{const r=(e=>_(e)||!p(e.target)||p(e.target)&&!e.type?e:V(e.target.value)?e.target.checked:e.target.value)(e);return B(r),L.current=r,r},$=e.useCallback((()=>{C.current[t]?C.current[t]=Object.assign({ref:C.current[t].ref},n):(y(Object.defineProperty({name:t,focus:N.current},"value",{set(e){B(e),L.current=e},get:()=>L.current}),n),w&&!x(f.current,t)&&B(E()))}),[n,t,y]);e.useEffect((()=>()=>g(t)),[g,t]),e.useEffect((()=>{$()}),[$]),e.useEffect((()=>{C.current[t]||($(),w&&B(E()))}));const M=()=>{F.current.touched&&!x(A,t)&&(R(A,t,!0),j({touched:A})),W(!0)&&b(t)},P=(...e)=>d(t,T(e),{shouldValidate:W(),shouldDirty:!0}),H=Object.assign(Object.assign({},o),{onChange:P,onBlur:M,name:t,value:D});return s?e.isValidElement(s)?e.cloneElement(s,H):e.createElement(s,H):c?c({onChange:P,onBlur:M,value:D,name:t}):null},exports.FormProvider=r=>{var{children:t}=r,n=ge(r,["children"]);return e.createElement(be.Provider,{value:Object.assign({},n)},t)},exports.appendErrors=ee,exports.get=x,exports.transformToNestObject=F,exports.useFieldArray=({control:r,name:t,keyName:n="id"})=>{const s=me(),c=e.useRef(-1),{updateWatchedValue:u,resetFieldArrayFunctionRef:i,fieldArrayNamesRef:a,fieldsRef:o,defaultValuesRef:l,removeFieldEventListener:f,formStateRef:d,shallowFieldsStateRef:y,updateFormState:g,readFormStateRef:b,validFieldsRef:m,fieldsWithValidationRef:h,fieldArrayDefaultValuesRef:v,validateResolver:p,getValues:O,shouldUnregister:j}=r||s.control,F=ce(t),C=e.useRef([...x(v.current,F)?x(v.current,t,[]):x(j?l.current:y.current,t,[])]),[S,k]=e.useState(xe(C.current,n)),w=e.useRef(S),E=()=>x(O(),t,w.current).map(((e,r)=>Object.assign(Object.assign({},w.current[r]),e)));w.current=S,a.current.add(t),x(v.current,F)||R(v.current,F,x(l.current,F));const D=e=>{if(k(e),b.current.isValid&&p){const r=O();R(r,t,e),p(r)}},B=e=>(b.current.isDirty||b.current.dirtyFields)&&(V(e)||!J(e.map(((e={})=>{var r=n;e[r];return ge(e,["symbol"==typeof r?r:r+""])})),x(l.current,t))),L=()=>{for(const e in o.current)ue(e,t)&&f(o.current[e],!0)},N=e=>!A(x(e,t,[])).length&&H(e,t),W=e=>{const r=x(l.current,t,[]),s=(e,r)=>{for(const s in e)for(const c in e[s])c===n||r[s]&&e[s]&&e[s][c]===r[s][c]||R(d.current.dirtyFields,`${t}[${s}]`,Object.assign(Object.assign({},x(d.current.dirtyFields,`${t}[${s}]`,{})),{[c]:!0}))};e&&(s(r,e),s(e,r))},T=(e,r,n,s=!0,c=!0,u=!1)=>{if(x(y.current,t)){const n=e(x(y.current,t),r.argA,r.argB);c&&R(y.current,t,n)}if(x(v.current,t)){const n=e(x(v.current,t),r.argA,r.argB);c&&R(v.current,t,n),N(v.current)}if(Array.isArray(x(d.current.errors,t))){const n=e(x(d.current.errors,t),r.argA,r.argB);c&&R(d.current.errors,t,n),N(d.current.errors)}if(b.current.touched&&x(d.current.touched,t)){const n=e(x(d.current.touched,t),r.argA,r.argB);c&&R(d.current.touched,t,n),N(d.current.touched)}if(b.current.dirtyFields||b.current.isDirty){const s=e(x(d.current.dirtyFields,t,[]),r.argC,r.argD);c&&R(d.current.dirtyFields,t,s),W(n),N(d.current.dirtyFields)}u&&b.current.isValid&&!p&&(R(m.current,t,e(x(m.current,t,[]),r.argA)),N(m.current),R(h.current,t,e(x(h.current,t,[]),r.argA)),N(h.current)),g({errors:d.current.errors,dirtyFields:d.current.dirtyFields,isDirty:s,touched:d.current.touched})},$=e=>{L(),!e&&H(v.current,t),H(y.current,t),C.current=x(e||l.current,t),k(xe(C.current,n))};return e.useEffect((()=>{const e=x(v.current,t);if(e&&S.length<e.length&&(e.pop(),R(v.current,t,e)),u(t),c.current>-1)for(const e in o.current){const r=o.current[e];if(e.startsWith(`${t}[${c.current}]`)&&r.ref.focus){r.ref.focus();break}}c.current=-1}),[S,t]),e.useEffect((()=>{const e=i.current,r=a.current;return ce(t)||(e[t]=$),()=>{L(),delete e[t],r.delete(t)}}),[]),{swap:e.useCallback(((e,r)=>{const t=E();Oe(t,e,r),L(),D([...t]),T(Oe,{argA:e,argB:r,argC:e,argD:r},void 0,B(t),!1)}),[t]),move:e.useCallback(((e,r)=>{const t=E();pe(t,e,r),L(),D([...t]),T(pe,{argA:e,argB:r,argC:e,argD:r},void 0,B(t),!1)}),[t]),prepend:e.useCallback(((e,r=!0)=>{const t=Re(e),s=Ae(E(),xe(Array.isArray(e)?e:[e],n));D(s),L(),T(Ae,{argA:t,argC:Ve(e)},s),c.current=r?0:-1}),[t]),append:e.useCallback(((e,r=!0)=>{const s=[...w.current,...xe(Array.isArray(e)?e:[e],n)];D(s),(b.current.dirtyFields||b.current.isDirty)&&(W(s),g({isDirty:!0,dirtyFields:d.current.dirtyFields})),j||(y.current[t]=[...y.current[t]||[],e]),c.current=r?w.current.length:-1}),[t]),remove:e.useCallback((e=>{const r=E(),t=ve(r,e);D(t),L(),T(ve,{argA:e,argC:e},t,B(ve(r,e)),!0,!0)}),[t]),insert:e.useCallback(((e,r,t=!0)=>{const s=Re(r),u=E(),i=je(u,e,xe(Array.isArray(r)?r:[r],n));D(i),L(),T(je,{argA:e,argB:s,argC:e,argD:Ve(r)},i,B(je(u,e))),c.current=t?e:-1}),[t]),fields:S}},exports.useForm=function({mode:c=i,reValidateMode:a=u,resolver:l,context:f,defaultValues:d={},shouldFocusError:y=!0,shouldUnregister:g=!0,criteriaMode:b}={}){const m=e.useRef({}),v=e.useRef({}),j=e.useRef(new Set),S=e.useRef({}),k=e.useRef({}),L=e.useRef({}),N=e.useRef({}),W=e.useRef(d),P=e.useRef({}),z=e.useRef(!1),K=e.useRef(!1),Q=e.useRef(),Y=e.useRef(g?{}:ae(d)),Z=e.useRef({}),ee=e.useRef(f),ue=e.useRef(l),ge=e.useRef(new Set),be=e.useRef(oe(c)),{isOnSubmit:me,isOnTouch:he}=be.current,ve=b===o,[pe,Oe]=e.useState({isDirty:!1,dirtyFields:{},isSubmitted:!1,submitCount:0,touched:{},isSubmitting:!1,isSubmitSuccessful:!1,isValid:!me,errors:{}}),Ae=e.useRef({isDirty:!ye,dirtyFields:!ye,touched:!ye||he,isSubmitting:!ye,isValid:!ye}),je=e.useRef(pe),Re=e.useRef(),{isOnBlur:Fe,isOnChange:Ve}=e.useRef(oe(a)).current;ee.current=f,ue.current=l,je.current=pe;const xe=e.useCallback(((e={})=>!z.current&&Oe(Object.assign(Object.assign({},je.current),e))),[]),Ce=e.useCallback(((e,r,t=!1,n={},s)=>{let c=t||function({errors:e,name:r,error:t,validFields:n,fieldsWithValidation:s}){const c=V(t),u=x(e,r);return c&&!!u||!c&&!J(u,t,!0)||c&&x(s,r)&&!x(n,r)}({errors:je.current.errors,error:r,name:e,validFields:N.current,fieldsWithValidation:L.current});const u=x(je.current.errors,e);r?(H(N.current,e),c=c||!u||!J(u,r,!0),R(je.current.errors,e,r)):((x(L.current,e)||ue.current)&&(R(N.current,e,!0),c=c||u),H(je.current.errors,e)),(c&&!h(t)||!M(n))&&xe(Object.assign(Object.assign(Object.assign({},n),{errors:je.current.errors}),ue.current?{isValid:!!s}:{}))}),[]),Se=e.useCallback(((e,t)=>{const{ref:n,options:s}=m.current[e],c=de&&r(n)&&h(t)?"":t;w(n)&&s?s.forEach((({ref:e})=>e.checked=e.value===c)):E(n)&&!I(c)?n.files=c:B(n)?[...n.options].forEach((e=>e.selected=c.includes(e.value))):D(n)&&s?s.length>1?s.forEach((({ref:e})=>e.checked=Array.isArray(c)?!!c.find((r=>r===e.value)):c===e.value)):s[0].ref.checked=!!c:n.value=c}),[]),ke=()=>!J(Me(),M(W.current)?P.current:W.current),we=e.useCallback(((e,r=!0)=>{if(Ae.current.isDirty||Ae.current.dirtyFields){const t=x(P.current,e)!==T(m,e,Y),n=x(je.current.dirtyFields,e),s=je.current.isDirty;t?R(je.current.dirtyFields,e,!0):H(je.current.dirtyFields,e);const c={isDirty:ke(),dirtyFields:je.current.dirtyFields},u=Ae.current.isDirty&&s!==c.isDirty||Ae.current.dirtyFields&&n!==x(je.current.dirtyFields,e);return u&&r&&(je.current=Object.assign(Object.assign({},je.current),c),xe(Object.assign({},c))),u?c:{}}return{}}),[]),Ee=e.useCallback((async(e,r)=>{if(m.current[e]){const t=(await re(m,ve,m.current[e],Y))[e];return Ce(e,t,r),V(t)}return!1}),[Ce,ve]),De=e.useCallback((async e=>{const{errors:r}=await ue.current(Me(),ee.current,ve),t=je.current.isValid;if(Array.isArray(e)){const t=e.map((e=>{const t=x(r,e);return t?R(je.current.errors,e,t):H(je.current.errors,e),!t})).every(Boolean);return xe({isValid:M(r),errors:je.current.errors}),t}{const n=x(r,e);return Ce(e,n,t!==M(r),{},M(r)),!n}}),[Ce,ve]),Be=e.useCallback((async e=>{const r=e||Object.keys(m.current);if(ue.current)return De(r);if(Array.isArray(r)){const e=await Promise.all(r.map((async e=>await Ee(e,null))));return xe(),e.every(Boolean)}return await Ee(r,Ae.current.isValid)}),[De,Ee]),Le=e.useCallback(((e,r,{shouldDirty:t,shouldValidate:n})=>{const s={};R(s,e,r);for(const c of te(e,r))m.current[c]&&(Se(c,x(s,c)),t&&we(c),n&&Be(c))}),[Be,Se,we]),Ne=e.useCallback(((e,r,t={})=>{m.current[e]?(Se(e,r),t.shouldDirty&&we(e)):_(r)||(Le(e,r,t),ge.current.has(e)&&(v.current[e]=r,Z.current[e]({[e]:r}),(Ae.current.isDirty||Ae.current.dirtyFields)&&t.shouldDirty&&(R(je.current.dirtyFields,e,q(r,x(W.current,e,[]),x(je.current.dirtyFields,e,[]))),xe({isDirty:!J(Object.assign(Object.assign({},Me()),{[e]:r}),W.current),dirtyFields:je.current.dirtyFields})))),!g&&R(Y.current,e,r)}),[we,Se,Le]),We=e=>K.current||j.current.has(e)||j.current.has((e.match(/\w+/)||[])[0]),Te=(e,r=!0)=>{if(!M(S.current))for(const t in S.current)e&&S.current[t].size&&!S.current[t].has(e)&&!S.current[t].has(ce(e))||(k.current[t](),r=!1);return r};function $e(e){if(!g){let r=ae(e);for(const e of ge.current)O(e)&&!r[e]&&(r=Object.assign(Object.assign({},r),{[e]:[]}));return r}return e}function Me(e){if(I(e))return T(m,e,Y);if(Array.isArray(e)){const r={};for(const t of e)R(r,t,T(m,t,Y));return r}return $e(G(m,Y))}Q.current=Q.current?Q.current:async({type:e,target:r})=>{const n=r.name,s=m.current[n];let c,u;if(s){const r=e===t,i=se(Object.assign({isBlurEvent:r,isReValidateOnChange:Ve,isReValidateOnBlur:Fe,isTouched:!!x(je.current.touched,n),isSubmitted:je.current.isSubmitted},be.current));let a=we(n,!1),o=!M(a)||We(n);if(r&&!x(je.current.touched,n)&&Ae.current.touched&&(R(je.current.touched,n,!0),a=Object.assign(Object.assign({},a),{touched:je.current.touched})),i)return Te(n),(!M(a)||o&&M(a))&&xe(a);if(ue.current){const{errors:e}=await ue.current(Me(),ee.current,ve),r=je.current.isValid;c=x(e,n),u=M(e),r!==u&&(o=!0)}else c=(await re(m,ve,s,Y))[n];Te(n),Ce(n,c,o,a,u)}};const Pe=e.useCallback((async(e={})=>{const{errors:r}=await ue.current(Object.assign(Object.assign(Object.assign({},W.current),Me()),e),ee.current,ve),t=M(r);je.current.isValid!==t&&xe({isValid:t})}),[ve]),He=e.useCallback(((e,r)=>function(e,r,t,n,s,c){const{ref:u,ref:{name:i,type:a}}=t,o=e.current[i];if(!s){const r=T(e,i,n);V(r)||R(n.current,i,r)}if(a)if((w(u)||D(u))&&o){const{options:t}=o;Array.isArray(t)&&t.length?(A(t).forEach(((e,n)=>{const{ref:s}=e;(s&&$(s)&&U(e,s)||c)&&(C(s,r),H(t,`[${n}]`))})),t&&!A(t).length&&delete e.current[i]):delete e.current[i]}else($(u)&&U(o,u)||c)&&(C(u,r),delete e.current[i]);else delete e.current[i]}(m,Q.current,e,Y,g,r)),[g]),Ue=e=>{if(K.current)xe();else if(j){let r=!0;for(const t of j.current)if(t.startsWith(e)){xe(),r=!1;break}r&&Te(e)}},qe=e.useCallback(((e,r)=>{e&&(He(e,r),g&&!A(e.options||[]).length&&(H(P.current,e.ref.name),H(N.current,e.ref.name),H(L.current,e.ref.name),H(je.current.errors,e.ref.name),R(je.current.dirtyFields,e.ref.name,!0),xe({errors:je.current.errors,isDirty:ke(),dirtyFields:je.current.dirtyFields}),ue.current&&Pe(),Ue(e.ref.name)))}),[Pe,He]),Ie=e.useCallback(((e,r,t)=>{const n=t?S.current[t]:j.current,s=V(r)?W.current:r,c=G(m,Y,!1,e);return I(e)?ne(c,e,n,V(r)?x(s,e):r,!0):Array.isArray(e)?e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:ne(c,r,n,s)})),{}):(K.current=V(t),F(!M(c)&&c||s))}),[]);function _e(e,c={}){const{name:u,type:i,value:a}=e,o=Object.assign({ref:e},c),l=m.current,f=le(e),d=ie(ge.current,u),y=t=>de&&(!r(e)||t===e);let g,b=l[u],h=!0;if(b&&(f?Array.isArray(b.options)&&A(b.options).find((e=>a===e.ref.value&&y(e.ref))):y(b.ref)))return void(l[u]=Object.assign(Object.assign({},b),c));b=i?f?Object.assign({options:[...A(b&&b.options||[]),{ref:e}],ref:{type:i,name:u}},c):Object.assign({},o):o,l[u]=b;const v=V(x(Y.current,u));if(M(W.current)&&v||(g=x(v?W.current:Y.current,u),h=V(g),h||d||Se(u,g)),M(c)||(R(L.current,u,!0),!me&&Ae.current.isValid&&re(m,ve,b,Y).then((e=>{const r=je.current.isValid;M(e)?R(N.current,u,!0):H(N.current,u),r!==M(e)&&xe()}))),!(P.current[u]||d&&h)){const e=T(m,u,Y);R(P.current,u,h?p(e)?Object.assign({},e):e:g),!d&&H(je.current.dirtyFields,u)}i&&function({ref:e},c,u){r(e)&&u&&(e.addEventListener(c?n:s,u),e.addEventListener(t,u))}(f&&b.options?b.options[b.options.length-1]:b,f||"select-one"===e.type,Q.current)}const ze=e.useCallback(((e,r)=>async t=>{t&&t.preventDefault&&(t.preventDefault(),t.persist());let n={},s=$e(G(m,Y,!0));Ae.current.isSubmitting&&xe({isSubmitting:!0});try{if(ue.current){const{errors:e,values:r}=await ue.current(s,ee.current,ve);je.current.errors=n=e,s=r}else for(const e of Object.values(m.current))if(e){const{ref:{name:r}}=e,t=await re(m,ve,e,Y);t[r]?(R(n,r,t[r]),H(N.current,r)):x(L.current,r)&&(H(je.current.errors,r),R(N.current,r,!0))}M(n)&&Object.keys(je.current.errors).every((e=>e in m.current))?(xe({errors:{},isSubmitting:!0}),await e(s,t)):(je.current.errors=Object.assign(Object.assign({},je.current.errors),n),r&&await r(n,t),y&&((e,r)=>{for(const t in e)if(x(r,t)){const r=e[t];if(r){if(r.ref.focus){r.ref.focus();break}if(r.options){r.options[0].ref.focus();break}}}})(m.current,n))}finally{xe({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:M(je.current.errors),errors:je.current.errors,submitCount:je.current.submitCount+1})}}),[y,ve]);e.useEffect((()=>(z.current=!1,l&&Ae.current.isValid&&Pe(),Re.current=Re.current||!de?Re.current:function(e,r){const t=new MutationObserver((()=>{for(const t of Object.values(e.current))if(t&&t.options)for(const e of t.options)e&&e.ref&&$(e.ref)&&r(t);else t&&$(t.ref)&&r(t)}));return t.observe(window.document,{childList:!0,subtree:!0}),t}(m,qe),()=>{z.current=!0,Re.current&&Re.current.disconnect(),Y.current={},Object.values(m.current).forEach((e=>qe(e,!0)))})),[qe]),!l&&Ae.current.isValid&&(pe.isValid=J(N.current,L.current)&&M(je.current.errors));const Ge={trigger:Be,setValue:e.useCallback((function(e,r,t){Ne(e,r,t),We(e)&&xe(),Te(e),(t||{}).shouldValidate&&Be(e)}),[Ne,Be]),getValues:e.useCallback(Me,[]),register:e.useCallback((function(e,r){if(!fe)if(I(e))_e({name:e},r);else{if(!p(e)||!("name"in e))return r=>r&&_e(r,e);_e(e,r)}}),[W.current]),unregister:e.useCallback((function(e){for(const r of Array.isArray(e)?e:[e])qe(m.current[r],!0)}),[])},Je=Object.assign({updateWatchedValue:Ue,shouldUnregister:g,removeFieldEventListener:He,watchInternal:Ie,mode:be.current,reValidateMode:{isReValidateOnBlur:Fe,isReValidateOnChange:Ve},fieldsRef:m,resetFieldArrayFunctionRef:Z,useWatchFieldsRef:S,useWatchRenderFunctionsRef:k,fieldArrayDefaultValuesRef:v,validFieldsRef:N,fieldsWithValidationRef:L,fieldArrayNamesRef:ge,readFormStateRef:Ae,formStateRef:je,defaultValuesRef:W,shallowFieldsStateRef:Y,updateFormState:xe,validateResolver:l?Pe:void 0},Ge);return Object.assign({watch:function(e,r){return Ie(e,r)},control:Je,formState:ye?new Proxy(pe,{get:(e,r)=>{if(r in e)return Ae.current[r]=!0,e[r]}}):pe,handleSubmit:ze,reset:e.useCallback(((e,t={})=>{if(de)for(const e of Object.values(m.current))if(e){const{ref:t,options:n}=e,s=le(t)&&Array.isArray(n)?n[0].ref:t;if(r(s))try{s.closest("form").reset();break}catch(e){}}m.current={},W.current=ae(e||W.current),e&&Te(""),Object.values(Z.current).forEach((e=>X(e)&&e())),Y.current=g?{}:ae(e)||{},(({errors:e,isDirty:r,isSubmitted:t,touched:n,isValid:s,submitCount:c,dirtyFields:u})=>{s||(N.current={},L.current={}),P.current={},v.current={},j.current=new Set,K.current=!1,xe({submitCount:c?je.current.submitCount:0,isDirty:!!r&&je.current.isDirty,isSubmitted:!!t&&je.current.isSubmitted,isValid:!!s&&je.current.isValid,dirtyFields:u?je.current.dirtyFields:{},touched:n?je.current.touched:{},errors:e?je.current.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})})(t)}),[]),clearErrors:e.useCallback((function(e){e&&(Array.isArray(e)?e:[e]).forEach((e=>m.current[e]?O(e)?delete je.current.errors[e]:R(je.current.errors,e,void 0):H(je.current.errors,e))),xe({errors:e?je.current.errors:{}})}),[]),setError:e.useCallback((function(e,r){const t=(m.current[e]||{}).ref;R(je.current.errors,e,Object.assign(Object.assign({},r),{ref:t})),xe({isValid:!1,errors:je.current.errors}),r.shouldFocus&&t&&t.focus&&t.focus()}),[]),errors:pe.errors},Ge)},exports.useFormContext=me,exports.useWatch=function({control:r,name:t,defaultValue:n}){const s=me(),{useWatchFieldsRef:c,useWatchRenderFunctionsRef:u,watchInternal:i,defaultValuesRef:a}=r||s.control,[o,l]=e.useState(V(n)?I(t)?x(a.current,t):Array.isArray(t)?t.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:x(a.current,r)})),{}):a.current:n),f=e.useRef(),d=e.useRef(n),y=e.useCallback((()=>{const e=i(t,d.current,f.current);l(p(e)?Object.assign({},e):Array.isArray(e)?[...e]:e)}),[l,i,d,t,f]);return e.useEffect((()=>{const e=f.current=he(),r=u.current,n=c.current;return n[e]=new Set,r[e]=y,i(t,d.current,e),()=>{delete n[e],delete r[e]}}),[t,y,u,c,i,d]),V(o)?n:o};
2
2
  //# sourceMappingURL=index.cjs.production.min.js.map