1 | "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,_=e=>/^\w*$/.test(e),g=e=>f(e.replace(/["|']|\]/g,"").split(/\.|\[/)),h=(e,t,r)=>{let s=-1;const a=_(t)?[t]:g(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])?{}:[]}if("__proto__"===t)return;e[t]=n,e=e[t]}return e};const v={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},b={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},x="max",A="min",V="maxLength",F="minLength",S="pattern",w="required",D="validate",k=t.default.createContext(null),C=()=>t.default.useContext(k);var E=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const n in e)Object.defineProperty(a,n,{get:()=>{const a=n;return t._proxyFormState[a]!==b.all&&(t._proxyFormState[a]=!s||b.all),r&&(r[a]=!0),e[a]}});return a},O=e=>i(e)&&!Object.keys(e).length,j=(e,t,r,s)=>{r(e);const{name:a,...n}=e;return O(n)||Object.keys(n).length>=Object.keys(t).length||Object.keys(n).find((e=>t[e]===(!s||b.all)))},U=e=>Array.isArray(e)?e:[e],T=(e,t,r)=>!e||!t||e===t||U(e).some((e=>e&&(r?e===t:e.startsWith(t)||t.startsWith(e))));function B(e){const r=t.default.useRef(e);r.current=e,t.default.useEffect((()=>{const t=!e.disabled&&r.current.subject&&r.current.subject.subscribe({next:r.current.next});return()=>{t&&t.unsubscribe()}}),[e.disabled])}function N(e){const r=C(),{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,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),c=t.default.useRef(n);return c.current=n,B({disabled:a,next:e=>l.current&&T(c.current,e.name,i)&&j(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]),E(u,s,d.current,!1)}var L=e=>"string"==typeof e,M=(e,t,r,s,a)=>L(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 R(e){const r=C(),{control:s=r.control,name:a,defaultValue:n,disabled:i,exact:u}=e||{},o=t.default.useRef(a);o.current=a,B({disabled:i,subject:s._subjects.values,next:e=>{T(o.current,e.name,u)&&d(c(M(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}function P(e){const r=C(),{name:s,disabled:a,control:n=r.control,shouldUnregister:i}=e,l=o(n._names.array,s),d=R({control:n,name:s,defaultValue:y(n._formValues,s,y(n._defaultValues,s,e.defaultValue)),exact:!0}),f=N({control:n,name:s}),_=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&&(r._f.mount=t)};if(t(s,!0),e){const e=c(y(n._options.defaultValues,s));h(n._defaultValues,s,e),m(y(n._formValues,s))&&h(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=>_.current.onChange({target:{value:u(e),name:s},type:v.CHANGE})),[s]),onBlur:t.default.useCallback((()=>_.current.onBlur({target:{value:y(n._formValues,s),name:s},type:v.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)},isValidating:{enumerable:!0,get:()=>!!y(f.validatingFields,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===b.onSubmit,isOnBlur:e===b.onBlur,isOnChange:e===b.onChange,isOnAll:e===b.all,isOnTouch:e===b.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=U(y(e,r));return h(s,"root",t[r]),h(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=>L(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:g,pattern:h,validate:v,name:b,valueAsNumber:k,mount:C,disabled:E}=e._f,j=y(t,b);if(!C||E)return{};const U=l?l[0]:o,T=e=>{n&&U.reportValidity&&(U.setCustomValidity(p(e)?"":e||""),U.reportValidity())},B={},N=Z(o),M=r(o),R=N||M,P=(k||K(o))&&m(o.value)&&m(j)||X(o)&&""===o.value||""===j||Array.isArray(j)&&!j.length,q=W.bind(null,b,s,B),I=(e,t,r,s=V,a=F)=>{const n=e?t:r;B[b]={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||N&&!ne(l).isValid)){const{value:e,message:t}=Y(d)?{value:!!d,message:d}:ue(d);if(e&&(B[b]={type:w,message:t,ref:U,...q(w,t)},!s))return T(t),B}if(!(P||a(_)&&a(g))){let e,t;const r=ue(g),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;L(r.value)&&j&&(e=i?a(j)>a(r.value):u?j>r.value:s>new Date(r.value)),L(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,x,A),!s))return T(B[b].message),B}if((c||f)&&!P&&(L(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 T(B[b].message),B}if(h&&!P&&L(j)){const{value:e,message:t}=ue(h);if(ee(e)&&!j.match(e)&&(B[b]={type:S,message:t,ref:o,...q(S,t)},!s))return T(t),B}if(v)if(Q(v)){const e=ie(await v(j,t),U);if(e&&(B[b]={...e,...q(D,e.message)},!s))return T(e.message),B}else if(i(v)){let e={};for(const r in v){if(!O(e)&&!s)break;const a=ie(await v[r](j,t),U,r);a&&(e={...a,...q(r,a.message)},T(a.message),s&&(B[b]=e))}if(!O(e)&&(B[b]={ref:U,...e},!s))return B}return T(!0),B},le=(e,t)=>[...e,...U(t)],de=e=>Array.isArray(e)?e.map((()=>{})):void 0;function ce(e,t,r){return[...e.slice(0,t),...U(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)=>[...U(t),...U(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,U(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:_(t)?[t]:g(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=m(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,n=r[a];return s&&delete s[n],0!==a&&(i(s)&&O(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 ge=(e,t,r)=>(e[t]=r,e);var he=()=>{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&&L(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&&h(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 Ue(e,t,r){const s=y(e,r);if(s||_(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 Te=(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:b.onSubmit,reValidateMode:b.onChange,shouldFocusError:!0};function Le(e={}){let t,n={...Ne,...e},l={submitCount:0,isDirty:!1,isLoading:Q(n.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:n.errors||{},disabled:n.disabled||!1},_={},g=(i(n.defaultValues)||i(n.values))&&c(n.defaultValues||n.values)||{},x=n.shouldUnregister?{}:c(g),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,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},w={values:he(),array:he(),state:he()},D=H(n.mode),k=H(n.reValidateMode),C=n.criteriaMode===b.all,E=async e=>{if(S.isValid||e){const e=n.resolver?O((await R()).errors):await P(_,!0);e!==l.isValid&&w.state.next({isValid:e})}},j=(e,t)=>{(S.isValidating||S.validatingFields)&&((e||Array.from(V.mount)).forEach((e=>{e&&(t?h(l.validatingFields,e,t):_e(l.validatingFields,e))})),w.state.next({validatingFields:l.validatingFields,isValidating:!O(l.validatingFields)}))},T=(e,t,r,s)=>{const a=y(_,e);if(a){const n=y(x,e,m(r)?y(g,e):r);m(n)||s&&s.defaultChecked||t?h(x,e,t?n:Ce(a._f)):I(e,n),A.mount&&E()}},B=(e,t,r,s,a)=>{let n=!1,i=!1;const u={name:e},o=!!(y(_,e)&&y(_,e)._f&&y(_,e)._f.disabled);if(!r||s){S.isDirty&&(i=l.isDirty,l.isDirty=u.isDirty=q(),n=i!==u.isDirty);const r=o||be(y(g,e),t);i=!(o||!y(l.dirtyFields,e)),r||o?_e(l.dirtyFields,e):h(l.dirtyFields,e,!0),u.dirtyFields=l.dirtyFields,n=n||S.dirtyFields&&i!==!r}if(r){const t=y(l.touchedFields,e);t||(h(l.touchedFields,e,r),u.touchedFields=l.touchedFields,n=n||S.touchedFields&&t!==r)}return n&&a&&w.state.next(u),n?u:{}},N=(r,s,a,n)=>{const i=y(l.errors,r),u=S.isValid&&p(s)&&l.isValid!==s;var o;if(e.delayError&&a?(o=()=>((e,t)=>{h(l.errors,e,t),w.state.next({errors:l.errors})})(r,a),t=e=>{clearTimeout(F),F=setTimeout(o,e)},t(e.delayError)):(clearTimeout(F),t=null,a?h(l.errors,r,a):_e(l.errors,r)),(a?!be(i,a):i)||!O(n)||u){const e={...n,...u&&p(s)?{isValid:s}:{},errors:l.errors,name:r};l={...l,...e},w.state.next(e)}},R=async e=>{j(e,!0);const t=await n.resolver(x,n.context,Ee(e||V.mount,_,n.criteriaMode,n.shouldUseNativeValidation));return j(e),t},P=async(e,t,r={valid:!0})=>{for(const s in e){const a=e[s];if(a){const{_f:e,...i}=a;if(e){const i=V.array.has(e.name);j([s],!0);const u=await oe(a,x,C,n.shouldUseNativeValidation&&!t,i);if(j([s]),u[e.name]&&(r.valid=!1,t))break;!t&&(y(u,e.name)?i?z(l.errors,u,e.name):h(l.errors,e.name,u[e.name]):_e(l.errors,e.name))}i&&await P(i,t,r)}}return r.valid},q=(e,t)=>(e&&t&&h(x,e,t),!be(re(),g)),W=(e,t,r)=>M(e,V,{...A.mount?x:m(t)?g:L(e)?{[e]:t}:t},r,t),I=(e,t,s={})=>{const n=y(_,e);let i=t;if(n){const s=n._f;s&&(!s.disabled&&h(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)&&B(e,i,s.shouldTouch,s.shouldDirty,!0),s.shouldValidate&&te(e)},$=(e,t,r)=>{for(const a in t){const n=t[a],i=`${e}.${a}`,u=y(_,i);!V.array.has(e)&&ve(n)&&(!u||u._f)||s(n)?I(i,n,r):$(i,n,r)}},Y=(e,t,r={})=>{const s=y(_,e),n=V.array.has(e),i=c(t);h(x,e,i),n?(w.array.next({name:e,values:{...x}}),(S.isDirty||S.dirtyFields)&&r.shouldDirty&&w.state.next({name:e,dirtyFields:De(g,x),isDirty:q(e,i)})):!s||s._f||a(i)?I(e,i,r):$(e,i,r),G(e,V)&&w.state.next({...l}),w.values.next({name:A.mount?e:void 0,values:{...x}})},Z=async e=>{A.mount=!0;const r=e.target;let s=r.name,a=!0;const i=y(_,s),o=e=>{a=Number.isNaN(e)||e===y(x,s,e)};if(i){let d,c;const f=r.type?Ce(i._f):u(e),m=e.type===v.BLUR||e.type===v.FOCUS_OUT,p=!je(i._f)&&!n.resolver&&!y(l.errors,s)&&!i._f.deps||Te(m,y(l.touchedFields,s),l.isSubmitted,k,D),g=G(s,V,m);h(x,s,f),m?(i._f.onBlur&&i._f.onBlur(e),t&&t(0)):i._f.onChange&&i._f.onChange(e);const b=B(s,f,m,!1),A=!O(b)||g;if(!m&&w.values.next({name:s,type:e.type,values:{...x}}),p)return S.isValid&&E(),A&&w.state.next({name:s,...g?{}:b});if(!m&&g&&w.state.next({...l}),n.resolver){const{errors:e}=await R([s]);if(o(f),a){const t=Ue(l.errors,_,s),r=Ue(e,_,t.name||s);d=r.error,s=r.name,c=O(e)}}else j([s],!0),d=(await oe(i,x,C,n.shouldUseNativeValidation))[s],j([s]),o(f),a&&(d?c=!1:S.isValid&&(c=await P(_,!0)));a&&(i._f.deps&&te(i._f.deps),N(s,c,d,b))}},ee=(e,t)=>{if(y(l.errors,t)&&e.focus)return e.focus(),1},te=async(e,t={})=>{let r,s;const a=U(e);if(n.resolver){const t=await(async e=>{const{errors:t}=await R(e);if(e)for(const r of e){const e=y(t,r);e?h(l.errors,r,e):_e(l.errors,r)}else l.errors=t;return t})(m(e)?e:a);r=O(t),s=e?!a.some((e=>y(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=y(_,e);return await P(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||l.isValid)&&E()):s=r=await P(_);return w.state.next({...!L(e)||S.isValid&&r!==l.isValid?{}:{name:e},...n.resolver||!e?{isValid:r}:{},errors:l.errors}),t.shouldFocus&&!s&&J(_,ee,e?a:V.mount),s},re=e=>{const t={...A.mount?x:g};return m(e)?t:L(e)?y(t,e):e.map((e=>y(t,e)))},se=(e,t)=>({invalid:!!y((t||l).errors,e),isDirty:!!y((t||l).dirtyFields,e),error:y((t||l).errors,e),isValidating:!!y(l.validatingFields,e),isTouched:!!y((t||l).touchedFields,e)}),ae=(e,t,r)=>{const s=(y(_,e,{_f:{}})._f||{}).ref,a=y(l.errors,e)||{},{ref:n,message:i,type:u,...o}=a;h(l.errors,e,{...o,...t,ref:s}),w.state.next({name:e,errors:l.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ne=(e,t={})=>{for(const r of e?U(e):V.mount)V.mount.delete(r),V.array.delete(r),t.keepValue||(_e(_,r),_e(x,r)),!t.keepError&&_e(l.errors,r),!t.keepDirty&&_e(l.dirtyFields,r),!t.keepTouched&&_e(l.touchedFields,r),!t.keepIsValidating&&_e(l.validatingFields,r),!n.shouldUnregister&&!t.keepDefaultValue&&_e(g,r);w.values.next({values:{...x}}),w.state.next({...l,...t.keepDirty?{isDirty:q()}:{}}),!t.keepIsValid&&E()},ie=({disabled:e,name:t,field:r,fields:s,value:a})=>{if(p(e)&&A.mount||e){const n=e?void 0:m(a)?Ce(r?r._f:y(s,t)._f):a;h(x,t,n),B(t,n,!1,!1,!0)}},ue=(e,t={})=>{let r=y(_,e);const s=p(t.disabled);return h(_,e,{...r||{},_f:{...r&&r._f?r._f:{ref:{name:e}},name:e,mount:!0,...t}}),V.mount.add(e),r?ie({field:r,disabled:t.disabled,name:e,value:t.value}):T(e,!0,t.value),{...s?{disabled:t.disabled}:{},...n.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:Z,onBlur:Z,ref:s=>{if(s){ue(e,t),r=y(_,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;h(_,e,{_f:{...r._f,...n?{refs:[...i.filter(Ve),a,...Array.isArray(y(g,e))?[{}]:[]],ref:{type:a.type,name:e}}:{ref:a}}}),T(e,!1,void 0,a)}else r=y(_,e,{}),r._f&&(r._f.mount=!1),(n.shouldUnregister||t.shouldUnregister)&&(!o(V.array,e)||!A.action)&&V.unMount.add(e)}}},le=()=>n.shouldFocusError&&J(_,ee,V.mount),de=(e,t)=>async r=>{let s;r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=c(x);if(w.state.next({isSubmitting:!0}),n.resolver){const{errors:e,values:t}=await R();l.errors=e,a=t}else await P(_);if(_e(l.errors,"root"),O(l.errors)){w.state.next({errors:{}});try{await e(a,r)}catch(e){s=e}}else t&&await t({...l.errors},r),le(),setTimeout(le);if(w.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:O(l.errors)&&!s,submitCount:l.submitCount+1,errors:l.errors}),s)throw s},ce=(t,r={})=>{const s=t?c(t):g,a=c(s),n=O(t),i=n?g:a;if(r.keepDefaultValues||(g=s),!r.keepValues){if(r.keepDirtyValues)for(const e of V.mount)y(l.dirtyFields,e)?h(i,e,y(x,e)):Y(e,y(i,e));else{if(d&&m(t))for(const e of V.mount){const t=y(_,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}}}}_={}}x=e.shouldUnregister?r.keepDefaultValues?c(g):{}:c(i),w.array.next({values:{...i}}),w.values.next({values:{...i}})}V={mount:r.keepDirtyValues?V.mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},A.mount=!S.isValid||!!r.keepIsValid||!!r.keepDirtyValues,A.watch=!!e.shouldUnregister,w.state.next({submitCount:r.keepSubmitCount?l.submitCount:0,isDirty:!n&&(r.keepDirty?l.isDirty:!(!r.keepDefaultValues||be(t,g))),isSubmitted:!!r.keepIsSubmitted&&l.isSubmitted,dirtyFields:n?{}:r.keepDirtyValues?r.keepDefaultValues&&x?De(g,x):l.dirtyFields:r.keepDefaultValues&&t?De(g,t):r.keepDirty?l.dirtyFields:{},touchedFields:r.keepTouched?l.touchedFields:{},errors:r.keepErrors?l.errors:{},isSubmitSuccessful:!!r.keepIsSubmitSuccessful&&l.isSubmitSuccessful,isSubmitting:!1})},fe=(e,t)=>ce(Q(e)?e(x):e,t);return{control:{register:ue,unregister:ne,getFieldState:se,handleSubmit:de,setError:ae,_executeSchema:R,_getWatch:W,_getDirty:q,_updateValid:E,_removeUnmounted:()=>{for(const e of V.unMount){const t=y(_,e);t&&(t._f.refs?t._f.refs.every((e=>!Ve(e))):!Ve(t._f.ref))&&ne(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(_,e))){const t=r(y(_,e),s.argA,s.argB);a&&h(_,e,t)}if(n&&Array.isArray(y(l.errors,e))){const t=r(y(l.errors,e),s.argA,s.argB);a&&h(l.errors,e,t),Be(l.errors,e)}if(S.touchedFields&&n&&Array.isArray(y(l.touchedFields,e))){const t=r(y(l.touchedFields,e),s.argA,s.argB);a&&h(l.touchedFields,e,t)}S.dirtyFields&&(l.dirtyFields=De(g,x)),w.state.next({name:e,isDirty:q(e,t),dirtyFields:l.dirtyFields,errors:l.errors,isValid:l.isValid})}else h(x,e,t)},_updateDisabledField:ie,_getFieldArray:t=>f(y(A.mount?x:g,t,e.shouldUnregister?y(g,t,[]):[])),_reset:ce,_resetDefaultValues:()=>Q(n.defaultValues)&&n.defaultValues().then((e=>{fe(e,n.resetOptions),w.state.next({isLoading:!1})})),_updateFormState:e=>{l={...l,...e}},_disableForm:e=>{p(e)&&(w.state.next({disabled:e}),J(_,((t,r)=>{const s=y(_,r);s&&(t.disabled=s._f.disabled||e,Array.isArray(s._f.refs)&&s._f.refs.forEach((t=>{t.disabled=s._f.disabled||e})))}),0,!1))},_subjects:w,_proxyFormState:S,_setErrors:e=>{l.errors=e,w.state.next({errors:l.errors,isValid:!1})},get _fields(){return _},get _formValues(){return x},get _state(){return A},set _state(e){A=e},get _defaultValues(){return g},get _names(){return V},set _names(e){V=e},get _formState(){return l},set _formState(e){l=e},get _options(){return n},set _options(e){n={...n,...e}}},trigger:te,register:ue,handleSubmit:de,watch:(e,t)=>Q(e)?w.values.subscribe({next:r=>e(W(void 0,t),r)}):W(e,t,!0),setValue:Y,getValues:re,reset:fe,resetField:(e,t={})=>{y(_,e)&&(m(t.defaultValue)?Y(e,c(y(g,e))):(Y(e,t.defaultValue),h(g,e,c(t.defaultValue))),t.keepTouched||_e(l.touchedFields,e),t.keepDirty||(_e(l.dirtyFields,e),l.isDirty=t.defaultValue?q(e,c(y(g,e))):q()),t.keepError||(_e(l.errors,e),S.isValid&&E()),w.state.next({...l}))},clearErrors:e=>{e&&U(e).forEach((e=>_e(l.errors,e))),w.state.next({errors:e?l.errors:{}})},unregister:ne,setError:ae,setFocus:(e,t={})=>{const r=y(_,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&e.select())}},getFieldState:se}}exports.Controller=e=>e.render(P(e)),exports.Form=function(e){const r=C(),[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:_,...g}=e,h=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:h})):t.default.createElement("form",{noValidate:s,action:o,method:l,encType:c,onSubmit:h,...g},u)},exports.FormProvider=e=>{const{children:r,...s}=e;return t.default.createElement(k.Provider,{value:s},r)},exports.appendErrors=W,exports.get=y,exports.set=h,exports.useController=P,exports.useFieldArray=function(e){const r=C(),{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),B({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?h(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||H(s._options.reValidateMode).isOnSubmit&&H(s._options.mode).isOnSubmit||oe(e,s._formValues,s._options.criteriaMode===b.all,s._options.shouldUseNativeValidation,!0).then((e=>!O(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=U(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=U(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=U(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=ge(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,ge,{argA:e,argB:r},!0,!1)}),[p,a,s]),replace:t.default.useCallback((e=>{const t=U(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:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Q(e.defaultValues)?void 0:e.defaultValues});r.current||(r.current={...Le(e),formState:a});const i=r.current.control;return i._options=e,B({subject:i._subjects.state,next:e=>{j(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()})),t.default.useEffect((()=>{e.shouldUnregister&&i._subjects.values.next({values:i._getWatch()})}),[e.shouldUnregister,i]),r.current.formState=E(a,i),r.current},exports.useFormContext=C,exports.useFormState=N,exports.useWatch=R;
|