react-hook-form
Advanced tools
Comparing version 7.48.2 to 7.49.3
@@ -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),u=e=>i(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,o=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>{const t=e.constructor&&e.constructor.prototype;return i(t)&&t.hasOwnProperty("isPrototypeOf")},d="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function c(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(d&&(e instanceof Blob||e instanceof FileList)||!r&&!i(e))return e;if(t=r?[]:{},r||l(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=c(e[r]));else t=e}return t}var f=e=>Array.isArray(e)?e.filter(Boolean):[],m=e=>void 0===e,y=(e,t,r)=>{if(!t||!i(e))return r;const s=f(t.split(/[,[\].]+?/)).reduce(((e,t)=>a(e)?e:e[t]),e);return m(s)||s===e?m(e[t])?r:e[t]:s},p=e=>"boolean"==typeof e;const _={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},h={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},g="max",v="min",b="maxLength",x="minLength",A="pattern",V="required",F="validate",S=t.default.createContext(null),w=()=>t.default.useContext(S);var D=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const n in e)Object.defineProperty(a,n,{get:()=>{const a=n;return t._proxyFormState[a]!==h.all&&(t._proxyFormState[a]=!s||h.all),r&&(r[a]=!0),e[a]}});return a},k=e=>i(e)&&!Object.keys(e).length,C=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return k(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||h.all)))},E=e=>Array.isArray(e)?e:[e],O=(e,t,r)=>!e||!t||e===t||E(e).some((e=>e&&(r?e===t:e.startsWith(t)||t.startsWith(e))));function j(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect((()=>{const t=!e.disabled&&r.current.subject&&r.current.subject.subscribe({next:r.current.next});return()=>{t&&t.unsubscribe()}}),[e.disabled])}function T(e){const r=w(),{control:s=r.control,disabled:a,name:n,exact:i}=e||{},[u,o]=t.default.useState(s._formState),l=t.default.useRef(!0),d=t.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=t.default.useRef(n);return c.current=n,j({disabled:a,next:e=>l.current&&O(c.current,e.name,i)&&C(e,d.current,s._updateFormState)&&o({...s._formState,...e}),subject:s._subjects.state}),t.default.useEffect((()=>(l.current=!0,d.current.isValid&&s._updateValid(!0),()=>{l.current=!1})),[s]),D(u,s,d.current,!1)}var U=e=>"string"==typeof e,B=(e,t,r,s,a)=>U(e)?(s&&t.watch.add(e),y(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),y(r,e)))):(s&&(t.watchAll=!0),r);function N(e){const r=w(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=t.default.useRef(a);o.current=a,j({disabled:i,subject:s._subjects.values,next:e=>{O(o.current,e.name,u)&&d(c(B(o.current,s._names,e.values||s._formValues,!1,n)))}});const[l,d]=t.default.useState(s._getWatch(a,n));return t.default.useEffect((()=>s._removeUnmounted())),l}var L=e=>/^\w*$/.test(e),M=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/));function R(e,t,r){let s=-1;const a=L(t)?[t]:M(t),n=a.length,u=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==u){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}function P(e){const r=w(),{name:s,disabled:a,control:n=r.control,shouldUnregister:i}=e,l=o(n._names.array,s),d=N({control:n,name:s,defaultValue:y(n._formValues,s,y(n._defaultValues,s,e.defaultValue)),exact:!0}),f=T({control:n,name:s}),h=t.default.useRef(n.register(s,{...e.rules,value:d}));return h.current=n.register(s,e.rules),t.default.useEffect((()=>{const e=n._options.shouldUnregister||i,t=(e,t)=>{const r=y(n._fields,e);r&&(r._f.mount=t)};if(t(s,!0),e){const e=c(y(n._options.defaultValues,s));R(n._defaultValues,s,e),m(y(n._formValues,s))&&R(n._formValues,s,e)}return()=>{(l?e&&!n._state.action:e)?n.unregister(s):t(s,!1)}}),[s,n,l,i]),t.default.useEffect((()=>{y(n._fields,s)&&n._updateDisabledField({disabled:a,fields:n._fields,name:s,value:y(n._fields,s)._f.value})}),[a,s,n]),{field:{name:s,value:d,...p(a)||p(f.disabled)?{disabled:f.disabled||a}:{},onChange:t.default.useCallback((e=>h.current.onChange({target:{value:u(e),name:s},type:_.CHANGE})),[s]),onBlur:t.default.useCallback((()=>h.current.onBlur({target:{value:y(n._formValues,s),name:s},type:_.BLUR})),[s,n]),ref:e=>{const t=y(n._fields,s);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:f,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!y(f.errors,s)},isDirty:{enumerable:!0,get:()=>!!y(f.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!y(f.touchedFields,s)},error:{enumerable:!0,get:()=>y(f.errors,s)}})}}const q="post";var W=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},I=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},$=(e,t,r={})=>r.shouldFocus||m(r.shouldFocus)?r.focusName||`${e}.${m(r.focusIndex)?t:r.focusIndex}.`:"",H=e=>({isOnSubmit:!e||e===h.onSubmit,isOnBlur:e===h.onBlur,isOnChange:e===h.onChange,isOnAll:e===h.all,isOnTouch:e===h.onTouched}),G=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const J=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=y(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break}else i(n)&&J(n,t)}}};var z=(e,t,r)=>{const s=f(y(e,r));return R(s,"root",t[r]),R(e,r,s),e},K=e=>"file"===e.type,Q=e=>"function"==typeof e,X=e=>{if(!d)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Y=e=>U(e),Z=e=>"radio"===e.type,ee=e=>e instanceof RegExp;const te={value:!1,isValid:!1},re={value:!0,isValid:!0};var se=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!m(e[0].attributes.value)?m(e[0].value)||""===e[0].value?re:{value:e[0].value,isValid:!0}:re:te}return te};const ae={isValid:!1,value:null};var ne=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ae):ae;function ie(e,t,r="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||p(e)&&!e)return{type:r,message:Y(e)?e:"",ref:t}}var ue=e=>i(e)&&!ee(e)?e:{value:e,message:""},oe=async(e,t,s,n,u)=>{const{ref:o,refs:l,required:d,maxLength:c,minLength:f,min:_,max:h,pattern:S,validate:w,name:D,valueAsNumber:C,mount:E,disabled:O}=e._f,j=y(t,D);if(!E||O)return{};const T=l?l[0]:o,B=e=>{n&&T.reportValidity&&(T.setCustomValidity(p(e)?"":e||""),T.reportValidity())},N={},L=Z(o),M=r(o),R=L||M,P=(C||K(o))&&m(o.value)&&m(j)||X(o)&&""===o.value||""===j||Array.isArray(j)&&!j.length,q=W.bind(null,D,s,N),I=(e,t,r,s=b,a=x)=>{const n=e?t:r;N[D]={type:e?s:a,message:n,ref:o,...q(e?s:a,n)}};if(u?!Array.isArray(j)||!j.length:d&&(!R&&(P||a(j))||p(j)&&!j||M&&!se(l).isValid||L&&!ne(l).isValid)){const{value:e,message:t}=Y(d)?{value:!!d,message:d}:ue(d);if(e&&(N[D]={type:V,message:t,ref:T,...q(V,t)},!s))return B(t),N}if(!(P||a(_)&&a(h))){let e,t;const r=ue(h),n=ue(_);if(a(j)||isNaN(j)){const s=o.valueAsDate||new Date(j),a=e=>new Date((new Date).toDateString()+" "+e),i="time"==o.type,u="week"==o.type;U(r.value)&&j&&(e=i?a(j)>a(r.value):u?j>r.value:s>new Date(r.value)),U(n.value)&&j&&(t=i?a(j)<a(n.value):u?j<n.value:s<new Date(n.value))}else{const s=o.valueAsNumber||(j?+j:j);a(r.value)||(e=s>r.value),a(n.value)||(t=s<n.value)}if((e||t)&&(I(!!e,r.message,n.message,g,v),!s))return B(N[D].message),N}if((c||f)&&!P&&(U(j)||u&&Array.isArray(j))){const e=ue(c),t=ue(f),r=!a(e.value)&&j.length>+e.value,n=!a(t.value)&&j.length<+t.value;if((r||n)&&(I(r,e.message,t.message),!s))return B(N[D].message),N}if(S&&!P&&U(j)){const{value:e,message:t}=ue(S);if(ee(e)&&!j.match(e)&&(N[D]={type:A,message:t,ref:o,...q(A,t)},!s))return B(t),N}if(w)if(Q(w)){const e=ie(await w(j,t),T);if(e&&(N[D]={...e,...q(F,e.message)},!s))return B(e.message),N}else if(i(w)){let e={};for(const r in w){if(!k(e)&&!s)break;const a=ie(await w[r](j,t),T,r);a&&(e={...a,...q(r,a.message)},B(a.message),s&&(N[D]=e))}if(!k(e)&&(N[D]={ref:T,...e},!s))return N}return B(!0),N};function le(e,t){return[...e,...E(t)]}var de=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ce(e,t,r){return[...e.slice(0,t),...E(r),...e.slice(t)]}var fe=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function me(e,t){return[...E(t),...E(e)]}var ye=(e,t)=>m(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return f(s).length?s:[]}(e,E(t).sort(((e,t)=>e-t))),pe=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function _e(e,t){const r=Array.isArray(t)?t:L(t)?[t]:M(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=m(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(i(s)&&k(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!m(e[t]))return!1;return!0}(s))&&_e(e,r.slice(0,-1)),e}var he=(e,t,r)=>(e[t]=r,e);function ge(){let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var ve=e=>a(e)||!n(e);function be(e,t){if(ve(e)||ve(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r){const r=e[n];if(!a.includes(n))return!1;if("ref"!==n){const e=t[n];if(s(r)&&s(e)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!be(r,e):r!==e)return!1}}return!0}var xe=e=>"select-multiple"===e.type,Ae=e=>Z(e)||r(e),Ve=e=>X(e)&&e.isConnected,Fe=e=>{for(const t in e)if(Q(e[t]))return!0;return!1};function Se(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!Fe(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Se(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function we(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!Fe(e[s])?m(t)||ve(r[s])?r[s]=Array.isArray(e[s])?Se(e[s],[]):{...Se(e[s])}:we(e[s],a(t)?{}:t[s],r[s]):r[s]=!be(e[s],t[s]);return r}var De=(e,t)=>we(e,t,Se(t)),ke=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&U(e)?new Date(e):s?s(e):e;function Ce(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return K(t)?t.files:Z(t)?ne(e.refs).value:xe(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?se(e.refs).value:ke(m(t.value)?e.ref.value:t.value,e)}var Ee=(e,t,r,s)=>{const a={};for(const r of e){const e=y(t,r);e&&R(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Oe=e=>m(e)?e:ee(e)?e.source:i(e)?ee(e.value)?e.value.source:e.value:e,je=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Te(e,t,r){const s=y(e,r);if(s||L(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=y(t,s),i=y(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Ue=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Be=(e,t)=>!f(y(e,t)).length&&_e(e,t);const Ne={mode:h.onSubmit,reValidateMode:h.onChange,shouldFocusError:!0};function Le(e={},t){let n,l={...Ne,...e},g={submitCount:0,isDirty:!1,isLoading:Q(l.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},v={},b=(i(l.defaultValues)||i(l.values))&&c(l.defaultValues||l.values)||{},x=l.shouldUnregister?{}:c(b),A={action:!1,mount:!1,watch:!1},V={mount:new Set,unMount:new Set,array:new Set,watch:new Set},F=0;const S={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={values:ge(),array:ge(),state:ge()},D=e.resetOptions&&e.resetOptions.keepDirtyValues,C=H(l.mode),O=H(l.reValidateMode),j=l.criteriaMode===h.all,T=async e=>{if(S.isValid||e){const e=l.resolver?k((await q()).errors):await W(v,!0);e!==g.isValid&&w.state.next({isValid:e})}},N=e=>S.isValidating&&w.state.next({isValidating:e}),L=(e,t,r,s)=>{const a=y(v,e);if(a){const n=y(x,e,m(r)?y(b,e):r);m(n)||s&&s.defaultChecked||t?R(x,e,t?n:Ce(a._f)):Y(e,n),A.mount&&T()}},M=(e,t,r,s,a)=>{let n=!1,i=!1;const u={name:e};if(!r||s){S.isDirty&&(i=g.isDirty,g.isDirty=u.isDirty=I(),n=i!==u.isDirty);const r=be(y(b,e),t);i=y(g.dirtyFields,e),r?_e(g.dirtyFields,e):R(g.dirtyFields,e,!0),u.dirtyFields=g.dirtyFields,n=n||S.dirtyFields&&i!==!r}if(r){const t=y(g.touchedFields,e);t||(R(g.touchedFields,e,r),u.touchedFields=g.touchedFields,n=n||S.touchedFields&&t!==r)}return n&&a&&w.state.next(u),n?u:{}},P=(t,r,s,a)=>{const i=y(g.errors,t),u=S.isValid&&p(r)&&g.isValid!==r;var o;if(e.delayError&&s?(o=()=>((e,t)=>{R(g.errors,e,t),w.state.next({errors:g.errors})})(t,s),n=e=>{clearTimeout(F),F=setTimeout(o,e)},n(e.delayError)):(clearTimeout(F),n=null,s?R(g.errors,t,s):_e(g.errors,t)),(s?!be(i,s):i)||!k(a)||u){const e={...a,...u&&p(r)?{isValid:r}:{},errors:g.errors,name:t};g={...g,...e},w.state.next(e)}N(!1)},q=async e=>l.resolver(x,l.context,Ee(e||V.mount,v,l.criteriaMode,l.shouldUseNativeValidation)),W=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=V.array.has(e.name),n=await oe(a,x,j,l.shouldUseNativeValidation&&!t,s);if(n[e.name]&&(r.valid=!1,t))break;!t&&(y(n,e.name)?s?z(g.errors,n,e.name):R(g.errors,e.name,n[e.name]):_e(g.errors,e.name))}s&&await W(s,t,r)}}return r.valid},I=(e,t)=>(e&&t&&R(x,e,t),!be(ae(),b)),$=(e,t,r)=>B(e,V,{...A.mount?x:m(t)?b:U(e)?{[e]:t}:t},r,t),Y=(e,t,s={})=>{const n=y(v,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&R(x,e,ke(t,s)),i=X(s.ref)&&a(t)?"":t,xe(s.ref)?[...s.ref.options].forEach((e=>e.selected=i.includes(e.value))):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(i)?!!i.find((t=>t===e.value)):i===e.value))):s.refs[0]&&(s.refs[0].checked=!!i):s.refs.forEach((e=>e.checked=e.value===i)):K(s.ref)?s.ref.value="":(s.ref.value=i,s.ref.type||w.values.next({name:e,values:{...x}})))}(s.shouldDirty||s.shouldTouch)&&M(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&se(e)},Z=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,u=y(v,i);!V.array.has(e)&&ve(n)&&(!u||u._f)||s(n)?Y(i,n,r):Z(i,n,r)}},ee=(e,r,s={})=>{const n=y(v,e),i=V.array.has(e),u=c(r);R(x,e,u),i?(w.array.next({name:e,values:{...x}}),(S.isDirty||S.dirtyFields)&&s.shouldDirty&&w.state.next({name:e,dirtyFields:De(b,x),isDirty:I(e,u)})):!n||n._f||a(u)?Y(e,u,s):Z(e,u,s),G(e,V)&&w.state.next({...g}),w.values.next({name:e,values:{...x}}),!A.mount&&t()},te=async e=>{const t=e.target;let r=t.name,s=!0;const a=y(v,r),i=e=>{s=Number.isNaN(e)||e===y(x,r,e)};if(a){let o,d;const c=t.type?Ce(a._f):u(e),f=e.type===_.BLUR||e.type===_.FOCUS_OUT,m=!je(a._f)&&!l.resolver&&!y(g.errors,r)&&!a._f.deps||Ue(f,y(g.touchedFields,r),g.isSubmitted,O,C),p=G(r,V,f);R(x,r,c),f?(a._f.onBlur&&a._f.onBlur(e),n&&n(0)):a._f.onChange&&a._f.onChange(e);const h=M(r,c,f,!1),b=!k(h)||p;if(!f&&w.values.next({name:r,type:e.type,values:{...x}}),m)return S.isValid&&T(),b&&w.state.next({name:r,...p?{}:h});if(!f&&p&&w.state.next({...g}),N(!0),l.resolver){const{errors:e}=await q([r]);if(i(c),s){const t=Te(g.errors,v,r),s=Te(e,v,t.name||r);o=s.error,r=s.name,d=k(e)}}else o=(await oe(a,x,j,l.shouldUseNativeValidation))[r],i(c),s&&(o?d=!1:S.isValid&&(d=await W(v,!0)));s&&(a._f.deps&&se(a._f.deps),P(r,d,o,h))}},re=(e,t)=>{if(y(g.errors,t)&&e.focus)return e.focus(),1},se=async(e,t={})=>{let r,s;const a=E(e);if(N(!0),l.resolver){const t=await(async e=>{const{errors:t}=await q(e);if(e)for(const r of e){const e=y(t,r);e?R(g.errors,r,e):_e(g.errors,r)}else g.errors=t;return t})(m(e)?e:a);r=k(t),s=e?!a.some((e=>y(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=y(v,e);return await W(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||g.isValid)&&T()):s=r=await W(v);return w.state.next({...!U(e)||S.isValid&&r!==g.isValid?{}:{name:e},...l.resolver||!e?{isValid:r}:{},errors:g.errors,isValidating:!1}),t.shouldFocus&&!s&&J(v,re,e?a:V.mount),s},ae=e=>{const t={...b,...A.mount?x:{}};return m(e)?t:U(e)?y(t,e):e.map((e=>y(t,e)))},ne=(e,t)=>({invalid:!!y((t||g).errors,e),isDirty:!!y((t||g).dirtyFields,e),isTouched:!!y((t||g).touchedFields,e),error:y((t||g).errors,e)}),ie=(e,t,r)=>{const s=(y(v,e,{_f:{}})._f||{}).ref;R(g.errors,e,{...t,ref:s}),w.state.next({name:e,errors:g.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ue=(e,t={})=>{for(const r of e?E(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(_e(v,r),_e(x,r)),!t.keepError&&_e(g.errors,r),!t.keepDirty&&_e(g.dirtyFields,r),!t.keepTouched&&_e(g.touchedFields,r),!l.shouldUnregister&&!t.keepDefaultValue&&_e(b,r);w.values.next({values:{...x}}),w.state.next({...g,...t.keepDirty?{isDirty:I()}:{}}),!t.keepIsValid&&T()},le=({disabled:e,name:t,field:r,fields:s,value:a})=>{if(p(e)){const n=e?void 0:m(a)?Ce(r?r._f:y(s,t)._f):a;R(x,t,n),M(t,n,!1,!1,!0)}},de=(e,t={})=>{let r=y(v,e);const s=p(t.disabled);return R(v,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?le({field:r,disabled:t.disabled,name:e}):L(e,!0,t.value),{...s?{disabled:t.disabled}:{},...l.progressive?{required:!!t.required,min:Oe(t.min),max:Oe(t.max),minLength:Oe(t.minLength),maxLength:Oe(t.maxLength),pattern:Oe(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:s=>{if(s){de(e,t),r=y(v,e);const a=m(s.value)&&s.querySelectorAll&&s.querySelectorAll("input,select,textarea")[0]||s,n=Ae(a),i=r._f.refs||[];if(n?i.find((e=>e===a)):a===r._f.ref)return;R(v,e,{_f:{...r._f,...n?{refs:[...i.filter(Ve),a,...Array.isArray(y(b,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),L(e,!1,void 0,a)}else r=y(v,e,{}),r._f&&(r._f.mount=!1),(l.shouldUnregister||t.shouldUnregister)&&(!o(V.array,e)||!A.action)&&V.unMount.add(e)}}},ce=()=>l.shouldFocusError&&J(v,re,V.mount),fe=(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let s=c(x);if(w.state.next({isSubmitting:!0}),l.resolver){const{errors:e,values:t}=await q();g.errors=e,s=t}else await W(v);_e(g.errors,"root"),k(g.errors)?(w.state.next({errors:{}}),await e(s,r)):(t&&await t({...g.errors},r),ce(),setTimeout(ce)),w.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:k(g.errors),submitCount:g.submitCount+1,errors:g.errors})},me=(r,s={})=>{const a=r?c(r):b,n=c(a),i=r&&!k(r)?n:b;if(s.keepDefaultValues||(b=a),!s.keepValues){if(s.keepDirtyValues||D)for(const e of V.mount)y(g.dirtyFields,e)?R(i,e,y(x,e)):ee(e,y(i,e));else{if(d&&m(r))for(const e of V.mount){const t=y(v,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(X(e)){const t=e.closest("form");if(t){t.reset();break}}}}v={}}x=e.shouldUnregister?s.keepDefaultValues?c(b):{}:c(i),w.array.next({values:{...i}}),w.values.next({values:{...i}})}V={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!A.mount&&t(),A.mount=!S.isValid||!!s.keepIsValid,A.watch=!!e.shouldUnregister,w.state.next({submitCount:s.keepSubmitCount?g.submitCount:0,isDirty:s.keepDirty?g.isDirty:!(!s.keepDefaultValues||be(r,b)),isSubmitted:!!s.keepIsSubmitted&&g.isSubmitted,dirtyFields:s.keepDirtyValues?g.dirtyFields:s.keepDefaultValues&&r?De(b,r):{},touchedFields:s.keepTouched?g.touchedFields:{},errors:s.keepErrors?g.errors:{},isSubmitSuccessful:!!s.keepIsSubmitSuccessful&&g.isSubmitSuccessful,isSubmitting:!1})},ye=(e,t)=>me(Q(e)?e(x):e,t);return{control:{register:de,unregister:ue,getFieldState:ne,handleSubmit:fe,setError:ie,_executeSchema:q,_getWatch:$,_getDirty:I,_updateValid:T,_removeUnmounted:()=>{for(const e of V.unMount){const t=y(v,e);t&&(t._f.refs?t._f.refs.every((e=>!Ve(e))):!Ve(t._f.ref))&&ue(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(A.action=!0,n&&Array.isArray(y(v,e))){const t=r(y(v,e),s.argA,s.argB);a&&R(v,e,t)}if(n&&Array.isArray(y(g.errors,e))){const t=r(y(g.errors,e),s.argA,s.argB);a&&R(g.errors,e,t),Be(g.errors,e)}if(S.touchedFields&&n&&Array.isArray(y(g.touchedFields,e))){const t=r(y(g.touchedFields,e),s.argA,s.argB);a&&R(g.touchedFields,e,t)}S.dirtyFields&&(g.dirtyFields=De(b,x)),w.state.next({name:e,isDirty:I(e,t),dirtyFields:g.dirtyFields,errors:g.errors,isValid:g.isValid})}else R(x,e,t)},_updateDisabledField:le,_getFieldArray:t=>f(y(A.mount?x:b,t,e.shouldUnregister?y(b,t,[]):[])),_reset:me,_resetDefaultValues:()=>Q(l.defaultValues)&&l.defaultValues().then((e=>{ye(e,l.resetOptions),w.state.next({isLoading:!1})})),_updateFormState:e=>{g={...g,...e}},_disableForm:e=>{p(e)&&(w.state.next({disabled:e}),J(v,(t=>{t.disabled=e}),0,!1))},_subjects:w,_proxyFormState:S,get _fields(){return v},get _formValues(){return x},get _state(){return A},set _state(e){A=e},get _defaultValues(){return b},get _names(){return V},set _names(e){V=e},get _formState(){return g},set _formState(e){g=e},get _options(){return l},set _options(e){l={...l,...e}}},trigger:se,register:de,handleSubmit:fe,watch:(e,t)=>Q(e)?w.values.subscribe({next:r=>e($(void 0,t),r)}):$(e,t,!0),setValue:ee,getValues:ae,reset:ye,resetField:(e,t={})=>{y(v,e)&&(m(t.defaultValue)?ee(e,y(b,e)):(ee(e,t.defaultValue),R(b,e,t.defaultValue)),t.keepTouched||_e(g.touchedFields,e),t.keepDirty||(_e(g.dirtyFields,e),g.isDirty=t.defaultValue?I(e,y(b,e)):I()),t.keepError||(_e(g.errors,e),S.isValid&&T()),w.state.next({...g}))},clearErrors:e=>{e&&E(e).forEach((e=>_e(g.errors,e))),w.state.next({errors:e?g.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=y(v,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.Form=function(e){const r=w(),[s,a]=t.default.useState(!1),{control:n=r.control,onSubmit:i,children:u,action:o,method:l=q,headers:d,encType:c,onError:f,render:m,onSuccess:p,validateStatus:_,...h}=e,g=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,y(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...d,...c?{"Content-Type":c}:{}},body:e?u:a});t&&(_?!_(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):p&&p({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return t.default.useEffect((()=>{a(!0)}),[]),m?t.default.createElement(t.default.Fragment,null,m({submit:g})):t.default.createElement("form",{noValidate:s,action:o,method:l,encType:c,onSubmit:g,...h},u)},exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(S.Provider,{value:s},r)},exports.appendErrors=W,exports.get=y,exports.set=R,exports.useController=P,exports.useFieldArray=function(e){const r=w(),{control:s=r.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map(I)),d=t.default.useRef(u),f=t.default.useRef(a),m=t.default.useRef(!1);f.current=a,d.current=u,s._names.array.add(a),e.rules&&s.register(a,e.rules),j({next:({values:e,name:t})=>{if(t===f.current||!t){const t=y(e,f.current);Array.isArray(t)&&(o(t),l.current=t.map(I))}},subject:s._subjects.array});const p=t.default.useCallback((e=>{m.current=!0,s._updateFieldArray(a,e)}),[s,a]);return t.default.useEffect((()=>{if(s._state.action=!1,G(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!H(s._options.mode).isOnSubmit||s._formState.isSubmitted))if(s._options.resolver)s._executeSchema([a]).then((e=>{const t=y(e.errors,a),r=y(s._formState.errors,a);(r?!t&&r.type||t&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?R(s._formState.errors,a,t):_e(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=y(s._fields,a);e&&e._f&&oe(e,s._formValues,s._options.criteriaMode===h.all,s._options.shouldUseNativeValidation,!0).then((e=>!k(e)&&s._subjects.state.next({errors:z(s._formState.errors,e,a)})))}s._subjects.values.next({name:a,values:{...s._formValues}}),s._names.focus&&J(s._fields,((e,t)=>{if(s._names.focus&&t.startsWith(s._names.focus)&&e.focus)return e.focus(),1})),s._names.focus="",s._updateValid(),m.current=!1}),[u,a,s]),t.default.useEffect((()=>(!y(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||i)&&s.unregister(a)})),[a,s,n,i]),{swap:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);pe(r,e,t),pe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,pe,{argA:e,argB:t},!1)}),[p,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);fe(r,e,t),fe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,fe,{argA:e,argB:t},!1)}),[p,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=E(c(e)),n=me(s._getFieldArray(a),r);s._names.focus=$(a,0,t),l.current=me(l.current,r.map(I)),p(n),o(n),s._updateFieldArray(a,n,me,{argA:de(e)})}),[p,a,s]),append:t.default.useCallback(((e,t)=>{const r=E(c(e)),n=le(s._getFieldArray(a),r);s._names.focus=$(a,n.length-1,t),l.current=le(l.current,r.map(I)),p(n),o(n),s._updateFieldArray(a,n,le,{argA:de(e)})}),[p,a,s]),remove:t.default.useCallback((e=>{const t=ye(s._getFieldArray(a),e);l.current=ye(l.current,e),p(t),o(t),s._updateFieldArray(a,t,ye,{argA:e})}),[p,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=E(c(t)),i=ce(s._getFieldArray(a),e,n);s._names.focus=$(a,e,r),l.current=ce(l.current,e,n.map(I)),p(i),o(i),s._updateFieldArray(a,i,ce,{argA:e,argB:de(t)})}),[p,a,s]),update:t.default.useCallback(((e,t)=>{const r=c(t),n=he(s._getFieldArray(a),e,r);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:I())),p(n),o([...n]),s._updateFieldArray(a,n,he,{argA:e,argB:r},!0,!1)}),[p,a,s]),replace:t.default.useCallback((e=>{const t=E(c(e));l.current=t.map(I),p([...t]),o([...t]),s._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[p,a,s]),fields:t.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||I()})))),[u,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),s=t.default.useRef(),[a,n]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:Q(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Q(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Le(e,(()=>n((e=>({...e}))))),formState:a});const i=r.current.control;return i._options=e,j({subject:i._subjects.state,next:e=>{C(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),t.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),t.default.useEffect((()=>{if(i._proxyFormState.isDirty){const e=i._getDirty();e!==a.isDirty&&i._subjects.state.next({isDirty:e})}}),[i,a.isDirty]),t.default.useEffect((()=>{e.values&&!be(e.values,s.current)?(i._reset(e.values,i._options.resetOptions),s.current=e.values):i._resetDefaultValues()}),[e.values,i]),t.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),r.current.formState=D(a,i),r.current},exports.useFormContext=w,exports.useFormState=T,exports.useWatch=N; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const n=e=>"object"==typeof e;var i=e=>!a(e)&&!Array.isArray(e)&&n(e)&&!s(e),u=e=>i(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,o=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),l=e=>{const t=e.constructor&&e.constructor.prototype;return i(t)&&t.hasOwnProperty("isPrototypeOf")},d="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function c(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(d&&(e instanceof Blob||e instanceof FileList)||!r&&!i(e))return e;if(t=r?[]:{},r||l(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=c(e[r]));else t=e}return t}var f=e=>Array.isArray(e)?e.filter(Boolean):[],m=e=>void 0===e,y=(e,t,r)=>{if(!t||!i(e))return r;const s=f(t.split(/[,[\].]+?/)).reduce(((e,t)=>a(e)?e:e[t]),e);return m(s)||s===e?m(e[t])?r:e[t]:s},p=e=>"boolean"==typeof e;const _={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},h={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},g="max",v="min",b="maxLength",x="minLength",A="pattern",V="required",F="validate",S=t.default.createContext(null),w=()=>t.default.useContext(S);var D=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const n in e)Object.defineProperty(a,n,{get:()=>{const a=n;return t._proxyFormState[a]!==h.all&&(t._proxyFormState[a]=!s||h.all),r&&(r[a]=!0),e[a]}});return a},k=e=>i(e)&&!Object.keys(e).length,C=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return k(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||h.all)))},E=e=>Array.isArray(e)?e:[e],O=(e,t,r)=>!e||!t||e===t||E(e).some((e=>e&&(r?e===t:e.startsWith(t)||t.startsWith(e))));function j(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect((()=>{const t=!e.disabled&&r.current.subject&&r.current.subject.subscribe({next:r.current.next});return()=>{t&&t.unsubscribe()}}),[e.disabled])}function T(e){const r=w(),{control:s=r.control,disabled:a,name:n,exact:i}=e||{},[u,o]=t.default.useState(s._formState),l=t.default.useRef(!0),d=t.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=t.default.useRef(n);return c.current=n,j({disabled:a,next:e=>l.current&&O(c.current,e.name,i)&&C(e,d.current,s._updateFormState)&&o({...s._formState,...e}),subject:s._subjects.state}),t.default.useEffect((()=>(l.current=!0,d.current.isValid&&s._updateValid(!0),()=>{l.current=!1})),[s]),D(u,s,d.current,!1)}var U=e=>"string"==typeof e,B=(e,t,r,s,a)=>U(e)?(s&&t.watch.add(e),y(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),y(r,e)))):(s&&(t.watchAll=!0),r);function N(e){const r=w(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=t.default.useRef(a);o.current=a,j({disabled:i,subject:s._subjects.values,next:e=>{O(o.current,e.name,u)&&d(c(B(o.current,s._names,e.values||s._formValues,!1,n)))}});const[l,d]=t.default.useState(s._getWatch(a,n));return t.default.useEffect((()=>s._removeUnmounted())),l}var L=e=>/^\w*$/.test(e),M=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/)),R=(e,t,r)=>{let s=-1;const a=L(t)?[t]:M(t),n=a.length,u=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==u){const r=e[t];n=i(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e};function P(e){const r=w(),{name:s,disabled:a,control:n=r.control,shouldUnregister:i}=e,l=o(n._names.array,s),d=N({control:n,name:s,defaultValue:y(n._formValues,s,y(n._defaultValues,s,e.defaultValue)),exact:!0}),f=T({control:n,name:s}),h=t.default.useRef(n.register(s,{...e.rules,value:d,...p(e.disabled)?{disabled:e.disabled}:{}}));return t.default.useEffect((()=>{const e=n._options.shouldUnregister||i,t=(e,t)=>{const r=y(n._fields,e);r&&(r._f.mount=t)};if(t(s,!0),e){const e=c(y(n._options.defaultValues,s));R(n._defaultValues,s,e),m(y(n._formValues,s))&&R(n._formValues,s,e)}return()=>{(l?e&&!n._state.action:e)?n.unregister(s):t(s,!1)}}),[s,n,l,i]),t.default.useEffect((()=>{y(n._fields,s)&&n._updateDisabledField({disabled:a,fields:n._fields,name:s,value:y(n._fields,s)._f.value})}),[a,s,n]),{field:{name:s,value:d,...p(a)||f.disabled?{disabled:f.disabled||a}:{},onChange:t.default.useCallback((e=>h.current.onChange({target:{value:u(e),name:s},type:_.CHANGE})),[s]),onBlur:t.default.useCallback((()=>h.current.onBlur({target:{value:y(n._formValues,s),name:s},type:_.BLUR})),[s,n]),ref:e=>{const t=y(n._fields,s);t&&e&&(t._f.ref={focus:()=>e.focus(),select:()=>e.select(),setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}},formState:f,fieldState:Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!y(f.errors,s)},isDirty:{enumerable:!0,get:()=>!!y(f.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!y(f.touchedFields,s)},error:{enumerable:!0,get:()=>y(f.errors,s)}})}}const q="post";var W=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},I=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},$=(e,t,r={})=>r.shouldFocus||m(r.shouldFocus)?r.focusName||`${e}.${m(r.focusIndex)?t:r.focusIndex}.`:"",H=e=>({isOnSubmit:!e||e===h.onSubmit,isOnBlur:e===h.onBlur,isOnChange:e===h.onChange,isOnAll:e===h.all,isOnTouch:e===h.onTouched}),G=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const J=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=y(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break;J(n,t)}else i(n)&&J(n,t)}}};var z=(e,t,r)=>{const s=f(y(e,r));return R(s,"root",t[r]),R(e,r,s),e},K=e=>"file"===e.type,Q=e=>"function"==typeof e,X=e=>{if(!d)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Y=e=>U(e),Z=e=>"radio"===e.type,ee=e=>e instanceof RegExp;const te={value:!1,isValid:!1},re={value:!0,isValid:!0};var se=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!m(e[0].attributes.value)?m(e[0].value)||""===e[0].value?re:{value:e[0].value,isValid:!0}:re:te}return te};const ae={isValid:!1,value:null};var ne=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ae):ae;function ie(e,t,r="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||p(e)&&!e)return{type:r,message:Y(e)?e:"",ref:t}}var ue=e=>i(e)&&!ee(e)?e:{value:e,message:""},oe=async(e,t,s,n,u)=>{const{ref:o,refs:l,required:d,maxLength:c,minLength:f,min:_,max:h,pattern:S,validate:w,name:D,valueAsNumber:C,mount:E,disabled:O}=e._f,j=y(t,D);if(!E||O)return{};const T=l?l[0]:o,B=e=>{n&&T.reportValidity&&(T.setCustomValidity(p(e)?"":e||""),T.reportValidity())},N={},L=Z(o),M=r(o),R=L||M,P=(C||K(o))&&m(o.value)&&m(j)||X(o)&&""===o.value||""===j||Array.isArray(j)&&!j.length,q=W.bind(null,D,s,N),I=(e,t,r,s=b,a=x)=>{const n=e?t:r;N[D]={type:e?s:a,message:n,ref:o,...q(e?s:a,n)}};if(u?!Array.isArray(j)||!j.length:d&&(!R&&(P||a(j))||p(j)&&!j||M&&!se(l).isValid||L&&!ne(l).isValid)){const{value:e,message:t}=Y(d)?{value:!!d,message:d}:ue(d);if(e&&(N[D]={type:V,message:t,ref:T,...q(V,t)},!s))return B(t),N}if(!(P||a(_)&&a(h))){let e,t;const r=ue(h),n=ue(_);if(a(j)||isNaN(j)){const s=o.valueAsDate||new Date(j),a=e=>new Date((new Date).toDateString()+" "+e),i="time"==o.type,u="week"==o.type;U(r.value)&&j&&(e=i?a(j)>a(r.value):u?j>r.value:s>new Date(r.value)),U(n.value)&&j&&(t=i?a(j)<a(n.value):u?j<n.value:s<new Date(n.value))}else{const s=o.valueAsNumber||(j?+j:j);a(r.value)||(e=s>r.value),a(n.value)||(t=s<n.value)}if((e||t)&&(I(!!e,r.message,n.message,g,v),!s))return B(N[D].message),N}if((c||f)&&!P&&(U(j)||u&&Array.isArray(j))){const e=ue(c),t=ue(f),r=!a(e.value)&&j.length>+e.value,n=!a(t.value)&&j.length<+t.value;if((r||n)&&(I(r,e.message,t.message),!s))return B(N[D].message),N}if(S&&!P&&U(j)){const{value:e,message:t}=ue(S);if(ee(e)&&!j.match(e)&&(N[D]={type:A,message:t,ref:o,...q(A,t)},!s))return B(t),N}if(w)if(Q(w)){const e=ie(await w(j,t),T);if(e&&(N[D]={...e,...q(F,e.message)},!s))return B(e.message),N}else if(i(w)){let e={};for(const r in w){if(!k(e)&&!s)break;const a=ie(await w[r](j,t),T,r);a&&(e={...a,...q(r,a.message)},B(a.message),s&&(N[D]=e))}if(!k(e)&&(N[D]={ref:T,...e},!s))return N}return B(!0),N},le=(e,t)=>[...e,...E(t)],de=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ce(e,t,r){return[...e.slice(0,t),...E(r),...e.slice(t)]}var fe=(e,t,r)=>Array.isArray(e)?(m(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[],me=(e,t)=>[...E(t),...E(e)];var ye=(e,t)=>m(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return f(s).length?s:[]}(e,E(t).sort(((e,t)=>e-t))),pe=(e,t,r)=>{[e[t],e[r]]=[e[r],e[t]]};function _e(e,t){const r=Array.isArray(t)?t:L(t)?[t]:M(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=m(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(i(s)&&k(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!m(e[t]))return!1;return!0}(s))&&_e(e,r.slice(0,-1)),e}var he=(e,t,r)=>(e[t]=r,e);var ge=()=>{let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}},ve=e=>a(e)||!n(e);function be(e,t){if(ve(e)||ve(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(const n of r){const r=e[n];if(!a.includes(n))return!1;if("ref"!==n){const e=t[n];if(s(r)&&s(e)||i(r)&&i(e)||Array.isArray(r)&&Array.isArray(e)?!be(r,e):r!==e)return!1}}return!0}var xe=e=>"select-multiple"===e.type,Ae=e=>Z(e)||r(e),Ve=e=>X(e)&&e.isConnected,Fe=e=>{for(const t in e)if(Q(e[t]))return!0;return!1};function Se(e,t={}){const r=Array.isArray(e);if(i(e)||r)for(const r in e)Array.isArray(e[r])||i(e[r])&&!Fe(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Se(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function we(e,t,r){const s=Array.isArray(e);if(i(e)||s)for(const s in e)Array.isArray(e[s])||i(e[s])&&!Fe(e[s])?m(t)||ve(r[s])?r[s]=Array.isArray(e[s])?Se(e[s],[]):{...Se(e[s])}:we(e[s],a(t)?{}:t[s],r[s]):r[s]=!be(e[s],t[s]);return r}var De=(e,t)=>we(e,t,Se(t)),ke=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>m(e)?e:t?""===e?NaN:e?+e:e:r&&U(e)?new Date(e):s?s(e):e;function Ce(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return K(t)?t.files:Z(t)?ne(e.refs).value:xe(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?se(e.refs).value:ke(m(t.value)?e.ref.value:t.value,e)}var Ee=(e,t,r,s)=>{const a={};for(const r of e){const e=y(t,r);e&&R(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Oe=e=>m(e)?e:ee(e)?e.source:i(e)?ee(e.value)?e.value.source:e.value:e,je=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Te(e,t,r){const s=y(e,r);if(s||L(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=y(t,s),i=y(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Ue=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Be=(e,t)=>!f(y(e,t)).length&&_e(e,t);const Ne={mode:h.onSubmit,reValidateMode:h.onChange,shouldFocusError:!0};function Le(e={},t){let n,l={...Ne,...e},g={submitCount:0,isDirty:!1,isLoading:Q(l.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:l.errors||{},disabled:l.disabled||!1},v={},b=(i(l.defaultValues)||i(l.values))&&c(l.defaultValues||l.values)||{},x=l.shouldUnregister?{}:c(b),A={action:!1,mount:!1,watch:!1},V={mount:new Set,unMount:new Set,array:new Set,watch:new Set},F=0;const S={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={values:ge(),array:ge(),state:ge()},D=H(l.mode),C=H(l.reValidateMode),O=l.criteriaMode===h.all,j=async e=>{if(S.isValid||e){const e=l.resolver?k((await P()).errors):await q(v,!0);e!==g.isValid&&w.state.next({isValid:e})}},T=e=>S.isValidating&&w.state.next({isValidating:e}),N=(e,t,r,s)=>{const a=y(v,e);if(a){const n=y(x,e,m(r)?y(b,e):r);m(n)||s&&s.defaultChecked||t?R(x,e,t?n:Ce(a._f)):$(e,n),A.mount&&j()}},L=(e,t,r,s,a)=>{let n=!1,i=!1;const u={name:e},o=!(!y(v,e)||!y(v,e)._f.disabled);if(!r||s){S.isDirty&&(i=g.isDirty,g.isDirty=u.isDirty=W(),n=i!==u.isDirty);const r=o||be(y(b,e),t);i=!(o||!y(g.dirtyFields,e)),r||o?_e(g.dirtyFields,e):R(g.dirtyFields,e,!0),u.dirtyFields=g.dirtyFields,n=n||S.dirtyFields&&i!==!r}if(r){const t=y(g.touchedFields,e);t||(R(g.touchedFields,e,r),u.touchedFields=g.touchedFields,n=n||S.touchedFields&&t!==r)}return n&&a&&w.state.next(u),n?u:{}},M=(t,r,s,a)=>{const i=y(g.errors,t),u=S.isValid&&p(r)&&g.isValid!==r;var o;if(e.delayError&&s?(o=()=>((e,t)=>{R(g.errors,e,t),w.state.next({errors:g.errors})})(t,s),n=e=>{clearTimeout(F),F=setTimeout(o,e)},n(e.delayError)):(clearTimeout(F),n=null,s?R(g.errors,t,s):_e(g.errors,t)),(s?!be(i,s):i)||!k(a)||u){const e={...a,...u&&p(r)?{isValid:r}:{},errors:g.errors,name:t};g={...g,...e},w.state.next(e)}T(!1)},P=async e=>l.resolver(x,l.context,Ee(e||V.mount,v,l.criteriaMode,l.shouldUseNativeValidation)),q=async(e,t,r={valid:!0})=>{for(const s in e){const a=e[s];if(a){const{_f:e,...s}=a;if(e){const s=V.array.has(e.name),n=await oe(a,x,O,l.shouldUseNativeValidation&&!t,s);if(n[e.name]&&(r.valid=!1,t))break;!t&&(y(n,e.name)?s?z(g.errors,n,e.name):R(g.errors,e.name,n[e.name]):_e(g.errors,e.name))}s&&await q(s,t,r)}}return r.valid},W=(e,t)=>(e&&t&&R(x,e,t),!be(se(),b)),I=(e,t,r)=>B(e,V,{...A.mount?x:m(t)?b:U(e)?{[e]:t}:t},r,t),$=(e,t,s={})=>{const n=y(v,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&R(x,e,ke(t,s)),i=X(s.ref)&&a(t)?"":t,xe(s.ref)?[...s.ref.options].forEach((e=>e.selected=i.includes(e.value))):s.refs?r(s.ref)?s.refs.length>1?s.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(i)?!!i.find((t=>t===e.value)):i===e.value))):s.refs[0]&&(s.refs[0].checked=!!i):s.refs.forEach((e=>e.checked=e.value===i)):K(s.ref)?s.ref.value="":(s.ref.value=i,s.ref.type||w.values.next({name:e,values:{...x}})))}(s.shouldDirty||s.shouldTouch)&&L(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&re(e)},Y=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,u=y(v,i);!V.array.has(e)&&ve(n)&&(!u||u._f)||s(n)?$(i,n,r):Y(i,n,r)}},Z=(e,r,s={})=>{const n=y(v,e),i=V.array.has(e),u=c(r);R(x,e,u),i?(w.array.next({name:e,values:{...x}}),(S.isDirty||S.dirtyFields)&&s.shouldDirty&&w.state.next({name:e,dirtyFields:De(b,x),isDirty:W(e,u)})):!n||n._f||a(u)?$(e,u,s):Y(e,u,s),G(e,V)&&w.state.next({...g}),w.values.next({name:e,values:{...x}}),!A.mount&&t()},ee=async e=>{const t=e.target;let r=t.name,s=!0;const a=y(v,r),i=e=>{s=Number.isNaN(e)||e===y(x,r,e)};if(a){let o,d;const c=t.type?Ce(a._f):u(e),f=e.type===_.BLUR||e.type===_.FOCUS_OUT,m=!je(a._f)&&!l.resolver&&!y(g.errors,r)&&!a._f.deps||Ue(f,y(g.touchedFields,r),g.isSubmitted,C,D),p=G(r,V,f);R(x,r,c),f?(a._f.onBlur&&a._f.onBlur(e),n&&n(0)):a._f.onChange&&a._f.onChange(e);const h=L(r,c,f,!1),b=!k(h)||p;if(!f&&w.values.next({name:r,type:e.type,values:{...x}}),m)return S.isValid&&j(),b&&w.state.next({name:r,...p?{}:h});if(!f&&p&&w.state.next({...g}),T(!0),l.resolver){const{errors:e}=await P([r]);if(i(c),s){const t=Te(g.errors,v,r),s=Te(e,v,t.name||r);o=s.error,r=s.name,d=k(e)}}else o=(await oe(a,x,O,l.shouldUseNativeValidation))[r],i(c),s&&(o?d=!1:S.isValid&&(d=await q(v,!0)));s&&(a._f.deps&&re(a._f.deps),M(r,d,o,h))}},te=(e,t)=>{if(y(g.errors,t)&&e.focus)return e.focus(),1},re=async(e,t={})=>{let r,s;const a=E(e);if(T(!0),l.resolver){const t=await(async e=>{const{errors:t}=await P(e);if(e)for(const r of e){const e=y(t,r);e?R(g.errors,r,e):_e(g.errors,r)}else g.errors=t;return t})(m(e)?e:a);r=k(t),s=e?!a.some((e=>y(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=y(v,e);return await q(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||g.isValid)&&j()):s=r=await q(v);return w.state.next({...!U(e)||S.isValid&&r!==g.isValid?{}:{name:e},...l.resolver||!e?{isValid:r}:{},errors:g.errors,isValidating:!1}),t.shouldFocus&&!s&&J(v,te,e?a:V.mount),s},se=e=>{const t={...b,...A.mount?x:{}};return m(e)?t:U(e)?y(t,e):e.map((e=>y(t,e)))},ae=(e,t)=>({invalid:!!y((t||g).errors,e),isDirty:!!y((t||g).dirtyFields,e),isTouched:!!y((t||g).touchedFields,e),error:y((t||g).errors,e)}),ne=(e,t,r)=>{const s=(y(v,e,{_f:{}})._f||{}).ref;R(g.errors,e,{...t,ref:s}),w.state.next({name:e,errors:g.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ie=(e,t={})=>{for(const r of e?E(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(_e(v,r),_e(x,r)),!t.keepError&&_e(g.errors,r),!t.keepDirty&&_e(g.dirtyFields,r),!t.keepTouched&&_e(g.touchedFields,r),!l.shouldUnregister&&!t.keepDefaultValue&&_e(b,r);w.values.next({values:{...x}}),w.state.next({...g,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&j()},ue=({disabled:e,name:t,field:r,fields:s,value:a})=>{if(p(e)){const n=e?void 0:m(a)?Ce(r?r._f:y(s,t)._f):a;R(x,t,n),L(t,n,!1,!1,!0)}},le=(e,t={})=>{let r=y(v,e);const s=p(t.disabled);return R(v,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?ue({field:r,disabled:t.disabled,name:e,value:t.value}):N(e,!0,t.value),{...s?{disabled:t.disabled}:{},...l.progressive?{required:!!t.required,min:Oe(t.min),max:Oe(t.max),minLength:Oe(t.minLength),maxLength:Oe(t.maxLength),pattern:Oe(t.pattern)}:{},name:e,onChange:ee,onBlur:ee,ref:s=>{if(s){le(e,t),r=y(v,e);const a=m(s.value)&&s.querySelectorAll&&s.querySelectorAll("input,select,textarea")[0]||s,n=Ae(a),i=r._f.refs||[];if(n?i.find((e=>e===a)):a===r._f.ref)return;R(v,e,{_f:{...r._f,...n?{refs:[...i.filter(Ve),a,...Array.isArray(y(b,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),N(e,!1,void 0,a)}else r=y(v,e,{}),r._f&&(r._f.mount=!1),(l.shouldUnregister||t.shouldUnregister)&&(!o(V.array,e)||!A.action)&&V.unMount.add(e)}}},de=()=>l.shouldFocusError&&J(v,te,V.mount),ce=(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let s=c(x);if(w.state.next({isSubmitting:!0}),l.resolver){const{errors:e,values:t}=await P();g.errors=e,s=t}else await q(v);_e(g.errors,"root"),k(g.errors)?(w.state.next({errors:{}}),await e(s,r)):(t&&await t({...g.errors},r),de(),setTimeout(de)),w.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:k(g.errors),submitCount:g.submitCount+1,errors:g.errors})},fe=(r,s={})=>{const a=r?c(r):b,n=c(a),i=r&&!k(r)?n:b;if(s.keepDefaultValues||(b=a),!s.keepValues){if(s.keepDirtyValues)for(const e of V.mount)y(g.dirtyFields,e)?R(i,e,y(x,e)):Z(e,y(i,e));else{if(d&&m(r))for(const e of V.mount){const t=y(v,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(X(e)){const t=e.closest("form");if(t){t.reset();break}}}}v={}}x=e.shouldUnregister?s.keepDefaultValues?c(b):{}:c(i),w.array.next({values:{...i}}),w.values.next({values:{...i}})}V={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!A.mount&&t(),A.mount=!S.isValid||!!s.keepIsValid,A.watch=!!e.shouldUnregister,w.state.next({submitCount:s.keepSubmitCount?g.submitCount:0,isDirty:s.keepDirty?g.isDirty:!(!s.keepDefaultValues||be(r,b)),isSubmitted:!!s.keepIsSubmitted&&g.isSubmitted,dirtyFields:s.keepDirtyValues?g.dirtyFields:s.keepDefaultValues&&r?De(b,r):{},touchedFields:s.keepTouched?g.touchedFields:{},errors:s.keepErrors?g.errors:{},isSubmitSuccessful:!!s.keepIsSubmitSuccessful&&g.isSubmitSuccessful,isSubmitting:!1})},me=(e,t)=>fe(Q(e)?e(x):e,t);return{control:{register:le,unregister:ie,getFieldState:ae,handleSubmit:ce,setError:ne,_executeSchema:P,_getWatch:I,_getDirty:W,_updateValid:j,_removeUnmounted:()=>{for(const e of V.unMount){const t=y(v,e);t&&(t._f.refs?t._f.refs.every((e=>!Ve(e))):!Ve(t._f.ref))&&ie(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(A.action=!0,n&&Array.isArray(y(v,e))){const t=r(y(v,e),s.argA,s.argB);a&&R(v,e,t)}if(n&&Array.isArray(y(g.errors,e))){const t=r(y(g.errors,e),s.argA,s.argB);a&&R(g.errors,e,t),Be(g.errors,e)}if(S.touchedFields&&n&&Array.isArray(y(g.touchedFields,e))){const t=r(y(g.touchedFields,e),s.argA,s.argB);a&&R(g.touchedFields,e,t)}S.dirtyFields&&(g.dirtyFields=De(b,x)),w.state.next({name:e,isDirty:W(e,t),dirtyFields:g.dirtyFields,errors:g.errors,isValid:g.isValid})}else R(x,e,t)},_updateDisabledField:ue,_getFieldArray:t=>f(y(A.mount?x:b,t,e.shouldUnregister?y(b,t,[]):[])),_reset:fe,_resetDefaultValues:()=>Q(l.defaultValues)&&l.defaultValues().then((e=>{me(e,l.resetOptions),w.state.next({isLoading:!1})})),_updateFormState:e=>{g={...g,...e}},_disableForm:e=>{p(e)&&(w.state.next({disabled:e}),J(v,((t,r)=>{let s=e;const a=y(v,r);a&&p(a._f.disabled)&&(s||(s=a._f.disabled)),t.disabled=s}),0,!1))},_subjects:w,_proxyFormState:S,_setErrors:e=>{g.errors=e,w.state.next({errors:g.errors,isValid:!1})},get _fields(){return v},get _formValues(){return x},get _state(){return A},set _state(e){A=e},get _defaultValues(){return b},get _names(){return V},set _names(e){V=e},get _formState(){return g},set _formState(e){g=e},get _options(){return l},set _options(e){l={...l,...e}}},trigger:re,register:le,handleSubmit:ce,watch:(e,t)=>Q(e)?w.values.subscribe({next:r=>e(I(void 0,t),r)}):I(e,t,!0),setValue:Z,getValues:se,reset:me,resetField:(e,t={})=>{y(v,e)&&(m(t.defaultValue)?Z(e,c(y(b,e))):(Z(e,t.defaultValue),R(b,e,c(t.defaultValue))),t.keepTouched||_e(g.touchedFields,e),t.keepDirty||(_e(g.dirtyFields,e),g.isDirty=t.defaultValue?W(e,c(y(b,e))):W()),t.keepError||(_e(g.errors,e),S.isValid&&j()),w.state.next({...g}))},clearErrors:e=>{e&&E(e).forEach((e=>_e(g.errors,e))),w.state.next({errors:e?g.errors:{}})},unregister:ie,setError:ne,setFocus:(e,t={})=>{const r=y(v,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ae}}exports.Controller=e=>e.render(P(e)),exports.Form=function(e){const r=w(),[s,a]=t.default.useState(!1),{control:n=r.control,onSubmit:i,children:u,action:o,method:l=q,headers:d,encType:c,onError:f,render:m,onSuccess:p,validateStatus:_,...h}=e,g=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,y(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...d,...c?{"Content-Type":c}:{}},body:e?u:a});t&&(_?!_(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):p&&p({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return t.default.useEffect((()=>{a(!0)}),[]),m?t.default.createElement(t.default.Fragment,null,m({submit:g})):t.default.createElement("form",{noValidate:s,action:o,method:l,encType:c,onSubmit:g,...h},u)},exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(S.Provider,{value:s},r)},exports.appendErrors=W,exports.get=y,exports.set=R,exports.useController=P,exports.useFieldArray=function(e){const r=w(),{control:s=r.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=t.default.useState(s._getFieldArray(a)),l=t.default.useRef(s._getFieldArray(a).map(I)),d=t.default.useRef(u),f=t.default.useRef(a),m=t.default.useRef(!1);f.current=a,d.current=u,s._names.array.add(a),e.rules&&s.register(a,e.rules),j({next:({values:e,name:t})=>{if(t===f.current||!t){const t=y(e,f.current);Array.isArray(t)&&(o(t),l.current=t.map(I))}},subject:s._subjects.array});const p=t.default.useCallback((e=>{m.current=!0,s._updateFieldArray(a,e)}),[s,a]);return t.default.useEffect((()=>{if(s._state.action=!1,G(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!H(s._options.mode).isOnSubmit||s._formState.isSubmitted))if(s._options.resolver)s._executeSchema([a]).then((e=>{const t=y(e.errors,a),r=y(s._formState.errors,a);(r?!t&&r.type||t&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?R(s._formState.errors,a,t):_e(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=y(s._fields,a);e&&e._f&&oe(e,s._formValues,s._options.criteriaMode===h.all,s._options.shouldUseNativeValidation,!0).then((e=>!k(e)&&s._subjects.state.next({errors:z(s._formState.errors,e,a)})))}s._subjects.values.next({name:a,values:{...s._formValues}}),s._names.focus&&J(s._fields,((e,t)=>{if(s._names.focus&&t.startsWith(s._names.focus)&&e.focus)return e.focus(),1})),s._names.focus="",s._updateValid(),m.current=!1}),[u,a,s]),t.default.useEffect((()=>(!y(s._formValues,a)&&s._updateFieldArray(a),()=>{(s._options.shouldUnregister||i)&&s.unregister(a)})),[a,s,n,i]),{swap:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);pe(r,e,t),pe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,pe,{argA:e,argB:t},!1)}),[p,a,s]),move:t.default.useCallback(((e,t)=>{const r=s._getFieldArray(a);fe(r,e,t),fe(l.current,e,t),p(r),o(r),s._updateFieldArray(a,r,fe,{argA:e,argB:t},!1)}),[p,a,s]),prepend:t.default.useCallback(((e,t)=>{const r=E(c(e)),n=me(s._getFieldArray(a),r);s._names.focus=$(a,0,t),l.current=me(l.current,r.map(I)),p(n),o(n),s._updateFieldArray(a,n,me,{argA:de(e)})}),[p,a,s]),append:t.default.useCallback(((e,t)=>{const r=E(c(e)),n=le(s._getFieldArray(a),r);s._names.focus=$(a,n.length-1,t),l.current=le(l.current,r.map(I)),p(n),o(n),s._updateFieldArray(a,n,le,{argA:de(e)})}),[p,a,s]),remove:t.default.useCallback((e=>{const t=ye(s._getFieldArray(a),e);l.current=ye(l.current,e),p(t),o(t),s._updateFieldArray(a,t,ye,{argA:e})}),[p,a,s]),insert:t.default.useCallback(((e,t,r)=>{const n=E(c(t)),i=ce(s._getFieldArray(a),e,n);s._names.focus=$(a,e,r),l.current=ce(l.current,e,n.map(I)),p(i),o(i),s._updateFieldArray(a,i,ce,{argA:e,argB:de(t)})}),[p,a,s]),update:t.default.useCallback(((e,t)=>{const r=c(t),n=he(s._getFieldArray(a),e,r);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:I())),p(n),o([...n]),s._updateFieldArray(a,n,he,{argA:e,argB:r},!0,!1)}),[p,a,s]),replace:t.default.useCallback((e=>{const t=E(c(e));l.current=t.map(I),p([...t]),o([...t]),s._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[p,a,s]),fields:t.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||I()})))),[u,n])}},exports.useForm=function(e={}){const r=t.default.useRef(),s=t.default.useRef(),[a,n]=t.default.useState({isDirty:!1,isValidating:!1,isLoading:Q(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Q(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Le(e,(()=>n((e=>({...e}))))),formState:a});const i=r.current.control;return i._options=e,j({subject:i._subjects.state,next:e=>{C(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),t.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),t.default.useEffect((()=>{if(i._proxyFormState.isDirty){const e=i._getDirty();e!==a.isDirty&&i._subjects.state.next({isDirty:e})}}),[i,a.isDirty]),t.default.useEffect((()=>{e.values&&!be(e.values,s.current)?(i._reset(e.values,i._options.resetOptions),s.current=e.values,n((e=>({...e})))):i._resetDefaultValues()}),[e.values,i]),t.default.useEffect((()=>{e.errors&&i._setErrors(e.errors)}),[e.errors,i]),t.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),r.current.formState=D(a,i),r.current},exports.useFormContext=w,exports.useFormState=T,exports.useWatch=N; | ||
//# 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 u=e=>"object"==typeof e;var o=e=>!i(e)&&!Array.isArray(e)&&u(e)&&!n(e),l=e=>o(e)&&e.target?a(e.target)?e.target.checked:e.target.value:e,d=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),c=e=>{const t=e.constructor&&e.constructor.prototype;return o(t)&&t.hasOwnProperty("isPrototypeOf")},f="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function m(e){let t;const r=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else{if(f&&(e instanceof Blob||e instanceof FileList)||!r&&!o(e))return e;if(t=r?[]:{},r||c(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=m(e[r]));else t=e}return t}var y=e=>Array.isArray(e)?e.filter(Boolean):[],p=e=>void 0===e,_=(e,t,r)=>{if(!t||!o(e))return r;const s=y(t.split(/[,[\].]+?/)).reduce(((e,t)=>i(e)?e:e[t]),e);return p(s)||s===e?p(e[t])?r:e[t]:s},h=e=>"boolean"==typeof e;const g={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},v={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},b="max",A="min",x="maxLength",V="minLength",F="pattern",S="required",w="validate",D=s.default.createContext(null),k=()=>s.default.useContext(D);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.all&&(t._proxyFormState[a]=!s||v.all),r&&(r[a]=!0),e[a]}});return a},E=e=>o(e)&&!Object.keys(e).length,O=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return E(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||v.all)))},j=e=>Array.isArray(e)?e:[e],T=(e,t,r)=>!e||!t||e===t||j(e).some((e=>e&&(r?e===t:e.startsWith(t)||t.startsWith(e))));function U(e){const t=s.default.useRef(e);t.current=e,s.default.useEffect((()=>{const r=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}}),[e.disabled])}function B(e){const t=k(),{control:r=t.control,disabled:a,name:n,exact:i}=e||{},[u,o]=s.default.useState(r._formState),l=s.default.useRef(!0),d=s.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=s.default.useRef(n);return c.current=n,U({disabled:a,next:e=>l.current&&T(c.current,e.name,i)&&O(e,d.current,r._updateFormState)&&o({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>(l.current=!0,d.current.isValid&&r._updateValid(!0),()=>{l.current=!1})),[r]),C(u,r,d.current,!1)}var N=e=>"string"==typeof e,L=(e,t,r,s,a)=>N(e)?(s&&t.watch.add(e),_(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),_(r,e)))):(s&&(t.watchAll=!0),r);function R(e){const t=k(),{control:r=t.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=s.default.useRef(a);o.current=a,U({disabled:i,subject:r._subjects.values,next:e=>{T(o.current,e.name,u)&&d(m(L(o.current,r._names,e.values||r._formValues,!1,n)))}});const[l,d]=s.default.useState(r._getWatch(a,n));return s.default.useEffect((()=>r._removeUnmounted())),l}var M=e=>/^\w*$/.test(e),P=e=>y(e.replace(/["|']|\]/g,"").split(/\.|\[/));function q(e,t,r){let s=-1;const a=M(t)?[t]:P(t),n=a.length,i=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==i){const r=e[t];n=o(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e}function W(e){const t=k(),{name:r,disabled:a,control:n=t.control,shouldUnregister:i}=e,u=d(n._names.array,r),o=R({control:n,name:r,defaultValue:_(n._formValues,r,_(n._defaultValues,r,e.defaultValue)),exact:!0}),c=B({control:n,name:r}),f=s.default.useRef(n.register(r,{...e.rules,value:o}));return f.current=n.register(r,e.rules),s.default.useEffect((()=>{const e=n._options.shouldUnregister||i,t=(e,t)=>{const r=_(n._fields,e);r&&(r._f.mount=t)};if(t(r,!0),e){const e=m(_(n._options.defaultValues,r));q(n._defaultValues,r,e),p(_(n._formValues,r))&&q(n._formValues,r,e)}return()=>{(u?e&&!n._state.action:e)?n.unregister(r):t(r,!1)}}),[r,n,u,i]),s.default.useEffect((()=>{_(n._fields,r)&&n._updateDisabledField({disabled:a,fields:n._fields,name:r,value:_(n._fields,r)._f.value})}),[a,r,n]),{field:{name:r,value:o,...h(a)||h(c.disabled)?{disabled:c.disabled||a}:{},onChange:s.default.useCallback((e=>f.current.onChange({target:{value:l(e),name:r},type:g.CHANGE})),[r]),onBlur:s.default.useCallback((()=>f.current.onBlur({target:{value:_(n._formValues,r),name:r},type:g.BLUR})),[r,n]),ref:e=>{const t=_(n._fields,r);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:()=>!!_(c.errors,r)},isDirty:{enumerable:!0,get:()=>!!_(c.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!_(c.touchedFields,r)},error:{enumerable:!0,get:()=>_(c.errors,r)}})}}const H="post";var I=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},$=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},G=(e,t,r={})=>r.shouldFocus||p(r.shouldFocus)?r.focusName||`${e}.${p(r.focusIndex)?t:r.focusIndex}.`:"",J=e=>({isOnSubmit:!e||e===v.onSubmit,isOnBlur:e===v.onBlur,isOnChange:e===v.onChange,isOnAll:e===v.all,isOnTouch:e===v.onTouched}),z=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const K=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=_(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break}else o(n)&&K(n,t)}}};var Q=(e,t,r)=>{const s=y(_(e,r));return q(s,"root",t[r]),q(e,r,s),e},X=e=>"file"===e.type,Y=e=>"function"==typeof e,Z=e=>{if(!f)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ee=e=>N(e),te=e=>"radio"===e.type,re=e=>e instanceof RegExp;const se={value:!1,isValid:!1},ae={value:!0,isValid:!0};var ne=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!p(e[0].attributes.value)?p(e[0].value)||""===e[0].value?ae:{value:e[0].value,isValid:!0}:ae:se}return se};const ie={isValid:!1,value:null};var ue=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ie):ie;function oe(e,t,r="validate"){if(ee(e)||Array.isArray(e)&&e.every(ee)||h(e)&&!e)return{type:r,message:ee(e)?e:"",ref:t}}var le=e=>o(e)&&!re(e)?e:{value:e,message:""},de=async(e,t,r,s,n)=>{const{ref:u,refs:l,required:d,maxLength:c,minLength:f,min:m,max:y,pattern:g,validate:v,name:D,valueAsNumber:k,mount:C,disabled:O}=e._f,j=_(t,D);if(!C||O)return{};const T=l?l[0]:u,U=e=>{s&&T.reportValidity&&(T.setCustomValidity(h(e)?"":e||""),T.reportValidity())},B={},L=te(u),R=a(u),M=L||R,P=(k||X(u))&&p(u.value)&&p(j)||Z(u)&&""===u.value||""===j||Array.isArray(j)&&!j.length,q=I.bind(null,D,r,B),W=(e,t,r,s=x,a=V)=>{const n=e?t:r;B[D]={type:e?s:a,message:n,ref:u,...q(e?s:a,n)}};if(n?!Array.isArray(j)||!j.length:d&&(!M&&(P||i(j))||h(j)&&!j||R&&!ne(l).isValid||L&&!ue(l).isValid)){const{value:e,message:t}=ee(d)?{value:!!d,message:d}:le(d);if(e&&(B[D]={type:S,message:t,ref:T,...q(S,t)},!r))return U(t),B}if(!(P||i(m)&&i(y))){let e,t;const s=le(y),a=le(m);if(i(j)||isNaN(j)){const r=u.valueAsDate||new Date(j),n=e=>new Date((new Date).toDateString()+" "+e),i="time"==u.type,o="week"==u.type;N(s.value)&&j&&(e=i?n(j)>n(s.value):o?j>s.value:r>new Date(s.value)),N(a.value)&&j&&(t=i?n(j)<n(a.value):o?j<a.value:r<new Date(a.value))}else{const r=u.valueAsNumber||(j?+j:j);i(s.value)||(e=r>s.value),i(a.value)||(t=r<a.value)}if((e||t)&&(W(!!e,s.message,a.message,b,A),!r))return U(B[D].message),B}if((c||f)&&!P&&(N(j)||n&&Array.isArray(j))){const e=le(c),t=le(f),s=!i(e.value)&&j.length>+e.value,a=!i(t.value)&&j.length<+t.value;if((s||a)&&(W(s,e.message,t.message),!r))return U(B[D].message),B}if(g&&!P&&N(j)){const{value:e,message:t}=le(g);if(re(e)&&!j.match(e)&&(B[D]={type:F,message:t,ref:u,...q(F,t)},!r))return U(t),B}if(v)if(Y(v)){const e=oe(await v(j,t),T);if(e&&(B[D]={...e,...q(w,e.message)},!r))return U(e.message),B}else if(o(v)){let e={};for(const s in v){if(!E(e)&&!r)break;const a=oe(await v[s](j,t),T,s);a&&(e={...a,...q(s,a.message)},U(a.message),r&&(B[D]=e))}if(!E(e)&&(B[D]={ref:T,...e},!r))return B}return U(!0),B};function ce(e,t){return[...e,...j(t)]}var fe=e=>Array.isArray(e)?e.map((()=>{})):void 0;function me(e,t,r){return[...e.slice(0,t),...j(r),...e.slice(t)]}var ye=(e,t,r)=>Array.isArray(e)?(p(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[];function pe(e,t){return[...j(t),...j(e)]}var _e=(e,t)=>p(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return y(s).length?s:[]}(e,j(t).sort(((e,t)=>e-t))),he=(e,t,r)=>{e[t]=[e[r],e[r]=e[t]][0]};function ge(e,t){const r=Array.isArray(t)?t:M(t)?[t]:P(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=p(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(o(s)&&E(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!p(e[t]))return!1;return!0}(s))&&ge(e,r.slice(0,-1)),e}var ve=(e,t,r)=>(e[t]=r,e);function be(){let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}}var Ae=e=>i(e)||!u(e);function xe(e,t){if(Ae(e)||Ae(t))return e===t;if(n(e)&&n(t))return e.getTime()===t.getTime();const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const a of r){const r=e[a];if(!s.includes(a))return!1;if("ref"!==a){const e=t[a];if(n(r)&&n(e)||o(r)&&o(e)||Array.isArray(r)&&Array.isArray(e)?!xe(r,e):r!==e)return!1}}return!0}var Ve=e=>"select-multiple"===e.type,Fe=e=>te(e)||a(e),Se=e=>Z(e)&&e.isConnected,we=e=>{for(const t in e)if(Y(e[t]))return!0;return!1};function De(e,t={}){const r=Array.isArray(e);if(o(e)||r)for(const r in e)Array.isArray(e[r])||o(e[r])&&!we(e[r])?(t[r]=Array.isArray(e[r])?[]:{},De(e[r],t[r])):i(e[r])||(t[r]=!0);return t}function ke(e,t,r){const s=Array.isArray(e);if(o(e)||s)for(const s in e)Array.isArray(e[s])||o(e[s])&&!we(e[s])?p(t)||Ae(r[s])?r[s]=Array.isArray(e[s])?De(e[s],[]):{...De(e[s])}:ke(e[s],i(t)?{}:t[s],r[s]):r[s]=!xe(e[s],t[s]);return r}var Ce=(e,t)=>ke(e,t,De(t)),Ee=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>p(e)?e:t?""===e?NaN:e?+e:e:r&&N(e)?new Date(e):s?s(e):e;function Oe(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return X(t)?t.files:te(t)?ue(e.refs).value:Ve(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ne(e.refs).value:Ee(p(t.value)?e.ref.value:t.value,e)}var je=(e,t,r,s)=>{const a={};for(const r of e){const e=_(t,r);e&&q(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Te=e=>p(e)?e:re(e)?e.source:o(e)?re(e.value)?e.value.source:e.value:e,Ue=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Be(e,t,r){const s=_(e,r);if(s||M(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=_(t,s),i=_(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Ne=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Le=(e,t)=>!y(_(e,t)).length&&ge(e,t);const Re={mode:v.onSubmit,reValidateMode:v.onChange,shouldFocusError:!0};function Me(e={},t){let r,s={...Re,...e},u={submitCount:0,isDirty:!1,isLoading:Y(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{},disabled:!1},c={},b=(o(s.defaultValues)||o(s.values))&&m(s.defaultValues||s.values)||{},A=s.shouldUnregister?{}:m(b),x={action:!1,mount:!1,watch:!1},V={mount:new Set,unMount:new Set,array:new Set,watch:new Set},F=0;const S={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={values:be(),array:be(),state:be()},D=e.resetOptions&&e.resetOptions.keepDirtyValues,k=J(s.mode),C=J(s.reValidateMode),O=s.criteriaMode===v.all,T=async e=>{if(S.isValid||e){const e=s.resolver?E((await P()).errors):await W(c,!0);e!==u.isValid&&w.state.next({isValid:e})}},U=e=>S.isValidating&&w.state.next({isValidating:e}),B=(e,t,r,s)=>{const a=_(c,e);if(a){const n=_(A,e,p(r)?_(b,e):r);p(n)||s&&s.defaultChecked||t?q(A,e,t?n:Oe(a._f)):$(e,n),x.mount&&T()}},R=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e};if(!r||s){S.isDirty&&(i=u.isDirty,u.isDirty=o.isDirty=H(),n=i!==o.isDirty);const r=xe(_(b,e),t);i=_(u.dirtyFields,e),r?ge(u.dirtyFields,e):q(u.dirtyFields,e,!0),o.dirtyFields=u.dirtyFields,n=n||S.dirtyFields&&i!==!r}if(r){const t=_(u.touchedFields,e);t||(q(u.touchedFields,e,r),o.touchedFields=u.touchedFields,n=n||S.touchedFields&&t!==r)}return n&&a&&w.state.next(o),n?o:{}},M=(t,s,a,n)=>{const i=_(u.errors,t),o=S.isValid&&h(s)&&u.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{q(u.errors,e,t),w.state.next({errors:u.errors})})(t,a),r=e=>{clearTimeout(F),F=setTimeout(l,e)},r(e.delayError)):(clearTimeout(F),r=null,a?q(u.errors,t,a):ge(u.errors,t)),(a?!xe(i,a):i)||!E(n)||o){const e={...n,...o&&h(s)?{isValid:s}:{},errors:u.errors,name:t};u={...u,...e},w.state.next(e)}U(!1)},P=async e=>s.resolver(A,s.context,je(e||V.mount,c,s.criteriaMode,s.shouldUseNativeValidation)),W=async(e,t,r={valid:!0})=>{for(const a in e){const n=e[a];if(n){const{_f:e,...a}=n;if(e){const a=V.array.has(e.name),i=await de(n,A,O,s.shouldUseNativeValidation&&!t,a);if(i[e.name]&&(r.valid=!1,t))break;!t&&(_(i,e.name)?a?Q(u.errors,i,e.name):q(u.errors,e.name,i[e.name]):ge(u.errors,e.name))}a&&await W(a,t,r)}}return r.valid},H=(e,t)=>(e&&t&&q(A,e,t),!xe(ae(),b)),I=(e,t,r)=>L(e,V,{...x.mount?A:p(t)?b:N(e)?{[e]:t}:t},r,t),$=(e,t,r={})=>{const s=_(c,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&q(A,e,Ee(t,r)),n=Z(r.ref)&&i(t)?"":t,Ve(r.ref)?[...r.ref.options].forEach((e=>e.selected=n.includes(e.value))):r.refs?a(r.ref)?r.refs.length>1?r.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(n)?!!n.find((t=>t===e.value)):n===e.value))):r.refs[0]&&(r.refs[0].checked=!!n):r.refs.forEach((e=>e.checked=e.value===n)):X(r.ref)?r.ref.value="":(r.ref.value=n,r.ref.type||w.values.next({name:e,values:{...A}})))}(r.shouldDirty||r.shouldTouch)&&R(e,n,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&se(e)},G=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,u=_(c,i);!V.array.has(e)&&Ae(a)&&(!u||u._f)||n(a)?$(i,a,r):G(i,a,r)}},ee=(e,r,s={})=>{const a=_(c,e),n=V.array.has(e),o=m(r);q(A,e,o),n?(w.array.next({name:e,values:{...A}}),(S.isDirty||S.dirtyFields)&&s.shouldDirty&&w.state.next({name:e,dirtyFields:Ce(b,A),isDirty:H(e,o)})):!a||a._f||i(o)?$(e,o,s):G(e,o,s),z(e,V)&&w.state.next({...u}),w.values.next({name:e,values:{...A}}),!x.mount&&t()},te=async e=>{const t=e.target;let a=t.name,n=!0;const i=_(c,a),o=e=>{n=Number.isNaN(e)||e===_(A,a,e)};if(i){let d,f;const m=t.type?Oe(i._f):l(e),y=e.type===g.BLUR||e.type===g.FOCUS_OUT,p=!Ue(i._f)&&!s.resolver&&!_(u.errors,a)&&!i._f.deps||Ne(y,_(u.touchedFields,a),u.isSubmitted,C,k),h=z(a,V,y);q(A,a,m),y?(i._f.onBlur&&i._f.onBlur(e),r&&r(0)):i._f.onChange&&i._f.onChange(e);const v=R(a,m,y,!1),b=!E(v)||h;if(!y&&w.values.next({name:a,type:e.type,values:{...A}}),p)return S.isValid&&T(),b&&w.state.next({name:a,...h?{}:v});if(!y&&h&&w.state.next({...u}),U(!0),s.resolver){const{errors:e}=await P([a]);if(o(m),n){const t=Be(u.errors,c,a),r=Be(e,c,t.name||a);d=r.error,a=r.name,f=E(e)}}else d=(await de(i,A,O,s.shouldUseNativeValidation))[a],o(m),n&&(d?f=!1:S.isValid&&(f=await W(c,!0)));n&&(i._f.deps&&se(i._f.deps),M(a,f,d,v))}},re=(e,t)=>{if(_(u.errors,t)&&e.focus)return e.focus(),1},se=async(e,t={})=>{let r,a;const n=j(e);if(U(!0),s.resolver){const t=await(async e=>{const{errors:t}=await P(e);if(e)for(const r of e){const e=_(t,r);e?q(u.errors,r,e):ge(u.errors,r)}else u.errors=t;return t})(p(e)?e:n);r=E(t),a=e?!n.some((e=>_(t,e))):r}else e?(a=(await Promise.all(n.map((async e=>{const t=_(c,e);return await W(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&T()):a=r=await W(c);return w.state.next({...!N(e)||S.isValid&&r!==u.isValid?{}:{name:e},...s.resolver||!e?{isValid:r}:{},errors:u.errors,isValidating:!1}),t.shouldFocus&&!a&&K(c,re,e?n:V.mount),a},ae=e=>{const t={...b,...x.mount?A:{}};return p(e)?t:N(e)?_(t,e):e.map((e=>_(t,e)))},ne=(e,t)=>({invalid:!!_((t||u).errors,e),isDirty:!!_((t||u).dirtyFields,e),isTouched:!!_((t||u).touchedFields,e),error:_((t||u).errors,e)}),ie=(e,t,r)=>{const s=(_(c,e,{_f:{}})._f||{}).ref;q(u.errors,e,{...t,ref:s}),w.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ue=(e,t={})=>{for(const r of e?j(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(ge(c,r),ge(A,r)),!t.keepError&&ge(u.errors,r),!t.keepDirty&&ge(u.dirtyFields,r),!t.keepTouched&&ge(u.touchedFields,r),!s.shouldUnregister&&!t.keepDefaultValue&&ge(b,r);w.values.next({values:{...A}}),w.state.next({...u,...t.keepDirty?{isDirty:H()}:{}}),!t.keepIsValid&&T()},oe=({disabled:e,name:t,field:r,fields:s,value:a})=>{if(h(e)){const n=e?void 0:p(a)?Oe(r?r._f:_(s,t)._f):a;q(A,t,n),R(t,n,!1,!1,!0)}},le=(e,t={})=>{let r=_(c,e);const a=h(t.disabled);return q(c,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?oe({field:r,disabled:t.disabled,name:e}):B(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.progressive?{required:!!t.required,min:Te(t.min),max:Te(t.max),minLength:Te(t.minLength),maxLength:Te(t.maxLength),pattern:Te(t.pattern)}:{},name:e,onChange:te,onBlur:te,ref:a=>{if(a){le(e,t),r=_(c,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=Fe(s),i=r._f.refs||[];if(n?i.find((e=>e===s)):s===r._f.ref)return;q(c,e,{_f:{...r._f,...n?{refs:[...i.filter(Se),s,...Array.isArray(_(b,e))?[{}]:[]],ref:{type:s.type,name:e}}:{ref:s}}}),B(e,!1,void 0,s)}else r=_(c,e,{}),r._f&&(r._f.mount=!1),(s.shouldUnregister||t.shouldUnregister)&&(!d(V.array,e)||!x.action)&&V.unMount.add(e)}}},ce=()=>s.shouldFocusError&&K(c,re,V.mount),fe=(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=m(A);if(w.state.next({isSubmitting:!0}),s.resolver){const{errors:e,values:t}=await P();u.errors=e,a=t}else await W(c);ge(u.errors,"root"),E(u.errors)?(w.state.next({errors:{}}),await e(a,r)):(t&&await t({...u.errors},r),ce(),setTimeout(ce)),w.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:E(u.errors),submitCount:u.submitCount+1,errors:u.errors})},me=(r,s={})=>{const a=r?m(r):b,n=m(a),i=r&&!E(r)?n:b;if(s.keepDefaultValues||(b=a),!s.keepValues){if(s.keepDirtyValues||D)for(const e of V.mount)_(u.dirtyFields,e)?q(i,e,_(A,e)):ee(e,_(i,e));else{if(f&&p(r))for(const e of V.mount){const t=_(c,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Z(e)){const t=e.closest("form");if(t){t.reset();break}}}}c={}}A=e.shouldUnregister?s.keepDefaultValues?m(b):{}:m(i),w.array.next({values:{...i}}),w.values.next({values:{...i}})}V={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&t(),x.mount=!S.isValid||!!s.keepIsValid,x.watch=!!e.shouldUnregister,w.state.next({submitCount:s.keepSubmitCount?u.submitCount:0,isDirty:s.keepDirty?u.isDirty:!(!s.keepDefaultValues||xe(r,b)),isSubmitted:!!s.keepIsSubmitted&&u.isSubmitted,dirtyFields:s.keepDirtyValues?u.dirtyFields:s.keepDefaultValues&&r?Ce(b,r):{},touchedFields:s.keepTouched?u.touchedFields:{},errors:s.keepErrors?u.errors:{},isSubmitSuccessful:!!s.keepIsSubmitSuccessful&&u.isSubmitSuccessful,isSubmitting:!1})},ye=(e,t)=>me(Y(e)?e(A):e,t);return{control:{register:le,unregister:ue,getFieldState:ne,handleSubmit:fe,setError:ie,_executeSchema:P,_getWatch:I,_getDirty:H,_updateValid:T,_removeUnmounted:()=>{for(const e of V.unMount){const t=_(c,e);t&&(t._f.refs?t._f.refs.every((e=>!Se(e))):!Se(t._f.ref))&&ue(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(x.action=!0,n&&Array.isArray(_(c,e))){const t=r(_(c,e),s.argA,s.argB);a&&q(c,e,t)}if(n&&Array.isArray(_(u.errors,e))){const t=r(_(u.errors,e),s.argA,s.argB);a&&q(u.errors,e,t),Le(u.errors,e)}if(S.touchedFields&&n&&Array.isArray(_(u.touchedFields,e))){const t=r(_(u.touchedFields,e),s.argA,s.argB);a&&q(u.touchedFields,e,t)}S.dirtyFields&&(u.dirtyFields=Ce(b,A)),w.state.next({name:e,isDirty:H(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else q(A,e,t)},_updateDisabledField:oe,_getFieldArray:t=>y(_(x.mount?A:b,t,e.shouldUnregister?_(b,t,[]):[])),_reset:me,_resetDefaultValues:()=>Y(s.defaultValues)&&s.defaultValues().then((e=>{ye(e,s.resetOptions),w.state.next({isLoading:!1})})),_updateFormState:e=>{u={...u,...e}},_disableForm:e=>{h(e)&&(w.state.next({disabled:e}),K(c,(t=>{t.disabled=e}),0,!1))},_subjects:w,_proxyFormState:S,get _fields(){return c},get _formValues(){return A},get _state(){return x},set _state(e){x=e},get _defaultValues(){return b},get _names(){return V},set _names(e){V=e},get _formState(){return u},set _formState(e){u=e},get _options(){return s},set _options(e){s={...s,...e}}},trigger:se,register:le,handleSubmit:fe,watch:(e,t)=>Y(e)?w.values.subscribe({next:r=>e(I(void 0,t),r)}):I(e,t,!0),setValue:ee,getValues:ae,reset:ye,resetField:(e,t={})=>{_(c,e)&&(p(t.defaultValue)?ee(e,_(b,e)):(ee(e,t.defaultValue),q(b,e,t.defaultValue)),t.keepTouched||ge(u.touchedFields,e),t.keepDirty||(ge(u.dirtyFields,e),u.isDirty=t.defaultValue?H(e,_(b,e)):H()),t.keepError||(ge(u.errors,e),S.isValid&&T()),w.state.next({...u}))},clearErrors:e=>{e&&j(e).forEach((e=>ge(u.errors,e))),w.state.next({errors:e?u.errors:{}})},unregister:ue,setError:ie,setFocus:(e,t={})=>{const r=_(c,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ne}}e.Controller=e=>e.render(W(e)),e.Form=function(e){const t=k(),[r,a]=s.default.useState(!1),{control:n=t.control,onSubmit:i,children:u,action:o,method:l=H,headers:d,encType:c,onError:f,render:m,onSuccess:y,validateStatus:p,...h}=e,g=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,_(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...d,...c?{"Content-Type":c}:{}},body:e?u:a});t&&(p?!p(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):y&&y({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return s.default.useEffect((()=>{a(!0)}),[]),m?s.default.createElement(s.default.Fragment,null,m({submit:g})):s.default.createElement("form",{noValidate:r,action:o,method:l,encType:c,onSubmit:g,...h},u)},e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(D.Provider,{value:r},t)},e.appendErrors=I,e.get=_,e.set=q,e.useController=W,e.useFieldArray=function(e){const t=k(),{control:r=t.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map($)),d=s.default.useRef(u),c=s.default.useRef(a),f=s.default.useRef(!1);c.current=a,d.current=u,r._names.array.add(a),e.rules&&r.register(a,e.rules),U({next:({values:e,name:t})=>{if(t===c.current||!t){const t=_(e,c.current);Array.isArray(t)&&(o(t),l.current=t.map($))}},subject:r._subjects.array});const y=s.default.useCallback((e=>{f.current=!0,r._updateFieldArray(a,e)}),[r,a]);return s.default.useEffect((()=>{if(r._state.action=!1,z(a,r._names)&&r._subjects.state.next({...r._formState}),f.current&&(!J(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=_(e.errors,a),s=_(r._formState.errors,a);(s?!t&&s.type||t&&(s.type!==t.type||s.message!==t.message):t&&t.type)&&(t?q(r._formState.errors,a,t):ge(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=_(r._fields,a);e&&e._f&&de(e,r._formValues,r._options.criteriaMode===v.all,r._options.shouldUseNativeValidation,!0).then((e=>!E(e)&&r._subjects.state.next({errors:Q(r._formState.errors,e,a)})))}r._subjects.values.next({name:a,values:{...r._formValues}}),r._names.focus&&K(r._fields,((e,t)=>{if(r._names.focus&&t.startsWith(r._names.focus)&&e.focus)return e.focus(),1})),r._names.focus="",r._updateValid(),f.current=!1}),[u,a,r]),s.default.useEffect((()=>(!_(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);he(s,e,t),he(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,he,{argA:e,argB:t},!1)}),[y,a,r]),move:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);ye(s,e,t),ye(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,ye,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=pe(r._getFieldArray(a),s);r._names.focus=G(a,0,t),l.current=pe(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,pe,{argA:fe(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=ce(r._getFieldArray(a),s);r._names.focus=G(a,n.length-1,t),l.current=ce(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,ce,{argA:fe(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=_e(r._getFieldArray(a),e);l.current=_e(l.current,e),y(t),o(t),r._updateFieldArray(a,t,_e,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=j(m(t)),i=me(r._getFieldArray(a),e,n);r._names.focus=G(a,e,s),l.current=me(l.current,e,n.map($)),y(i),o(i),r._updateFieldArray(a,i,me,{argA:e,argB:fe(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=m(t),n=ve(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:$())),y(n),o([...n]),r._updateFieldArray(a,n,ve,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=j(m(e));l.current=t.map($),y([...t]),o([...t]),r._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,r]),fields:s.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||$()})))),[u,n])}},e.useForm=function(e={}){const t=s.default.useRef(),r=s.default.useRef(),[a,n]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:Y(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},disabled:!1,defaultValues:Y(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Me(e,(()=>n((e=>({...e}))))),formState:a});const i=t.current.control;return i._options=e,U({subject:i._subjects.state,next:e=>{O(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),s.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),s.default.useEffect((()=>{if(i._proxyFormState.isDirty){const e=i._getDirty();e!==a.isDirty&&i._subjects.state.next({isDirty:e})}}),[i,a.isDirty]),s.default.useEffect((()=>{e.values&&!xe(e.values,r.current)?(i._reset(e.values,i._options.resetOptions),r.current=e.values):i._resetDefaultValues()}),[e.values,i]),s.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),t.current.formState=C(a,i),t.current},e.useFormContext=k,e.useFormState=B,e.useWatch=R,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookForm={},e.React)}(this,(function(e,t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(t),a=e=>"checkbox"===e.type,n=e=>e instanceof Date,i=e=>null==e;const u=e=>"object"==typeof e;var o=e=>!i(e)&&!Array.isArray(e)&&u(e)&&!n(e),l=e=>o(e)&&e.target?a(e.target)?e.target.checked:e.target.value:e,d=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),c=e=>{const t=e.constructor&&e.constructor.prototype;return o(t)&&t.hasOwnProperty("isPrototypeOf")},f="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function m(e){let t;const r=Array.isArray(e);if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else{if(f&&(e instanceof Blob||e instanceof FileList)||!r&&!o(e))return e;if(t=r?[]:{},r||c(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=m(e[r]));else t=e}return t}var y=e=>Array.isArray(e)?e.filter(Boolean):[],p=e=>void 0===e,_=(e,t,r)=>{if(!t||!o(e))return r;const s=y(t.split(/[,[\].]+?/)).reduce(((e,t)=>i(e)?e:e[t]),e);return p(s)||s===e?p(e[t])?r:e[t]:s},h=e=>"boolean"==typeof e;const g={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},v={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},b="max",A="min",x="maxLength",V="minLength",F="pattern",S="required",w="validate",D=s.default.createContext(null),k=()=>s.default.useContext(D);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.all&&(t._proxyFormState[a]=!s||v.all),r&&(r[a]=!0),e[a]}});return a},E=e=>o(e)&&!Object.keys(e).length,O=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return E(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||v.all)))},j=e=>Array.isArray(e)?e:[e],T=(e,t,r)=>!e||!t||e===t||j(e).some((e=>e&&(r?e===t:e.startsWith(t)||t.startsWith(e))));function U(e){const t=s.default.useRef(e);t.current=e,s.default.useEffect((()=>{const r=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{r&&r.unsubscribe()}}),[e.disabled])}function B(e){const t=k(),{control:r=t.control,disabled:a,name:n,exact:i}=e||{},[u,o]=s.default.useState(r._formState),l=s.default.useRef(!0),d=s.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=s.default.useRef(n);return c.current=n,U({disabled:a,next:e=>l.current&&T(c.current,e.name,i)&&O(e,d.current,r._updateFormState)&&o({...r._formState,...e}),subject:r._subjects.state}),s.default.useEffect((()=>(l.current=!0,d.current.isValid&&r._updateValid(!0),()=>{l.current=!1})),[r]),C(u,r,d.current,!1)}var N=e=>"string"==typeof e,L=(e,t,r,s,a)=>N(e)?(s&&t.watch.add(e),_(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),_(r,e)))):(s&&(t.watchAll=!0),r);function R(e){const t=k(),{control:r=t.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=s.default.useRef(a);o.current=a,U({disabled:i,subject:r._subjects.values,next:e=>{T(o.current,e.name,u)&&d(m(L(o.current,r._names,e.values||r._formValues,!1,n)))}});const[l,d]=s.default.useState(r._getWatch(a,n));return s.default.useEffect((()=>r._removeUnmounted())),l}var M=e=>/^\w*$/.test(e),P=e=>y(e.replace(/["|']|\]/g,"").split(/\.|\[/)),q=(e,t,r)=>{let s=-1;const a=M(t)?[t]:P(t),n=a.length,i=n-1;for(;++s<n;){const t=a[s];let n=r;if(s!==i){const r=e[t];n=o(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}e[t]=n,e=e[t]}return e};function W(e){const t=k(),{name:r,disabled:a,control:n=t.control,shouldUnregister:i}=e,u=d(n._names.array,r),o=R({control:n,name:r,defaultValue:_(n._formValues,r,_(n._defaultValues,r,e.defaultValue)),exact:!0}),c=B({control:n,name:r}),f=s.default.useRef(n.register(r,{...e.rules,value:o,...h(e.disabled)?{disabled:e.disabled}:{}}));return s.default.useEffect((()=>{const e=n._options.shouldUnregister||i,t=(e,t)=>{const r=_(n._fields,e);r&&(r._f.mount=t)};if(t(r,!0),e){const e=m(_(n._options.defaultValues,r));q(n._defaultValues,r,e),p(_(n._formValues,r))&&q(n._formValues,r,e)}return()=>{(u?e&&!n._state.action:e)?n.unregister(r):t(r,!1)}}),[r,n,u,i]),s.default.useEffect((()=>{_(n._fields,r)&&n._updateDisabledField({disabled:a,fields:n._fields,name:r,value:_(n._fields,r)._f.value})}),[a,r,n]),{field:{name:r,value:o,...h(a)||c.disabled?{disabled:c.disabled||a}:{},onChange:s.default.useCallback((e=>f.current.onChange({target:{value:l(e),name:r},type:g.CHANGE})),[r]),onBlur:s.default.useCallback((()=>f.current.onBlur({target:{value:_(n._formValues,r),name:r},type:g.BLUR})),[r,n]),ref:e=>{const t=_(n._fields,r);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:()=>!!_(c.errors,r)},isDirty:{enumerable:!0,get:()=>!!_(c.dirtyFields,r)},isTouched:{enumerable:!0,get:()=>!!_(c.touchedFields,r)},error:{enumerable:!0,get:()=>_(c.errors,r)}})}}const H="post";var I=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},$=()=>{const e="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const r=(16*Math.random()+e)%16|0;return("x"==t?r:3&r|8).toString(16)}))},G=(e,t,r={})=>r.shouldFocus||p(r.shouldFocus)?r.focusName||`${e}.${p(r.focusIndex)?t:r.focusIndex}.`:"",J=e=>({isOnSubmit:!e||e===v.onSubmit,isOnBlur:e===v.onBlur,isOnChange:e===v.onChange,isOnAll:e===v.all,isOnTouch:e===v.onTouched}),z=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const K=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=_(e,a);if(r){const{_f:e,...n}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)break;if(e.ref&&t(e.ref,e.name)&&!s)break;K(n,t)}else o(n)&&K(n,t)}}};var Q=(e,t,r)=>{const s=y(_(e,r));return q(s,"root",t[r]),q(e,r,s),e},X=e=>"file"===e.type,Y=e=>"function"==typeof e,Z=e=>{if(!f)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ee=e=>N(e),te=e=>"radio"===e.type,re=e=>e instanceof RegExp;const se={value:!1,isValid:!1},ae={value:!0,isValid:!0};var ne=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!p(e[0].attributes.value)?p(e[0].value)||""===e[0].value?ae:{value:e[0].value,isValid:!0}:ae:se}return se};const ie={isValid:!1,value:null};var ue=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),ie):ie;function oe(e,t,r="validate"){if(ee(e)||Array.isArray(e)&&e.every(ee)||h(e)&&!e)return{type:r,message:ee(e)?e:"",ref:t}}var le=e=>o(e)&&!re(e)?e:{value:e,message:""},de=async(e,t,r,s,n)=>{const{ref:u,refs:l,required:d,maxLength:c,minLength:f,min:m,max:y,pattern:g,validate:v,name:D,valueAsNumber:k,mount:C,disabled:O}=e._f,j=_(t,D);if(!C||O)return{};const T=l?l[0]:u,U=e=>{s&&T.reportValidity&&(T.setCustomValidity(h(e)?"":e||""),T.reportValidity())},B={},L=te(u),R=a(u),M=L||R,P=(k||X(u))&&p(u.value)&&p(j)||Z(u)&&""===u.value||""===j||Array.isArray(j)&&!j.length,q=I.bind(null,D,r,B),W=(e,t,r,s=x,a=V)=>{const n=e?t:r;B[D]={type:e?s:a,message:n,ref:u,...q(e?s:a,n)}};if(n?!Array.isArray(j)||!j.length:d&&(!M&&(P||i(j))||h(j)&&!j||R&&!ne(l).isValid||L&&!ue(l).isValid)){const{value:e,message:t}=ee(d)?{value:!!d,message:d}:le(d);if(e&&(B[D]={type:S,message:t,ref:T,...q(S,t)},!r))return U(t),B}if(!(P||i(m)&&i(y))){let e,t;const s=le(y),a=le(m);if(i(j)||isNaN(j)){const r=u.valueAsDate||new Date(j),n=e=>new Date((new Date).toDateString()+" "+e),i="time"==u.type,o="week"==u.type;N(s.value)&&j&&(e=i?n(j)>n(s.value):o?j>s.value:r>new Date(s.value)),N(a.value)&&j&&(t=i?n(j)<n(a.value):o?j<a.value:r<new Date(a.value))}else{const r=u.valueAsNumber||(j?+j:j);i(s.value)||(e=r>s.value),i(a.value)||(t=r<a.value)}if((e||t)&&(W(!!e,s.message,a.message,b,A),!r))return U(B[D].message),B}if((c||f)&&!P&&(N(j)||n&&Array.isArray(j))){const e=le(c),t=le(f),s=!i(e.value)&&j.length>+e.value,a=!i(t.value)&&j.length<+t.value;if((s||a)&&(W(s,e.message,t.message),!r))return U(B[D].message),B}if(g&&!P&&N(j)){const{value:e,message:t}=le(g);if(re(e)&&!j.match(e)&&(B[D]={type:F,message:t,ref:u,...q(F,t)},!r))return U(t),B}if(v)if(Y(v)){const e=oe(await v(j,t),T);if(e&&(B[D]={...e,...q(w,e.message)},!r))return U(e.message),B}else if(o(v)){let e={};for(const s in v){if(!E(e)&&!r)break;const a=oe(await v[s](j,t),T,s);a&&(e={...a,...q(s,a.message)},U(a.message),r&&(B[D]=e))}if(!E(e)&&(B[D]={ref:T,...e},!r))return B}return U(!0),B},ce=(e,t)=>[...e,...j(t)],fe=e=>Array.isArray(e)?e.map((()=>{})):void 0;function me(e,t,r){return[...e.slice(0,t),...j(r),...e.slice(t)]}var ye=(e,t,r)=>Array.isArray(e)?(p(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[],pe=(e,t)=>[...j(t),...j(e)];var _e=(e,t)=>p(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return y(s).length?s:[]}(e,j(t).sort(((e,t)=>e-t))),he=(e,t,r)=>{[e[t],e[r]]=[e[r],e[t]]};function ge(e,t){const r=Array.isArray(t)?t:M(t)?[t]:P(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=p(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(o(s)&&E(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!p(e[t]))return!1;return!0}(s))&&ge(e,r.slice(0,-1)),e}var ve=(e,t,r)=>(e[t]=r,e);var be=()=>{let e=[];return{get observers(){return e},next:t=>{for(const r of e)r.next&&r.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter((e=>e!==t))}}),unsubscribe:()=>{e=[]}}},Ae=e=>i(e)||!u(e);function xe(e,t){if(Ae(e)||Ae(t))return e===t;if(n(e)&&n(t))return e.getTime()===t.getTime();const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const a of r){const r=e[a];if(!s.includes(a))return!1;if("ref"!==a){const e=t[a];if(n(r)&&n(e)||o(r)&&o(e)||Array.isArray(r)&&Array.isArray(e)?!xe(r,e):r!==e)return!1}}return!0}var Ve=e=>"select-multiple"===e.type,Fe=e=>te(e)||a(e),Se=e=>Z(e)&&e.isConnected,we=e=>{for(const t in e)if(Y(e[t]))return!0;return!1};function De(e,t={}){const r=Array.isArray(e);if(o(e)||r)for(const r in e)Array.isArray(e[r])||o(e[r])&&!we(e[r])?(t[r]=Array.isArray(e[r])?[]:{},De(e[r],t[r])):i(e[r])||(t[r]=!0);return t}function ke(e,t,r){const s=Array.isArray(e);if(o(e)||s)for(const s in e)Array.isArray(e[s])||o(e[s])&&!we(e[s])?p(t)||Ae(r[s])?r[s]=Array.isArray(e[s])?De(e[s],[]):{...De(e[s])}:ke(e[s],i(t)?{}:t[s],r[s]):r[s]=!xe(e[s],t[s]);return r}var Ce=(e,t)=>ke(e,t,De(t)),Ee=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>p(e)?e:t?""===e?NaN:e?+e:e:r&&N(e)?new Date(e):s?s(e):e;function Oe(e){const t=e.ref;if(!(e.refs?e.refs.every((e=>e.disabled)):t.disabled))return X(t)?t.files:te(t)?ue(e.refs).value:Ve(t)?[...t.selectedOptions].map((({value:e})=>e)):a(t)?ne(e.refs).value:Ee(p(t.value)?e.ref.value:t.value,e)}var je=(e,t,r,s)=>{const a={};for(const r of e){const e=_(t,r);e&&q(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}},Te=e=>p(e)?e:re(e)?e.source:o(e)?re(e.value)?e.value.source:e.value:e,Ue=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Be(e,t,r){const s=_(e,r);if(s||M(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),n=_(t,s),i=_(e,s);if(n&&!Array.isArray(n)&&r!==s)return{name:r};if(i&&i.type)return{name:s,error:i};a.pop()}return{name:r}}var Ne=(e,t,r,s,a)=>!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e),Le=(e,t)=>!y(_(e,t)).length&&ge(e,t);const Re={mode:v.onSubmit,reValidateMode:v.onChange,shouldFocusError:!0};function Me(e={},t){let r,s={...Re,...e},u={submitCount:0,isDirty:!1,isLoading:Y(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:s.errors||{},disabled:s.disabled||!1},c={},b=(o(s.defaultValues)||o(s.values))&&m(s.defaultValues||s.values)||{},A=s.shouldUnregister?{}:m(b),x={action:!1,mount:!1,watch:!1},V={mount:new Set,unMount:new Set,array:new Set,watch:new Set},F=0;const S={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={values:be(),array:be(),state:be()},D=J(s.mode),k=J(s.reValidateMode),C=s.criteriaMode===v.all,O=async e=>{if(S.isValid||e){const e=s.resolver?E((await M()).errors):await P(c,!0);e!==u.isValid&&w.state.next({isValid:e})}},T=e=>S.isValidating&&w.state.next({isValidating:e}),U=(e,t,r,s)=>{const a=_(c,e);if(a){const n=_(A,e,p(r)?_(b,e):r);p(n)||s&&s.defaultChecked||t?q(A,e,t?n:Oe(a._f)):I(e,n),x.mount&&O()}},B=(e,t,r,s,a)=>{let n=!1,i=!1;const o={name:e},l=!(!_(c,e)||!_(c,e)._f.disabled);if(!r||s){S.isDirty&&(i=u.isDirty,u.isDirty=o.isDirty=W(),n=i!==o.isDirty);const r=l||xe(_(b,e),t);i=!(l||!_(u.dirtyFields,e)),r||l?ge(u.dirtyFields,e):q(u.dirtyFields,e,!0),o.dirtyFields=u.dirtyFields,n=n||S.dirtyFields&&i!==!r}if(r){const t=_(u.touchedFields,e);t||(q(u.touchedFields,e,r),o.touchedFields=u.touchedFields,n=n||S.touchedFields&&t!==r)}return n&&a&&w.state.next(o),n?o:{}},R=(t,s,a,n)=>{const i=_(u.errors,t),o=S.isValid&&h(s)&&u.isValid!==s;var l;if(e.delayError&&a?(l=()=>((e,t)=>{q(u.errors,e,t),w.state.next({errors:u.errors})})(t,a),r=e=>{clearTimeout(F),F=setTimeout(l,e)},r(e.delayError)):(clearTimeout(F),r=null,a?q(u.errors,t,a):ge(u.errors,t)),(a?!xe(i,a):i)||!E(n)||o){const e={...n,...o&&h(s)?{isValid:s}:{},errors:u.errors,name:t};u={...u,...e},w.state.next(e)}T(!1)},M=async e=>s.resolver(A,s.context,je(e||V.mount,c,s.criteriaMode,s.shouldUseNativeValidation)),P=async(e,t,r={valid:!0})=>{for(const a in e){const n=e[a];if(n){const{_f:e,...a}=n;if(e){const a=V.array.has(e.name),i=await de(n,A,C,s.shouldUseNativeValidation&&!t,a);if(i[e.name]&&(r.valid=!1,t))break;!t&&(_(i,e.name)?a?Q(u.errors,i,e.name):q(u.errors,e.name,i[e.name]):ge(u.errors,e.name))}a&&await P(a,t,r)}}return r.valid},W=(e,t)=>(e&&t&&q(A,e,t),!xe(se(),b)),H=(e,t,r)=>L(e,V,{...x.mount?A:p(t)?b:N(e)?{[e]:t}:t},r,t),I=(e,t,r={})=>{const s=_(c,e);let n=t;if(s){const r=s._f;r&&(!r.disabled&&q(A,e,Ee(t,r)),n=Z(r.ref)&&i(t)?"":t,Ve(r.ref)?[...r.ref.options].forEach((e=>e.selected=n.includes(e.value))):r.refs?a(r.ref)?r.refs.length>1?r.refs.forEach((e=>(!e.defaultChecked||!e.disabled)&&(e.checked=Array.isArray(n)?!!n.find((t=>t===e.value)):n===e.value))):r.refs[0]&&(r.refs[0].checked=!!n):r.refs.forEach((e=>e.checked=e.value===n)):X(r.ref)?r.ref.value="":(r.ref.value=n,r.ref.type||w.values.next({name:e,values:{...A}})))}(r.shouldDirty||r.shouldTouch)&&B(e,n,r.shouldTouch,r.shouldDirty,!0),r.shouldValidate&&re(e)},$=(e,t,r)=>{for(const s in t){const a=t[s],i=`${e}.${s}`,u=_(c,i);!V.array.has(e)&&Ae(a)&&(!u||u._f)||n(a)?I(i,a,r):$(i,a,r)}},G=(e,r,s={})=>{const a=_(c,e),n=V.array.has(e),o=m(r);q(A,e,o),n?(w.array.next({name:e,values:{...A}}),(S.isDirty||S.dirtyFields)&&s.shouldDirty&&w.state.next({name:e,dirtyFields:Ce(b,A),isDirty:W(e,o)})):!a||a._f||i(o)?I(e,o,s):$(e,o,s),z(e,V)&&w.state.next({...u}),w.values.next({name:e,values:{...A}}),!x.mount&&t()},ee=async e=>{const t=e.target;let a=t.name,n=!0;const i=_(c,a),o=e=>{n=Number.isNaN(e)||e===_(A,a,e)};if(i){let d,f;const m=t.type?Oe(i._f):l(e),y=e.type===g.BLUR||e.type===g.FOCUS_OUT,p=!Ue(i._f)&&!s.resolver&&!_(u.errors,a)&&!i._f.deps||Ne(y,_(u.touchedFields,a),u.isSubmitted,k,D),h=z(a,V,y);q(A,a,m),y?(i._f.onBlur&&i._f.onBlur(e),r&&r(0)):i._f.onChange&&i._f.onChange(e);const v=B(a,m,y,!1),b=!E(v)||h;if(!y&&w.values.next({name:a,type:e.type,values:{...A}}),p)return S.isValid&&O(),b&&w.state.next({name:a,...h?{}:v});if(!y&&h&&w.state.next({...u}),T(!0),s.resolver){const{errors:e}=await M([a]);if(o(m),n){const t=Be(u.errors,c,a),r=Be(e,c,t.name||a);d=r.error,a=r.name,f=E(e)}}else d=(await de(i,A,C,s.shouldUseNativeValidation))[a],o(m),n&&(d?f=!1:S.isValid&&(f=await P(c,!0)));n&&(i._f.deps&&re(i._f.deps),R(a,f,d,v))}},te=(e,t)=>{if(_(u.errors,t)&&e.focus)return e.focus(),1},re=async(e,t={})=>{let r,a;const n=j(e);if(T(!0),s.resolver){const t=await(async e=>{const{errors:t}=await M(e);if(e)for(const r of e){const e=_(t,r);e?q(u.errors,r,e):ge(u.errors,r)}else u.errors=t;return t})(p(e)?e:n);r=E(t),a=e?!n.some((e=>_(t,e))):r}else e?(a=(await Promise.all(n.map((async e=>{const t=_(c,e);return await P(t&&t._f?{[e]:t}:t)})))).every(Boolean),(a||u.isValid)&&O()):a=r=await P(c);return w.state.next({...!N(e)||S.isValid&&r!==u.isValid?{}:{name:e},...s.resolver||!e?{isValid:r}:{},errors:u.errors,isValidating:!1}),t.shouldFocus&&!a&&K(c,te,e?n:V.mount),a},se=e=>{const t={...b,...x.mount?A:{}};return p(e)?t:N(e)?_(t,e):e.map((e=>_(t,e)))},ae=(e,t)=>({invalid:!!_((t||u).errors,e),isDirty:!!_((t||u).dirtyFields,e),isTouched:!!_((t||u).touchedFields,e),error:_((t||u).errors,e)}),ne=(e,t,r)=>{const s=(_(c,e,{_f:{}})._f||{}).ref;q(u.errors,e,{...t,ref:s}),w.state.next({name:e,errors:u.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ie=(e,t={})=>{for(const r of e?j(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(ge(c,r),ge(A,r)),!t.keepError&&ge(u.errors,r),!t.keepDirty&&ge(u.dirtyFields,r),!t.keepTouched&&ge(u.touchedFields,r),!s.shouldUnregister&&!t.keepDefaultValue&&ge(b,r);w.values.next({values:{...A}}),w.state.next({...u,...t.keepDirty?{isDirty:W()}:{}}),!t.keepIsValid&&O()},ue=({disabled:e,name:t,field:r,fields:s,value:a})=>{if(h(e)){const n=e?void 0:p(a)?Oe(r?r._f:_(s,t)._f):a;q(A,t,n),B(t,n,!1,!1,!0)}},oe=(e,t={})=>{let r=_(c,e);const a=h(t.disabled);return q(c,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?ue({field:r,disabled:t.disabled,name:e,value:t.value}):U(e,!0,t.value),{...a?{disabled:t.disabled}:{},...s.progressive?{required:!!t.required,min:Te(t.min),max:Te(t.max),minLength:Te(t.minLength),maxLength:Te(t.maxLength),pattern:Te(t.pattern)}:{},name:e,onChange:ee,onBlur:ee,ref:a=>{if(a){oe(e,t),r=_(c,e);const s=p(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=Fe(s),i=r._f.refs||[];if(n?i.find((e=>e===s)):s===r._f.ref)return;q(c,e,{_f:{...r._f,...n?{refs:[...i.filter(Se),s,...Array.isArray(_(b,e))?[{}]:[]],ref:{type:s.type,name:e}}:{ref:s}}}),U(e,!1,void 0,s)}else r=_(c,e,{}),r._f&&(r._f.mount=!1),(s.shouldUnregister||t.shouldUnregister)&&(!d(V.array,e)||!x.action)&&V.unMount.add(e)}}},le=()=>s.shouldFocusError&&K(c,te,V.mount),ce=(e,t)=>async r=>{r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=m(A);if(w.state.next({isSubmitting:!0}),s.resolver){const{errors:e,values:t}=await M();u.errors=e,a=t}else await P(c);ge(u.errors,"root"),E(u.errors)?(w.state.next({errors:{}}),await e(a,r)):(t&&await t({...u.errors},r),le(),setTimeout(le)),w.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:E(u.errors),submitCount:u.submitCount+1,errors:u.errors})},fe=(r,s={})=>{const a=r?m(r):b,n=m(a),i=r&&!E(r)?n:b;if(s.keepDefaultValues||(b=a),!s.keepValues){if(s.keepDirtyValues)for(const e of V.mount)_(u.dirtyFields,e)?q(i,e,_(A,e)):G(e,_(i,e));else{if(f&&p(r))for(const e of V.mount){const t=_(c,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Z(e)){const t=e.closest("form");if(t){t.reset();break}}}}c={}}A=e.shouldUnregister?s.keepDefaultValues?m(b):{}:m(i),w.array.next({values:{...i}}),w.values.next({values:{...i}})}V={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&t(),x.mount=!S.isValid||!!s.keepIsValid,x.watch=!!e.shouldUnregister,w.state.next({submitCount:s.keepSubmitCount?u.submitCount:0,isDirty:s.keepDirty?u.isDirty:!(!s.keepDefaultValues||xe(r,b)),isSubmitted:!!s.keepIsSubmitted&&u.isSubmitted,dirtyFields:s.keepDirtyValues?u.dirtyFields:s.keepDefaultValues&&r?Ce(b,r):{},touchedFields:s.keepTouched?u.touchedFields:{},errors:s.keepErrors?u.errors:{},isSubmitSuccessful:!!s.keepIsSubmitSuccessful&&u.isSubmitSuccessful,isSubmitting:!1})},me=(e,t)=>fe(Y(e)?e(A):e,t);return{control:{register:oe,unregister:ie,getFieldState:ae,handleSubmit:ce,setError:ne,_executeSchema:M,_getWatch:H,_getDirty:W,_updateValid:O,_removeUnmounted:()=>{for(const e of V.unMount){const t=_(c,e);t&&(t._f.refs?t._f.refs.every((e=>!Se(e))):!Se(t._f.ref))&&ie(e)}V.unMount=new Set},_updateFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r){if(x.action=!0,n&&Array.isArray(_(c,e))){const t=r(_(c,e),s.argA,s.argB);a&&q(c,e,t)}if(n&&Array.isArray(_(u.errors,e))){const t=r(_(u.errors,e),s.argA,s.argB);a&&q(u.errors,e,t),Le(u.errors,e)}if(S.touchedFields&&n&&Array.isArray(_(u.touchedFields,e))){const t=r(_(u.touchedFields,e),s.argA,s.argB);a&&q(u.touchedFields,e,t)}S.dirtyFields&&(u.dirtyFields=Ce(b,A)),w.state.next({name:e,isDirty:W(e,t),dirtyFields:u.dirtyFields,errors:u.errors,isValid:u.isValid})}else q(A,e,t)},_updateDisabledField:ue,_getFieldArray:t=>y(_(x.mount?A:b,t,e.shouldUnregister?_(b,t,[]):[])),_reset:fe,_resetDefaultValues:()=>Y(s.defaultValues)&&s.defaultValues().then((e=>{me(e,s.resetOptions),w.state.next({isLoading:!1})})),_updateFormState:e=>{u={...u,...e}},_disableForm:e=>{h(e)&&(w.state.next({disabled:e}),K(c,((t,r)=>{let s=e;const a=_(c,r);a&&h(a._f.disabled)&&(s||(s=a._f.disabled)),t.disabled=s}),0,!1))},_subjects:w,_proxyFormState:S,_setErrors:e=>{u.errors=e,w.state.next({errors:u.errors,isValid:!1})},get _fields(){return c},get _formValues(){return A},get _state(){return x},set _state(e){x=e},get _defaultValues(){return b},get _names(){return V},set _names(e){V=e},get _formState(){return u},set _formState(e){u=e},get _options(){return s},set _options(e){s={...s,...e}}},trigger:re,register:oe,handleSubmit:ce,watch:(e,t)=>Y(e)?w.values.subscribe({next:r=>e(H(void 0,t),r)}):H(e,t,!0),setValue:G,getValues:se,reset:me,resetField:(e,t={})=>{_(c,e)&&(p(t.defaultValue)?G(e,m(_(b,e))):(G(e,t.defaultValue),q(b,e,m(t.defaultValue))),t.keepTouched||ge(u.touchedFields,e),t.keepDirty||(ge(u.dirtyFields,e),u.isDirty=t.defaultValue?W(e,m(_(b,e))):W()),t.keepError||(ge(u.errors,e),S.isValid&&O()),w.state.next({...u}))},clearErrors:e=>{e&&j(e).forEach((e=>ge(u.errors,e))),w.state.next({errors:e?u.errors:{}})},unregister:ie,setError:ne,setFocus:(e,t={})=>{const r=_(c,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:ae}}e.Controller=e=>e.render(W(e)),e.Form=function(e){const t=k(),[r,a]=s.default.useState(!1),{control:n=t.control,onSubmit:i,children:u,action:o,method:l=H,headers:d,encType:c,onError:f,render:m,onSuccess:y,validateStatus:p,...h}=e,g=async t=>{let r=!1,s="";await n.handleSubmit((async e=>{const a=new FormData;let u="";try{u=JSON.stringify(e)}catch(e){}for(const t of n._names.mount)a.append(t,_(e,t));if(i&&await i({data:e,event:t,method:l,formData:a,formDataJson:u}),o)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(o,{method:l,headers:{...d,...c?{"Content-Type":c}:{}},body:e?u:a});t&&(p?!p(t.status):t.status<200||t.status>=300)?(r=!0,f&&f({response:t}),s=String(t.status)):y&&y({response:t})}catch(e){r=!0,f&&f({error:e})}}))(t),r&&e.control&&(e.control._subjects.state.next({isSubmitSuccessful:!1}),e.control.setError("root.server",{type:s}))};return s.default.useEffect((()=>{a(!0)}),[]),m?s.default.createElement(s.default.Fragment,null,m({submit:g})):s.default.createElement("form",{noValidate:r,action:o,method:l,encType:c,onSubmit:g,...h},u)},e.FormProvider=e=>{const{children:t,...r}=e;return s.default.createElement(D.Provider,{value:r},t)},e.appendErrors=I,e.get=_,e.set=q,e.useController=W,e.useFieldArray=function(e){const t=k(),{control:r=t.control,name:a,keyName:n="id",shouldUnregister:i}=e,[u,o]=s.default.useState(r._getFieldArray(a)),l=s.default.useRef(r._getFieldArray(a).map($)),d=s.default.useRef(u),c=s.default.useRef(a),f=s.default.useRef(!1);c.current=a,d.current=u,r._names.array.add(a),e.rules&&r.register(a,e.rules),U({next:({values:e,name:t})=>{if(t===c.current||!t){const t=_(e,c.current);Array.isArray(t)&&(o(t),l.current=t.map($))}},subject:r._subjects.array});const y=s.default.useCallback((e=>{f.current=!0,r._updateFieldArray(a,e)}),[r,a]);return s.default.useEffect((()=>{if(r._state.action=!1,z(a,r._names)&&r._subjects.state.next({...r._formState}),f.current&&(!J(r._options.mode).isOnSubmit||r._formState.isSubmitted))if(r._options.resolver)r._executeSchema([a]).then((e=>{const t=_(e.errors,a),s=_(r._formState.errors,a);(s?!t&&s.type||t&&(s.type!==t.type||s.message!==t.message):t&&t.type)&&(t?q(r._formState.errors,a,t):ge(r._formState.errors,a),r._subjects.state.next({errors:r._formState.errors}))}));else{const e=_(r._fields,a);e&&e._f&&de(e,r._formValues,r._options.criteriaMode===v.all,r._options.shouldUseNativeValidation,!0).then((e=>!E(e)&&r._subjects.state.next({errors:Q(r._formState.errors,e,a)})))}r._subjects.values.next({name:a,values:{...r._formValues}}),r._names.focus&&K(r._fields,((e,t)=>{if(r._names.focus&&t.startsWith(r._names.focus)&&e.focus)return e.focus(),1})),r._names.focus="",r._updateValid(),f.current=!1}),[u,a,r]),s.default.useEffect((()=>(!_(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);he(s,e,t),he(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,he,{argA:e,argB:t},!1)}),[y,a,r]),move:s.default.useCallback(((e,t)=>{const s=r._getFieldArray(a);ye(s,e,t),ye(l.current,e,t),y(s),o(s),r._updateFieldArray(a,s,ye,{argA:e,argB:t},!1)}),[y,a,r]),prepend:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=pe(r._getFieldArray(a),s);r._names.focus=G(a,0,t),l.current=pe(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,pe,{argA:fe(e)})}),[y,a,r]),append:s.default.useCallback(((e,t)=>{const s=j(m(e)),n=ce(r._getFieldArray(a),s);r._names.focus=G(a,n.length-1,t),l.current=ce(l.current,s.map($)),y(n),o(n),r._updateFieldArray(a,n,ce,{argA:fe(e)})}),[y,a,r]),remove:s.default.useCallback((e=>{const t=_e(r._getFieldArray(a),e);l.current=_e(l.current,e),y(t),o(t),r._updateFieldArray(a,t,_e,{argA:e})}),[y,a,r]),insert:s.default.useCallback(((e,t,s)=>{const n=j(m(t)),i=me(r._getFieldArray(a),e,n);r._names.focus=G(a,e,s),l.current=me(l.current,e,n.map($)),y(i),o(i),r._updateFieldArray(a,i,me,{argA:e,argB:fe(t)})}),[y,a,r]),update:s.default.useCallback(((e,t)=>{const s=m(t),n=ve(r._getFieldArray(a),e,s);l.current=[...n].map(((t,r)=>t&&r!==e?l.current[r]:$())),y(n),o([...n]),r._updateFieldArray(a,n,ve,{argA:e,argB:s},!0,!1)}),[y,a,r]),replace:s.default.useCallback((e=>{const t=j(m(e));l.current=t.map($),y([...t]),o([...t]),r._updateFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,r]),fields:s.default.useMemo((()=>u.map(((e,t)=>({...e,[n]:l.current[t]||$()})))),[u,n])}},e.useForm=function(e={}){const t=s.default.useRef(),r=s.default.useRef(),[a,n]=s.default.useState({isDirty:!1,isValidating:!1,isLoading:Y(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Y(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Me(e,(()=>n((e=>({...e}))))),formState:a});const i=t.current.control;return i._options=e,U({subject:i._subjects.state,next:e=>{O(e,i._proxyFormState,i._updateFormState,!0)&&n({...i._formState})}}),s.default.useEffect((()=>i._disableForm(e.disabled)),[i,e.disabled]),s.default.useEffect((()=>{if(i._proxyFormState.isDirty){const e=i._getDirty();e!==a.isDirty&&i._subjects.state.next({isDirty:e})}}),[i,a.isDirty]),s.default.useEffect((()=>{e.values&&!xe(e.values,r.current)?(i._reset(e.values,i._options.resetOptions),r.current=e.values,n((e=>({...e})))):i._resetDefaultValues()}),[e.values,i]),s.default.useEffect((()=>{e.errors&&i._setErrors(e.errors)}),[e.errors,i]),s.default.useEffect((()=>{i._state.mount||(i._updateValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()})),t.current.formState=C(a,i),t.current},e.useFormContext=k,e.useFormState=B,e.useWatch=R,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,2 +0,2 @@ | ||
import { FieldValues, UseFormReturn } from '../types'; | ||
import { FieldErrors, FieldValues, UseFormReturn } from '../types'; | ||
export declare function createFormControl<TFieldValues extends FieldValues = FieldValues, TContext = any>(props: Partial<{ | ||
@@ -8,2 +8,3 @@ mode: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all"; | ||
values: TFieldValues; | ||
errors: FieldErrors<TFieldValues>; | ||
resetOptions: Partial<{ | ||
@@ -10,0 +11,0 @@ keepDirtyValues: boolean; |
import { FieldRefs, InternalFieldName } from '../types'; | ||
declare const focusFieldBy: (fields: FieldRefs, callback: (name?: string) => boolean, fieldsNames?: Set<InternalFieldName> | InternalFieldName[]) => void; | ||
declare const focusFieldBy: ( | ||
fields: FieldRefs, | ||
callback: (name?: string) => boolean, | ||
fieldsNames?: Set<InternalFieldName> | InternalFieldName[], | ||
) => void; | ||
export default focusFieldBy; | ||
//# sourceMappingURL=focusFieldBy.d.ts.map | ||
//# sourceMappingURL=focusFieldBy.d.ts.map |
@@ -1,3 +0,3 @@ | ||
declare const _default: <T>(defaultValues: T, formValues: T) => any; | ||
declare const _default: <T>(defaultValues: T, formValues: T) => Record<Extract<keyof T, string>, boolean | Record<string, any>>; | ||
export default _default; | ||
//# sourceMappingURL=getDirtyFields.d.ts.map |
@@ -1,10 +0,4 @@ | ||
import { Mode } from '../types'; | ||
declare const _default: (mode?: Mode) => { | ||
isOnSubmit: boolean; | ||
isOnBlur: boolean; | ||
isOnChange: boolean; | ||
isOnAll: boolean; | ||
isOnTouch: boolean; | ||
}; | ||
import { Mode, ValidationModeFlags } from '../types'; | ||
declare const _default: (mode?: Mode) => ValidationModeFlags; | ||
export default _default; | ||
//# sourceMappingURL=getValidationModes.d.ts.map |
@@ -0,12 +1,7 @@ | ||
import { ValidationModeFlags } from '../types'; | ||
declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode: { | ||
isOnBlur: boolean; | ||
isOnChange: boolean; | ||
}, mode: Partial<{ | ||
isOnSubmit: boolean; | ||
isOnBlur: boolean; | ||
isOnChange: boolean; | ||
isOnTouch: boolean; | ||
isOnAll: boolean; | ||
}>) => boolean; | ||
}, mode: Partial<ValidationModeFlags>) => boolean; | ||
export default _default; | ||
//# sourceMappingURL=skipValidation.d.ts.map |
@@ -29,2 +29,9 @@ import React from 'react'; | ||
export type Mode = keyof ValidationMode; | ||
export type ValidationModeFlags = { | ||
isOnSubmit: boolean; | ||
isOnBlur: boolean; | ||
isOnChange: boolean; | ||
isOnAll: boolean; | ||
isOnTouch: boolean; | ||
}; | ||
export type CriteriaMode = 'firstError' | 'all'; | ||
@@ -60,2 +67,3 @@ export type SubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event?: React.BaseSyntheticEvent) => unknown | Promise<unknown>; | ||
values: TFieldValues; | ||
errors: FieldErrors<TFieldValues>; | ||
resetOptions: Parameters<UseFormReset<TFieldValues>>[1]; | ||
@@ -481,3 +489,3 @@ resolver: Resolver<TFieldValues, TContext>; | ||
*/ | ||
export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = (onValid: TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : SubmitHandler<TFieldValues>, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; | ||
export type UseFormHandleSubmit<TFieldValues extends FieldValues, TTransformedValues extends FieldValues | undefined = undefined> = (onValid: TTransformedValues extends undefined ? SubmitHandler<TFieldValues> : TTransformedValues extends FieldValues ? SubmitHandler<TTransformedValues> : never, onInvalid?: SubmitErrorHandler<TFieldValues>) => (e?: React.BaseSyntheticEvent) => Promise<void>; | ||
/** | ||
@@ -592,2 +600,3 @@ * Reset a field state and reference. | ||
_getFieldArray: <TFieldArrayValues>(name: InternalFieldName) => Partial<TFieldArrayValues>[]; | ||
_setErrors: (errors: FieldErrors<TFieldValues>) => void; | ||
_updateDisabledField: (props: { | ||
@@ -594,0 +603,0 @@ disabled?: boolean; |
@@ -22,3 +22,3 @@ import { NestedValue } from './form'; | ||
export type DeepPartial<T> = T extends BrowserNativeObject | NestedValue ? T : { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]; | ||
}; | ||
@@ -25,0 +25,0 @@ export type DeepPartialSkipArrayKey<T> = T extends BrowserNativeObject | NestedValue ? T : T extends ReadonlyArray<any> ? { |
@@ -1,2 +0,3 @@ | ||
export default function append<T>(data: T[], value: T | T[]): T[]; | ||
declare const _default: <T>(data: T[], value: T | T[]) => T[]; | ||
export default _default; | ||
//# sourceMappingURL=append.d.ts.map |
@@ -13,3 +13,4 @@ import { Noop } from '../types'; | ||
} & Observer<T>; | ||
export default function createSubject<T>(): Subject<T>; | ||
declare const _default: <T>() => Subject<T>; | ||
export default _default; | ||
//# sourceMappingURL=createSubject.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export declare function deepMerge<T extends Record<keyof T, any>, U extends Record<keyof U, any>>(target: T, source: U): T & U; | ||
export default function deepMerge<T extends Record<keyof T, any>, U extends Record<keyof U, any>>(target: T, source: U): T & U; | ||
//# sourceMappingURL=deepMerge.d.ts.map |
@@ -1,3 +0,3 @@ | ||
declare const _default: <T>(obj: T, path?: string, defaultValue?: unknown) => any; | ||
declare const _default: <T>(object: T, path?: string, defaultValue?: unknown) => any; | ||
export default _default; | ||
//# sourceMappingURL=get.d.ts.map |
@@ -1,4 +0,4 @@ | ||
export declare const isObjectType: (value: unknown) => boolean; | ||
export declare const isObjectType: (value: unknown) => value is object; | ||
declare const _default: <T extends object>(value: unknown) => value is T; | ||
export default _default; | ||
//# sourceMappingURL=isObject.d.ts.map |
@@ -1,2 +0,3 @@ | ||
export default function prepend<T>(data: T[], value: T | T[]): T[]; | ||
declare const _default: <T>(data: T[], value: T | T[]) => T[]; | ||
export default _default; | ||
//# sourceMappingURL=prepend.d.ts.map |
import { FieldValues } from '../types'; | ||
export default function set(object: FieldValues, path: string, value?: unknown): FieldValues; | ||
declare const _default: (object: FieldValues, path: string, value?: unknown) => FieldValues; | ||
export default _default; | ||
//# sourceMappingURL=set.d.ts.map |
@@ -1,2 +0,3 @@ | ||
export declare function sleep(ms: number): Promise<unknown>; | ||
declare const _default: (ms: number) => Promise<unknown>; | ||
export default _default; | ||
//# sourceMappingURL=sleep.d.ts.map |
{ | ||
"name": "react-hook-form", | ||
"description": "Performant, flexible and extensible forms library for React Hooks", | ||
"version": "7.48.2", | ||
"version": "7.49.3", | ||
"main": "dist/index.cjs.js", | ||
@@ -22,2 +22,3 @@ "module": "dist/index.esm.mjs", | ||
"types": "./dist/index.d.ts", | ||
"react-server": "./dist/react-server.esm.mjs", | ||
"import": "./dist/index.esm.mjs", | ||
@@ -53,3 +54,4 @@ "require": "./dist/index.cjs.js" | ||
"bundlewatch": "pnpm build:modern && bundlewatch", | ||
"start": "pnpm build:esm && pnpm --dir ./app install && pnpm --dir ./app run dev" | ||
"start": "pnpm build:esm && pnpm --dir ./app install && pnpm --dir ./app run dev", | ||
"csb:install": "npm i -g pnpm@8 && pnpm i" | ||
}, | ||
@@ -147,5 +149,5 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=12.22.0" | ||
}, | ||
"packageManager": "pnpm@7.18.0" | ||
"node": ">=18", | ||
"pnpm": "8" | ||
} | ||
} |
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
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
887281
306
5089