@bombillazo/rhf-plus 7.62.0-plus.6 → 7.63.0-plus.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,5 +1,6 @@
1
1
  MIT License
2
2
 
3
+ Copyright (c) 2019-present Beier(Bill) Luo
3
4
  Copyright (c) 2025-present Hector Ayala
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # React Hook Form Plus (RHF+)
2
+
1
3
  <div align="center">
2
4
  <img src="./docs/logo.png" alt="RHF Plus Logo" />
3
5
  </div>
@@ -10,100 +12,76 @@
10
12
 
11
13
  </div>
12
14
 
13
- **RHF+** is a fork of [react-hook-form](https://react-hook-form.com/) (**RHF**) with feature enhancements. It is designed to be a drop-in replacement for RHF, so you can use it in your existing projects without any changes.
15
+ React Hook Form Plus (**RHF+**) is an enhanced fork of [React Hook Form](https://react-hook-form.com/). It is designed to be a drop-in replacement for React Hook Form, so you can use it in your existing projects without any changes.
14
16
 
15
17
  ## Install
16
18
 
17
- ### npm
18
-
19
19
  ```sh
20
20
  npm install @bombillazo/rhf-plus
21
21
  ```
22
22
 
23
- ### yarn
24
-
25
23
  ```sh
26
24
  yarn add @bombillazo/rhf-plus
27
25
  ```
28
26
 
29
- ### pnpm
30
-
31
27
  ```sh
32
28
  pnpm add @bombillazo/rhf-plus
33
29
  ```
34
30
 
35
- ## Enhancements
31
+ Simply replace your React Hook Form import:
36
32
 
37
- - [Imperative form submission](./docs/imperative_submit.md)
38
- - [Smart `disabled` state](./docs/smart-disabled-state.md)
39
- - [JSX error messages](./docs/jsx-error-messages.md)
40
- - [Controllable `isLoading` state](./docs/controllable-is-loading-state.md)
41
- - [Form metadata](./docs/form-metadata.md)
42
- - [`ScrollIntoView` method on field refs](./docs/scroll-into-view-method.md)
43
- - [`Controller` children function](./docs/controller-children-function.md)
44
- - [Form and field `focus` state](./docs/focused-fields.md)
45
- - [Form `isDirtySinceSubmit` state](./docs/is-dirty-since-submit.md)
46
- - [Form `hasBeenSubmitted` state](./docs/has-been-submitted.md)
33
+ ```ts
34
+ // Before
35
+ import { useForm } from 'react-hook-form'
47
36
 
48
- Minor improvements:
37
+ // After
38
+ import { useForm } from '@bombillazo/rhf-plus'
39
+ ```
49
40
 
50
- - [Controller rules update on prop change](./docs/controller-rules-update.md)
51
- - [Empty array validation](./docs/empty-array-validation.md)
52
- - [Add displayName to `useFormContext`](./docs/use-form-context-display-name.md)
53
- - [Improve `useController` error on missing `control` prop](./docs/improve-missing-use-controller-prop-error.md)
41
+ ## 📖 Documentation
54
42
 
55
- ## Motive
43
+ **[View all features and enhancements →](https://bombillazo.github.io/rhf-plus/)**
56
44
 
57
- RHF is a robust and delightful form library for React. Preserving high-quality standards for such a popular package takes time, effort, and thoughtfulness from maintainers. In the case of RHF, this has caused a development bottleneck that slows and stalls contributions.
45
+ ## Motive
58
46
 
59
- Thus, [`rhf-plus`](https://github.com/bombillazo/rhf-plus) was born: a fork of RHF that enhances the library with new features and improvements while keeping the core of RHF intact.
47
+ React Hook Form is a robust and delightful form library for React. Preserving high-quality standards for such a popular package takes time, effort, and thoughtfulness from maintainers. In the case of React Hook Form, this has caused a development bottleneck that slows and stalls contributions.
60
48
 
61
- > [!Warning]
62
- >
63
- > The inevitable reality of adding new form states, methods, and data events includes:
64
- >
65
- > - Additional form renders
66
- > - Increased package size
67
- >
68
- > As we add new enhancements, we work to optimize these features to minimize the impact on form performance.
49
+ Thus, [`rhf-plus`](https://github.com/bombillazo/rhf-plus) was born: a fork of React Hook Form that enhances the library with new features and improvements while keeping the core of the library intact.
69
50
 
70
- ## Goals
51
+ ### 🏁 Goals
71
52
 
72
- - **Features**: This package aims to enhance RHF's functionality. We avoid other development efforts.
73
- - **Compatibility**: New features should be additive, not destructive. `rhf-plus` aims to stay closely synced to the original RHF.
53
+ - **Features**: This package aims to enhance React Hook Form's functionality. We avoid other development efforts.
54
+ - **Compatibility**: New features should be additive and non-breaking. `rhf-plus` aims to stay closely synced to the original React Hook Form.
74
55
  - **Practicality**: The enhancements must be practical and solve real-world problems.
75
56
  - **Speed**: Discuss, review, and ship features fast!
76
- - **Quality**: We maintain the same high-quality standards as RHF. This means clean code, thorough testing, and precise documentation.
57
+ - **Quality**: We maintain the same high-quality standards as React Hook Form. This means clean code, thorough testing, and precise documentation.
77
58
 
78
59
  ### ❌ Out of Scope
79
60
 
80
- - **RHF bugs**
81
- RHF maintainers are responsible for fixing RHF bugs. We focus on fixing bugs related to our enhancements. When RHF bugs are fixed, those fixes are rolled into this package when we sync to the latest RHF version.
61
+ - **React Hook Form bugs**
62
+ React Hook Form maintainers are responsible for fixing its bugs. We focus on fixing bugs related to our enhancements. When those bugs are fixed, they are rolled into this package when we sync to the latest React Hook Form version.
82
63
 
83
64
  - **Refactors**
84
- We do not refactor RHF code. This includes adding new tooling, changing documentation, updating dependency versions, fixing code styling, and anything unrelated to adding new features and enhancements (these changes complicate syncing the fork with RHF).
65
+ We do not refactor React Hook Form code. This includes adding new tooling, changing documentation, updating dependency versions, fixing code styling, and anything unrelated to adding new features and enhancements (these changes complicate syncing the fork with the upstream repository).
85
66
 
86
67
  - **Breaking changes**
87
- We do not introduce breaking changes to the RHF API. We only add new features and enhancements that are backward compatible with the existing RHF API.
68
+ We do not introduce breaking changes to the React Hook Form API. We only add new features and enhancements that are backward compatible with the existing API.
88
69
 
89
70
  - **Complex/bloated features**
90
- We avoid enhancements that aggressively modify large parts of the RHF codebase. This ensures we do not diverge too much from the original RHF package.
71
+ We avoid enhancements that aggressively modify large parts of the React Hook Form codebase. This ensures we do not diverge too much from the original package.
91
72
 
92
- - **Past RHF versions**
93
- As new enhancements are introduced, they are only applied to the current and latest RHF versions. This ensures that we are closely synced to RHF and reduces the overhead of maintaining multiple `rhf-plus` versions.
73
+ - **Past React Hook Form versions**
74
+ As new enhancements are introduced, they are only applied to the current and latest React Hook Form versions. This ensures that we are closely synced to React Hook Form and reduces the overhead of maintaining multiple `rhf-plus` versions.
94
75
 
95
76
  ### 📣 Help us grow
96
77
 
97
- Ideally, this fork would not exist, and all of these enhancements and features would be natively part of RHF. You can help RHF and RHF+ grow by:
98
-
99
- - Spreading the word about this fork so more people can test these enhancements
100
- - Using this library to test the enhancements and provide feedback.
101
- - Reporting enhancement bugs and issues [here](https://github.com/bombillazo/rhf-plus/issues).
102
- - [Contributing](CONTRIBUTING.md) new code to add new enhancements.
103
- - Sharing the enhancements in the react-hook-form [issues](https://github.com/react-hook-form/react-hook-form/issues) (create a new one if it doesn't exist).:
78
+ - Spread the word about this package so more people can test these enhancements
79
+ - Use this library to test the enhancements and provide feedback.
80
+ - Report enhancement bugs and issues [here](https://github.com/bombillazo/rhf-plus/issues).
81
+ - [Contribute](CONTRIBUTING.md) new code to add new enhancements.
82
+ - Share the enhancements in the React Hook Form [issues](https://github.com/react-hook-form/react-hook-form/issues) where applicable:
104
83
  - Upvote the issue to garner support
105
- - Kindly comment on the issue to show RHF maintainers there is a demand
106
- - Link to the enhancement page in this repo to show that a working solution is available
84
+ - Link to the enhancement page in this repo to show the available working solution
107
85
 
108
86
  ## Versioning
109
87
 
@@ -116,24 +94,24 @@ Ideally, this fork would not exist, and all of these enhancements and features w
116
94
  1 2 3
117
95
  ```
118
96
 
119
- 1. **RHF version**
120
- The react-hook-form version used as the base to add enhancements to (e.g., `7.55.0`)
97
+ 1. **React Hook Form version**
98
+ The React Hook Form version used as the base to add enhancements to (e.g., `7.55.0`)
121
99
 
122
100
  1. **Separator token**
123
- Separates RHF from RHF+ version (always `-plus.`)
101
+ Separates React Hook Form from RHF+ version (always `-plus.`)
124
102
 
125
103
  1. **RHF+ version**
126
104
  RHF+ version index (e.g., `0`)
127
105
 
128
106
  > [!Note]
129
- > Please get in touch with maintainers if a new RHF version is available and this library is behind. We will sync `rhf-plus` and release a new version.
107
+ > Please get in touch with maintainers if a new React Hook Form version is available and this library is behind. We will sync `rhf-plus` and release a new version.
130
108
 
131
109
  ### Conventions
132
110
 
133
- 1. New RHF+ versions use the latest RHF version as the base version
111
+ 1. New RHF+ versions use the latest React Hook Form version as the base version
134
112
  2. RHF+ versions start from index `0`
135
- - For example, the first version of `rhf-plus` based on RHF `7.55.0` would be `7.55.0-plus.0`
113
+ - For example, the first version of `rhf-plus` based on React Hook Form `7.55.0` would be `7.55.0-plus.0`
136
114
  3. The RHF+ version increments with each new `rhf-plus` release
137
- - For example, a new release based on RHF `7.55.0` would bump the version to `7.5.0-plus.1`
138
- 4. The RHF+ version is reset to `0` when a new version of RHF is released
139
- - For example, if RHF `7.56.0` is released, the newly synced version of `rhf-plus` based on that would be `7.56.0-plus.0`
115
+ - For example, a new release based on React Hook Form `7.55.0` would bump the version to `7.5.0-plus.1`
116
+ 4. The RHF+ version is reset to `0` when a new version of React Hook Form is released
117
+ - For example, if React Hook Form `7.56.0` is released, the newly synced version of `rhf-plus` based on that would be `7.56.0-plus.0`
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react"),t=require("crypto"),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const i=e=>"object"==typeof e;var n=e=>!a(e)&&!Array.isArray(e)&&i(e)&&!s(e),o=e=>n(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,l=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),u="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function d(e){let t;const r=Array.isArray(e),s="undefined"!=typeof FileList&&e instanceof FileList;if(e instanceof Date)t=new Date(e);else{if(u&&(e instanceof Blob||s)||!r&&!n(e))return e;if(t=r?[]:Object.create(Object.getPrototypeOf(e)),r||(e=>{const t=e.constructor&&e.constructor.prototype;return n(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=d(e[r]));else t=e}return t}var c=e=>/^\w*$/.test(e),f=e=>void 0===e,m=e=>Array.isArray(e)?e.filter(Boolean):[],y=e=>m(e.replace(/["|']|\]/g,"").split(/\.|\[/)),b=(e,t,r)=>{if(!t||!n(e))return r;const s=(c(t)?[t]:y(t)).reduce(((e,t)=>a(e)?e:e[t]),e);return f(s)||s===e?f(e[t])?r:e[t]:s},p=e=>"boolean"==typeof e;var g=(e,t,r)=>{let s=-1;const a=c(t)?[t]:y(t),i=a.length,o=i-1;for(;++s<i;){const t=a[s];let i=r;if(s!==o){const r=e[t];i=n(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}if("__proto__"===t||"constructor"===t||"prototype"===t)return;e[t]=i,e=e[t]}};const _="blur",v="focusout",h="focus",S="focusin",A="change",F="onBlur",V="onChange",x="onSubmit",w="onTouched",D="all",k="max",E="min",C="maxLength",O="minLength",M="pattern",L="required",U="validate",j=e.createContext(null);j.displayName="HookFormContext";const B=()=>e.useContext(j);var T=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(a,i,{get:()=>{const a=i;return t._proxyFormState[a]!==D&&(t._proxyFormState[a]=!s||D),r&&(r[a]=!0),e[a]}});return a};const R="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;function N(t){const r=B(),{control:s=r.control,disabled:a,name:i,exact:n}=t||{},[o,l]=e.useState(s._formState),u=e.useRef({isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,focusedField:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return R((()=>s._subscribe({name:i,formState:u.current,exact:n,callback:e=>{!a&&l({...s._formState,...e})}})),[i,a,n]),e.useEffect((()=>{u.current.isValid&&s._setValid(!0)}),[s]),e.useMemo((()=>T(o,s,u.current,!1)),[o,s])}var I=e=>"string"==typeof e,P=(e,t,r,s,a)=>I(e)?(s&&t.watch.add(e),b(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),b(r,e)))):(s&&(t.watchAll=!0),r),q=e=>a(e)||!i(e);function W(e,t,r=new WeakSet){if(q(e)||q(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const a=Object.keys(e),i=Object.keys(t);if(a.length!==i.length)return!1;if(r.has(e)||r.has(t))return!0;r.add(e),r.add(t);for(const o of a){const a=e[o];if(!i.includes(o))return!1;if("ref"!==o){const e=t[o];if(s(a)&&s(e)||n(a)&&n(e)||Array.isArray(a)&&Array.isArray(e)?!W(a,e,r):a!==e)return!1}}return!0}function $(t){const r=B(),{control:s=r.control,name:a,defaultValue:i,disabled:n,exact:o,compute:l}=t||{},u=e.useRef(i),d=e.useRef(l),c=e.useRef(void 0);d.current=l;const f=e.useMemo((()=>s._getWatch(a,u.current)),[s,a]),[m,y]=e.useState(d.current?d.current(f):f);return R((()=>s._subscribe({name:a,formState:{values:!0},exact:o,callback:e=>{if(!n){const t=P(a,s._names,e.values||s._formValues,!1,u.current);if(d.current){const e=d.current(t);W(e,c.current)||(y(e),c.current=e)}else y(t)}}})),[s,n,a,o]),e.useEffect((()=>s._removeUnmounted())),m}function H(t){const r=B(),{name:s,disabled:a,control:i=(null==r?void 0:r.control),shouldUnregister:n,defaultValue:u}=t;if(!i)throw new Error("useController: missing `control`. Pass `control` as a prop or provide it via FormProvider.");const c=l(i._names.array,s),m=e.useMemo((()=>b(i._formValues,s,b(i._defaultValues,s,u))),[i,s,u]),y=$({control:i,name:s,defaultValue:m,exact:!0}),v=N({control:i,name:s,exact:!0}),S=e.useRef(t),F=e.useRef(t.rules),V=e.useRef(i.register(s,{...t.rules,value:y,...p(t.disabled)?{disabled:t.disabled}:{}})),x=e.useMemo((()=>function(e,t){if(!t)return t;const r={...t};if(e)for(const t in e)t in r||(r[t]=void 0);return r}(F.current,t.rules)),[t.rules]);e.useEffect((()=>{V.current=i.register(s,{...x,value:y,...p(t.disabled)?{disabled:t.disabled}:{}}),F.current=t.rules}),[x,t.rules,y,t.disabled,i,s]),S.current=t;const w=e.useMemo((()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!b(v.errors,s)},isDirty:{enumerable:!0,get:()=>!!b(v.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!b(v.touchedFields,s)},isFocused:{enumerable:!0,get:()=>v.focusedField===s},isValidating:{enumerable:!0,get:()=>!!b(v.validatingFields,s)},error:{enumerable:!0,get:()=>b(v.errors,s)}})),[v,s]),D=e.useCallback((e=>V.current.onChange({target:{value:o(e),name:s},type:A})),[s]),k=e.useCallback((()=>V.current.onBlur({target:{value:b(i._formValues,s),name:s},type:_})),[s,i._formValues]),E=e.useCallback((()=>V.current.onFocus({target:{value:b(i._formValues,s),name:s},type:h})),[s,i._formValues]),C=e.useRef(null),O=e.useCallback((e=>{C.current=e;const t=b(i._fields,s);t&&e&&(t._f.ref={focus:()=>{var t;return null===(t=e.focus)||void 0===t?void 0:t.call(e)},select:()=>{var t;return null===(t=e.select)||void 0===t?void 0:t.call(e)},setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}),[i._fields,s]);O.scrollIntoView=e.useCallback((e=>{C.current&&"function"==typeof C.current.scrollIntoView&&C.current.scrollIntoView(e)}),[]);const M=e.useMemo((()=>{let e;return p(a)?e=a:p(i._options.disabled)?e=i._options.disabled:Array.isArray(i._options.disabled)&&(e=i._options.disabled.includes(s)),{name:s,value:y,...p(e)?{disabled:e}:{},onChange:D,onBlur:k,onFocus:E,ref:O}}),[s,a,i._options.disabled,D,k,E,O,y]);return e.useEffect((()=>{const e=i._options.shouldUnregister||n;i.register(s,{...S.current.rules,...p(S.current.disabled)?{disabled:S.current.disabled}:{}});const t=(e,t)=>{const r=b(i._fields,e);r&&r._f&&(r._f.mount=t)};if(t(s,!0),e){const e=d(b(i._options.defaultValues,s));g(i._defaultValues,s,e),f(b(i._formValues,s))&&g(i._formValues,s,e)}return!c&&i.register(s),()=>{(c?e&&!i._state.action:e)?i.unregister(s):t(s,!1)}}),[s,i,c,n]),e.useEffect((()=>{i._setDisabledField({disabled:a,name:s})}),[a,s,i]),e.useMemo((()=>({field:M,formState:v,fieldState:w})),[M,v,w])}const J=e=>{const t={};for(const r of Object.keys(e))if(i(e[r])&&null!==e[r]){const s=J(e[r]);for(const e of Object.keys(s))t[`${r}.${e}`]=s[e]}else t[r]=e[r];return t},z="post";var G=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},K=e=>Array.isArray(e)?e:[e],Q=e=>e||`form-${"undefined"!=typeof window&&"function"==typeof window.crypto.randomUUID?window.crypto.randomUUID():t.randomBytes(16).toString("hex")}`,X=()=>{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=[]}}};function Y(e,t){if(q(e)||q(t))return t;for(const r in t){const s=e[r],a=t[r];try{e[r]=n(s)&&n(a)||Array.isArray(s)&&Array.isArray(a)?Y(s,a):a}catch(e){}}return e}var Z=e=>n(e)&&!Object.keys(e).length,ee=e=>"file"===e.type,te=e=>"function"==typeof e,re=e=>{if(!u)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},se=e=>"select-multiple"===e.type,ae=e=>"radio"===e.type,ie=e=>re(e)&&e.isConnected,ne=e=>{var t;try{null===(t=null===document||void 0===document?void 0:document.getElementById(e))||void 0===t||t.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}))}catch(e){}};function oe(e,t){const r=Array.isArray(t)?t:c(t)?[t]:y(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=f(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,i=r[a];return s&&delete s[i],0!==a&&(n(s)&&Z(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!f(e[t]))return!1;return!0}(s))&&oe(e,r.slice(0,-1)),e}var le=e=>{for(const t in e)if(te(e[t]))return!0;return!1};function ue(e,t={}){const r=Array.isArray(e);if(n(e)||r)for(const r in e)Array.isArray(e[r])||n(e[r])&&!le(e[r])?(t[r]=Array.isArray(e[r])?[]:{},ue(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function de(e,t,r){const s=Array.isArray(e);if(n(e)||s)for(const s in e)Array.isArray(e[s])||n(e[s])&&!le(e[s])?f(t)||q(r[s])?r[s]=Array.isArray(e[s])?ue(e[s],[]):{...ue(e[s])}:de(e[s],a(t)?{}:t[s],r[s]):r[s]=!W(e[s],t[s]);return r}var ce=(e,t)=>de(e,t,ue(t));const fe={value:!1,isValid:!1},me={value:!0,isValid:!0};var ye=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!f(e[0].attributes.value)?f(e[0].value)||""===e[0].value?me:{value:e[0].value,isValid:!0}:me:fe}return fe},be=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>f(e)?e:t?""===e?NaN:e?+e:e:r&&I(e)?new Date(e):s?s(e):e;const pe={isValid:!1,value:null};var ge=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),pe):pe;function _e(e){const t=e.ref;return ee(t)?t.files:ae(t)?ge(e.refs).value:se(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?ye(e.refs).value:be(f(t.value)?e.ref.value:t.value,e)}var ve=e=>e instanceof RegExp,he=e=>f(e)?e:ve(e)?e.source:n(e)?ve(e.value)?e.value.source:e.value:e,Se=e=>({isOnSubmit:!e||e===x,isOnBlur:e===F,isOnChange:e===V,isOnAll:e===D,isOnTouch:e===w});const Ae="AsyncFunction";var Fe=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const Ve=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=b(e,a);if(r){const{_f:e,...i}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)return!0;if(e.ref&&t(e.ref,e.name)&&!s)return!0;if(Ve(i,t))break}else if(n(i)&&Ve(i,t))break}}};function xe(e,t,r){const s=b(e,r);if(s||c(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),i=b(t,s),n=b(e,s);if(i&&!Array.isArray(i)&&r!==s)return{name:r};if(n&&n.type)return{name:s,error:n};if(n&&n.root&&n.root.type)return{name:`${s}.root`,error:n.root};a.pop()}return{name:r}}var we=(e,t,r)=>{const s=K(b(e,r));return g(s,"root",t[r]),g(e,r,s),e},De=t=>!!I(t)||!!e.isValidElement(t);function ke(e,t,r="validate"){if(De(e)||Array.isArray(e)&&e.every(De)||p(e)&&!e)return{type:r,message:De(e)?e:"",ref:t}}var Ee=e=>n(e)&&!ve(e)?e:{value:e,message:""},Ce=async(e,t,s,i,o,l)=>{const{ref:u,refs:d,required:c,maxLength:m,minLength:y,min:g,max:_,pattern:v,validate:h,name:S,valueAsNumber:A,mount:F}=e._f,V=b(s,S);if(!F||t.has(S))return{};const x=d?d[0]:u,w=e=>{o&&x.reportValidity&&(p(e)?x.setCustomValidity(""):"string"==typeof e?x.setCustomValidity(e||""):x.setCustomValidity(""),x.reportValidity())},D={},j=ae(u),B=r(u),T=j||B,R=(A||ee(u))&&f(u.value)&&f(V)||re(u)&&""===u.value||""===V||Array.isArray(V)&&!V.length,N=G.bind(null,S,i,D),P=(e,t,r,s=C,a=O)=>{const i=e?t:r;D[S]={type:e?s:a,message:i,ref:u,...N(e?s:a,i)}};if(l?!Array.isArray(V)||!V.length:c&&(!T&&(R||a(V))||p(V)&&!V||B&&!ye(d).isValid||j&&!ge(d).isValid)){const{value:e,message:t}=De(c)?{value:!!c,message:c}:Ee(c);if(e&&(D[S]={type:L,message:t,ref:x,...N(L,t)},!i))return w(t),D}if(!(R||a(g)&&a(_))){let e,t;const r=Ee(_),s=Ee(g);if(a(V)||isNaN(V)){const a=u.valueAsDate||new Date(V),i=e=>new Date((new Date).toDateString()+" "+e),n="time"==u.type,o="week"==u.type;I(r.value)&&V&&(e=n?i(V)>i(r.value):o?V>r.value:a>new Date(r.value)),I(s.value)&&V&&(t=n?i(V)<i(s.value):o?V<s.value:a<new Date(s.value))}else{const i=u.valueAsNumber||(V?+V:V);a(r.value)||(e=i>r.value),a(s.value)||(t=i<s.value)}if((e||t)&&(P(!!e,r.message,s.message,k,E),!i))return w(D[S].message),D}if((m||y)&&!R&&(I(V)||l&&Array.isArray(V))){const e=Ee(m),t=Ee(y),r=!a(e.value)&&V.length>+e.value,s=!a(t.value)&&V.length<+t.value;if((r||s)&&(P(r,e.message,t.message),!i))return w(D[S].message),D}if(v&&!R&&I(V)){const{value:e,message:t}=Ee(v);if(ve(e)&&!V.match(e)&&(D[S]={type:M,message:t,ref:u,...N(M,t)},!i))return w(t),D}if(h)if(te(h)){const e=ke(await h(V,s),x);if(e&&(D[S]={...e,...N(U,e.message)},!i))return w(e.message),D}else if(n(h)){let e={};for(const t in h){if(!Z(e)&&!i)break;const r=ke(await h[t](V,s),x,t);r&&(e={...r,...N(t,r.message)},w(r.message),i&&(D[S]=e))}if(!Z(e)&&(D[S]={ref:x,...e},!i))return D}return w(!0),D};const Oe={mode:x,reValidateMode:V,shouldFocusError:!0};function Me(e={}){let t,i={...Oe,...e},c=i.isLoading||te(i.defaultValues),y={submitCount:0,isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isReady:!1,isLoading:c,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},focusedField:void 0,validatingFields:{},errors:i.errors||{},disabled:!Array.isArray(i.disabled)&&(i.disabled||!1),metadata:i.defaultMetadata||{}},A={},F=(n(i.defaultValues)||n(i.values))&&d(i.defaultValues||i.values)||{},V=i.shouldUnregister?{}:d(F),x={action:!1,mount:!1,watch:!1},w={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},k=0;const E={isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,focusedField:!1,isValidating:!1,isValid:!1,errors:!1};let C={...E};const O={array:X(),state:X()},M=i.criteriaMode===D,L=Q(e.id);let U=!1;const j=async e=>{if((Array.isArray(i.disabled)||!i.disabled)&&(E.isValid||C.isValid||e)){const e=i.resolver?Z((await q()).errors):await $(A,!0);e!==y.isValid&&O.state.next({isValid:e})}},B=(e,t)=>{!i.disabled&&(E.isValidating||E.validatingFields||C.isValidating||C.validatingFields)&&((e||Array.from(w.mount)).forEach((e=>{e&&(t?g(y.validatingFields,e,t):oe(y.validatingFields,e))})),O.state.next({validatingFields:y.validatingFields,isValidating:!Z(y.validatingFields)}))},T=(e,t,r,s)=>{const a=b(A,e);if(a){const i=b(V,e,f(r)?b(F,e):r);f(i)||s&&s.defaultChecked||t?g(V,e,t?i:_e(a._f)):z(e,i),x.mount&&j()}},R=(e,t,r,s,a,n)=>{let o=!1,l=!1;const u={name:e};if(!i.disabled){if(!r||a){(E.isDirty||C.isDirty)&&(l=y.isDirty,y.isDirty=u.isDirty=H(),o=l!==u.isDirty);const r=W(b(F,e),t);l=!!b(y.dirtyFields,e),r?oe(y.dirtyFields,e):g(y.dirtyFields,e,!0),u.dirtyFields=y.dirtyFields,o=o||(E.dirtyFields||C.dirtyFields)&&l!==!r}if(!y.isSubmitted&&!U||y.isDirtySinceSubmit||r||s||!a||(y.isDirtySinceSubmit=u.isDirtySinceSubmit=!0,o=o||!(!E.isDirtySinceSubmit&&!C.isDirtySinceSubmit)),r){const t=b(y.touchedFields,e);t||(g(y.touchedFields,e,r),u.touchedFields=y.touchedFields,o=o||(E.touchedFields||C.touchedFields)&&t!==r)}if(s||r){const t=y.focusedField===e,a=s&&!r;t!==a&&(y.focusedField=a?e:void 0,u.focusedField=y.focusedField,o=o||(E.focusedField||C.focusedField)&&t!==a)}o&&n&&O.state.next(u)}return o?u:{}},N=(e,r,s,a)=>{const n=b(y.errors,e),o=(E.isValid||C.isValid)&&p(r)&&y.isValid!==r;var l;if(i.delayError&&s?(l=()=>((e,t)=>{g(y.errors,e,t),O.state.next({errors:y.errors})})(e,s),t=e=>{clearTimeout(k),k=setTimeout(l,e)},t(i.delayError)):(clearTimeout(k),t=null,s?g(y.errors,e,s):oe(y.errors,e)),(s?!W(n,s):n)||!Z(a)||o){const t={...a,...o&&p(r)?{isValid:r}:{},errors:y.errors,name:e};y={...y,...t},O.state.next(t)}},q=async e=>{B(e,!0);const t=await i.resolver(V,i.context,((e,t,r,s)=>{const a={};for(const r of e){const e=b(t,r);e&&g(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||w.mount,A,i.criteriaMode,i.shouldUseNativeValidation));return B(e),t},$=async(e,t,r={valid:!0})=>{for(const a in e){const o=e[a];if(o){const{_f:e,...l}=o;if(e){const l=w.array.has(e.name),u=o._f&&(!!(s=o._f)&&!!s.validate&&!!(te(s.validate)&&s.validate.constructor.name===Ae||n(s.validate)&&Object.values(s.validate).find((e=>e.constructor.name===Ae))));u&&E.validatingFields&&B([a],!0);const d=await Ce(o,w.disabled,V,M,i.shouldUseNativeValidation&&!t,l);if(u&&E.validatingFields&&B([a]),d[e.name]&&(r.valid=!1,t))break;!t&&(b(d,e.name)?l?we(y.errors,d,e.name):g(y.errors,e.name,d[e.name]):oe(y.errors,e.name))}!Z(l)&&await $(l,t,r)}}var s;return r.valid},H=(e,t)=>!i.disabled&&(e&&t&&g(V,e,t),!W(me(),F)),J=(e,t,r)=>P(e,w,{...x.mount?V:f(t)?F:I(e)?{[e]:t}:t},r,t),z=(e,t,s={})=>{const i=b(A,e);let n=t;if(i){const s=i._f;s&&(!s.disabled&&g(V,e,be(t,s)),n=re(s.ref)&&a(t)?"":t,se(s.ref)?[...s.ref.options].forEach((e=>e.selected=n.includes(e.value))):s.refs?r(s.ref)?s.refs.forEach((e=>{e.defaultChecked&&e.disabled||(Array.isArray(n)?e.checked=!!n.find((t=>t===e.value)):e.checked=n===e.value||!!n)})):s.refs.forEach((e=>e.checked=e.value===n)):ee(s.ref)?s.ref.value="":(s.ref.value=n,s.ref.type||O.state.next({name:e,values:d(V)})))}const o=(y.isSubmitted||U)&&!W(b(F,e),n);(s.shouldDirty||s.shouldTouch||o)&&R(e,n,s.shouldTouch,!1,s.shouldDirty||o,!0),s.shouldValidate&&fe(e)},G=(e,t,r)=>{for(const a in t){if(!t.hasOwnProperty(a))return;const i=t[a],o=e+"."+a,l=b(A,o);(w.array.has(e)||n(i)||l&&!l._f)&&!s(i)?G(o,i,r):z(o,i,r)}},le=(e,t,r={})=>{const s=b(A,e),i=w.array.has(e),n=d(t);g(V,e,n),i?(O.array.next({name:e,values:d(V)}),(E.isDirty||E.dirtyFields||C.isDirty||C.dirtyFields||E.isDirtySinceSubmit||C.isDirtySinceSubmit)&&r.shouldDirty?O.state.next({name:e,dirtyFields:ce(F,V),isDirty:H(e,n),...!y.isSubmitted&&!U||y.isDirtySinceSubmit?{}:{isDirtySinceSubmit:!0}}):!y.isSubmitted&&!U||y.isDirtySinceSubmit||O.state.next({name:e,isDirtySinceSubmit:!0})):!s||s._f||a(n)?z(e,n,r):G(e,n,r),Fe(e,w)&&O.state.next({...y,name:e}),O.state.next({name:x.mount?e:void 0,values:d(V)}),r.shouldValidate&&fe(e)},ue=async e=>{x.mount=!0;const r=e.target;let a=r.name,n=!0;const l=b(A,a),u=e=>{n=Number.isNaN(e)||s(e)&&isNaN(e.getTime())||W(e,b(V,a,e))},c=Se(i.mode),f=Se(i.reValidateMode);if(l){if(p(l._f.disabled)?l._f.disabled:p(i.disabled)?i.disabled:!!Array.isArray(i.disabled)&&new Set(i.disabled).has(a)){const e=b(V,a);return void(r.value!==e&&(r.value=e))}let s,F;const x=r.type?_e(l._f):o(e),D=e.type===_||e.type===v,k=e.type===h||e.type===S,L=!((m=l._f).mount&&(m.required||m.min||m.max||m.maxLength||m.minLength||m.pattern||m.validate)||i.resolver||b(y.errors,a)||l._f.deps)||((e,t,r,s,a,i)=>!!i||!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e))(D,b(y.touchedFields,a),y.isSubmitted,f,c,k),U=Fe(a,w,D||k);g(V,a,x),D?r&&r.readOnly||(l._f.onBlur&&l._f.onBlur(e),t&&t(0)):l._f.onChange&&l._f.onChange(e);const T=R(a,x,D,k,!D),I=!Z(T)||U;if(!D&&O.state.next({name:a,type:e.type,values:d(V)}),L)return(E.isValid||C.isValid)&&("onBlur"===i.mode?D&&j():D||j()),I&&O.state.next({name:a,...U?{}:T});if(!D&&U&&O.state.next({...y}),i.resolver){const{errors:e}=await q([a]);if(u(x),n){const t=xe(y.errors,A,a),r=xe(e,A,t.name||a);s=r.error,a=r.name,F=Z(e)}}else B([a],!0),s=(await Ce(l,w.disabled,V,M,i.shouldUseNativeValidation))[a],B([a]),u(x),n&&(s?F=!1:(E.isValid||C.isValid)&&(F=await $(A,!0)));n&&(l._f.deps&&fe(l._f.deps),N(a,F,s,T))}var m},de=(e,t)=>{if(b(y.errors,t)&&e.focus)return e.focus(),1},fe=async(e,t={})=>{let r,s;const a=K(e);if(i.resolver){const t=await(async e=>{const{errors:t}=await q(e);if(e)for(const r of e){const e=b(t,r);e?g(y.errors,r,e):oe(y.errors,r)}else y.errors=t;return t})(f(e)?e:a);r=Z(t),s=e?!a.some((e=>b(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=b(A,e);return await $(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||y.isValid)&&j()):s=r=await $(A);return O.state.next({...!I(e)||(E.isValid||C.isValid)&&r!==y.isValid?{}:{name:e},...i.resolver||!e?{isValid:r}:{},errors:y.errors}),t.shouldFocus&&!s&&Ve(A,de,e?a:w.mount),s},me=e=>{const t={...x.mount?V:F};return f(e)?t:I(e)?b(t,e):e.map((e=>b(t,e)))},ye=(e,t)=>({invalid:!!b((t||y).errors,e),isDirty:!!b((t||y).dirtyFields,e),error:b((t||y).errors,e),isValidating:!!b(y.validatingFields,e),isTouched:!!b((t||y).touchedFields,e),isFocused:(t||y).focusedField===e}),pe=(e,t,r)=>{const s=(b(A,e,{_f:{}})._f||{}).ref,a=b(y.errors,e)||{},{ref:i,message:n,type:o,...l}=a;g(y.errors,e,{...l,...t,ref:s}),O.state.next({name:e,errors:y.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ge=e=>O.state.subscribe({next:t=>{var r,s,a;r=e.name,s=t.name,a=e.exact,r&&s&&r!==s&&!K(r).some((e=>e&&(a?e===s:e.startsWith(s)||s.startsWith(e))))||!((e,t,r,s)=>{r(e);const{name:a,...i}=e;return Z(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find((e=>t[e]===(!s||D)))})(t,e.formState||E,je,e.reRenderRoot)||e.callback({values:{...V},...y,...t,defaultValues:F})}}).unsubscribe,ve=(e,t={})=>{for(const r of e?K(e):w.mount)w.mount.delete(r),w.array.delete(r),t.keepValue||(oe(A,r),oe(V,r)),!t.keepError&&oe(y.errors,r),!t.keepDirty&&oe(y.dirtyFields,r),!t.keepTouched&&oe(y.touchedFields,r),!t.keepIsValidating&&oe(y.validatingFields,r),!i.shouldUnregister&&!t.keepDefaultValue&&oe(F,r);O.state.next({values:d(V)}),O.state.next({...y,...t.keepDirty?{isDirty:H()}:{}}),!t.keepIsValid&&j()},De=({disabled:e,name:t})=>{(p(e)&&x.mount||e||w.disabled.has(t))&&(e?w.disabled.add(t):w.disabled.delete(t))},ke=(e,t={})=>{let s=b(A,e);const a=p(t.disabled)||p(i.disabled)||Array.isArray(i.disabled);return g(A,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),w.mount.add(e),s?De({disabled:p(t.disabled)?t.disabled:Array.isArray(i.disabled)?new Set(i.disabled).has(e):i.disabled,name:e}):T(e,!0,t.value),{...a?{disabled:p(t.disabled)?t.disabled:Array.isArray(i.disabled)?new Set(i.disabled).has(e):!!i.disabled}:{},...i.progressive?{required:!!t.required,min:he(t.min),max:he(t.max),minLength:he(t.minLength),maxLength:he(t.maxLength),pattern:he(t.pattern)}:{},name:e,onChange:ue,onBlur:ue,onFocus:ue,ref:a=>{if(a){ke(e,t),s=b(A,e);const i=f(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,n=(e=>ae(e)||r(e))(i),o=s._f.refs||[];if(n?o.find((e=>e===i)):i===s._f.ref)return;g(A,e,{_f:{...s._f,...n?{refs:[...o.filter(ie),i,...Array.isArray(b(F,e))?[{}]:[]],ref:{type:i.type,name:e}}:{ref:i}}}),T(e,!1,void 0,i)}else s=b(A,e,{}),s._f&&(s._f.mount=!1),(i.shouldUnregister||t.shouldUnregister)&&(!l(w.array,e)||!x.action)&&w.unMount.add(e)}}},Ee=()=>i.shouldFocusError&&Ve(A,de,w.mount),Me=(e,t)=>async r=>{let s;r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=d(V);if(O.state.next({isSubmitting:!0}),i.resolver){const{errors:e,values:t}=await q();y.errors=e,a=d(t)}else await $(A);if(w.disabled.size)for(const e of w.disabled)oe(a,e);if(oe(y.errors,"root"),Z(y.errors)){O.state.next({errors:{}});try{await e(a,r)}catch(e){s=e}}else t&&await t({...y.errors},r),Ee(),setTimeout(Ee);if(U=!0,O.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Z(y.errors)&&!s,submitCount:y.submitCount+1,isDirtySinceSubmit:!1,hasBeenSubmitted:U,errors:y.errors}),s)throw s},Le=(e,t={})=>{const r=e?d(e):F,s=d(r),a=Z(e),n=a?F:s;if(t.keepDefaultValues||(F=r),!t.keepValues){if(t.keepDirtyValues){const e=new Set([...w.mount,...Object.keys(ce(F,V))]);for(const t of Array.from(e))b(y.dirtyFields,t)?g(n,t,b(V,t)):le(t,b(n,t))}else{if(u&&f(e))for(const e of w.mount){const t=b(A,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(re(e)){const t=e.closest("form");if(t){HTMLFormElement.prototype.reset.call(t);break}}}}if(t.keepFieldsRef)for(const e of w.mount)le(e,b(n,e));else A={}}V=i.shouldUnregister?t.keepDefaultValues?d(F):{}:d(n),O.array.next({values:{...n}}),O.state.next({values:{...n}})}w={mount:t.keepDirtyValues?w.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},x.mount=!E.isValid||!!t.keepIsValid||!!t.keepDirtyValues,x.watch=!!i.shouldUnregister,O.state.next({submitCount:t.keepSubmitCount?y.submitCount:0,isDirty:!a&&(t.keepDirty?y.isDirty:!(!t.keepDefaultValues||W(e,F))),isDirtySinceSubmit:!1,hasBeenSubmitted:U,isSubmitted:!!t.keepIsSubmitted&&y.isSubmitted,dirtyFields:a?{}:t.keepDirtyValues?t.keepDefaultValues&&V?ce(F,V):y.dirtyFields:t.keepDefaultValues&&e?ce(F,e):t.keepDirty?y.dirtyFields:{},touchedFields:t.keepTouched?y.touchedFields:{},focusedField:void 0,errors:t.keepErrors?y.errors:{},isSubmitSuccessful:!!t.keepIsSubmitSuccessful&&y.isSubmitSuccessful,isSubmitting:!1,defaultValues:F})},Ue=(e,t)=>Le(te(e)?e(V):e,t),je=e=>{y={...y,...e}},Be={control:{register:ke,unregister:ve,getFieldState:ye,handleSubmit:Me,setError:pe,_subscribe:ge,_runSchema:q,_focusError:Ee,_getWatch:J,_getDirty:H,_setValid:j,_setFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r&&!i.disabled){if(x.action=!0,n&&Array.isArray(b(A,e))){const t=r(b(A,e),s.argA,s.argB);a&&g(A,e,t)}if(n&&Array.isArray(b(y.errors,e))){const t=r(b(y.errors,e),s.argA,s.argB);a&&g(y.errors,e,t),((e,t)=>{!m(b(e,t)).length&&oe(e,t)})(y.errors,e)}if((E.touchedFields||C.touchedFields)&&n&&Array.isArray(b(y.touchedFields,e))){const t=r(b(y.touchedFields,e),s.argA,s.argB);a&&g(y.touchedFields,e,t)}(E.dirtyFields||C.dirtyFields)&&(y.dirtyFields=ce(F,V)),O.state.next({name:e,isDirty:H(e,t),dirtyFields:y.dirtyFields,errors:y.errors,isValid:y.isValid})}else g(V,e,t)},_setDisabledField:De,_setErrors:e=>{y.errors=e,O.state.next({errors:y.errors,isValid:!1})},_getFieldArray:e=>m(b(x.mount?V:F,e,i.shouldUnregister?b(F,e,[]):[])),_reset:Le,_resetDefaultValues:()=>te(i.defaultValues)&&i.defaultValues().then((e=>{Ue(e,i.resetOptions),O.state.next({isLoading:!1}),c=!1})),_removeUnmounted:()=>{for(const e of w.unMount){const t=b(A,e);t&&(t._f.refs?t._f.refs.every((e=>!ie(e))):!ie(t._f.ref))&&ve(e)}w.unMount=new Set},_disableForm:e=>{p(e)?(O.state.next({disabled:e}),Ve(A,((t,r)=>{const s=b(A,r);s&&(t.disabled=p(s._f.disabled)?s._f.disabled:e,Array.isArray(s._f.refs)&&s._f.refs.forEach((t=>{t.disabled=p(s._f.disabled)?s._f.disabled:e})))}),0,!1)):Array.isArray(e)&&Ve(A,((t,r)=>{const s=b(A,r);if(s){const a=p(s._f.disabled)?s._f.disabled:new Set(e).has(r);t.disabled=a,Array.isArray(s._f.refs)&&s._f.refs.forEach((e=>{e.disabled=a}))}}),0,!1)},_updateIsLoading:e=>{if(f(e))!!e!==y.isLoading&&(y.isLoading=c,O.state.next({isLoading:c}));else{const t=e||c;y.isLoading!==t&&(y.isLoading=t,O.state.next({isLoading:t}))}},_subjects:O,_proxyFormState:E,get _fields(){return A},get _formValues(){return V},get _state(){return x},set _state(e){x=e},get _defaultValues(){return F},get _names(){return w},set _names(e){w=e},get _formState(){return y},get _options(){return i},set _options(e){i={...i,...e}}},subscribe:e=>(x.mount=!0,C={...C,...e.formState},ge({...e,formState:C})),trigger:fe,register:ke,handleSubmit:Me,watch:(e,t)=>te(e)?O.state.subscribe({next:r=>"values"in r&&e(J(void 0,t),r)}):J(e,t,!0),setValue:le,getValues:me,reset:Ue,resetField:(e,t={})=>{b(A,e)&&(f(t.defaultValue)?le(e,d(b(F,e))):(le(e,t.defaultValue),g(F,e,d(t.defaultValue))),t.keepTouched||oe(y.touchedFields,e),t.keepDirty||(oe(y.dirtyFields,e),y.isDirty=t.defaultValue?H(e,d(b(F,e))):H()),t.keepError||(oe(y.errors,e),E.isValid&&j()),O.state.next({...y}))},clearErrors:e=>{e&&K(e).forEach((e=>oe(y.errors,e))),O.state.next({errors:e?y.errors:{}})},unregister:ve,setError:pe,setFocus:(e,t={})=>{const r=b(A,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&te(e.select)&&e.select())}},getFieldState:ye,id:L,submit:()=>{ne(L)},setMetadata:e=>{let t;t=e||(i.defaultMetadata?d(i.defaultMetadata):{}),y.metadata=t,O.state.next({metadata:t})},updateMetadata:e=>{const t=Y(y.metadata,e);y.metadata=t,O.state.next({metadata:t})}};return{...Be,formControl:Be}}var Le=()=>{if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();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)}))},Ue=(e,t,r={})=>r.shouldFocus||f(r.shouldFocus)?r.focusName||`${e}.${f(r.focusIndex)?t:r.focusIndex}.`:"",je=(e,t)=>[...e,...K(t)],Be=e=>Array.isArray(e)?e.map((()=>{})):void 0;function Te(e,t,r){return[...e.slice(0,t),...K(r),...e.slice(t)]}var Re=(e,t,r)=>Array.isArray(e)?(f(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[],Ne=(e,t)=>[...K(t),...K(e)];var Ie=(e,t)=>f(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return m(s).length?s:[]}(e,K(t).sort(((e,t)=>e-t))),Pe=(e,t,r)=>{[e[t],e[r]]=[e[r],e[t]]},qe=(e,t,r)=>(e[t]=r,e);exports.Controller=e=>{const t=H(e);return("children"in e?e.children:e.render)(t)},exports.Form=function(t){const r=B(),[s,a]=e.useState(!1),{control:i=r.control,onSubmit:n,children:o,action:l,method:u=z,headers:d,encType:c,onError:f,render:m,onSuccess:y,validateStatus:b,...p}=t,g=async e=>{let r=!1,s="";await i.handleSubmit((async t=>{const a=new FormData;let o="";try{o=JSON.stringify(t)}catch(e){}const m=J(i._formValues);for(const e in m)a.append(e,m[e]);if(n&&await n({data:t,event:e,method:u,formData:a,formDataJson:o}),l)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(String(l),{method:u,headers:{...d,...c&&"multipart/form-data"!==c?{"Content-Type":c}:{}},body:e?o:a});t&&(b?!b(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})}}))(e),r&&t.control&&(t.control._subjects.state.next({isSubmitSuccessful:!1}),t.control.setError("root.server",{type:s}))};return e.useEffect((()=>{a(!0)}),[]),m?e.createElement(e.Fragment,null,m({submit:g})):e.createElement("form",{noValidate:s,action:l,method:u,encType:c,onSubmit:g,...p},o)},exports.FormProvider=t=>{const{children:r,...s}=t;return e.createElement(j.Provider,{value:s},r)},exports.appendErrors=G,exports.createFormControl=Me,exports.get=b,exports.set=g,exports.submit=ne,exports.useController=H,exports.useFieldArray=function(t){const r=B(),{control:s=r.control,name:a,keyName:i="id",shouldUnregister:n,rules:o}=t,[l,u]=e.useState(s._getFieldArray(a)),c=e.useRef(s._getFieldArray(a).map(Le)),f=e.useRef(l),m=e.useRef(!1);f.current=l,s._names.array.add(a),e.useMemo((()=>o&&s.register(a,o)),[s,o,a]),R((()=>s._subjects.array.subscribe({next:({values:e,name:t})=>{if(t===a||!t){const t=b(e,a);Array.isArray(t)&&(u(t),c.current=t.map(Le))}}}).unsubscribe),[s,a]);const y=e.useCallback((e=>{m.current=!0,s._setFieldArray(a,e)}),[s,a]);return e.useEffect((()=>{if(s._state.action=!1,Fe(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!Se(s._options.mode).isOnSubmit||s._formState.isSubmitted)&&!Se(s._options.reValidateMode).isOnSubmit)if(s._options.resolver)s._runSchema([a]).then((e=>{const t=b(e.errors,a),r=b(s._formState.errors,a);(r?!t&&r.type||t&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?g(s._formState.errors,a,t):oe(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=b(s._fields,a);!e||!e._f||Se(s._options.reValidateMode).isOnSubmit&&Se(s._options.mode).isOnSubmit||Ce(e,s._names.disabled,s._formValues,s._options.criteriaMode===D,s._options.shouldUseNativeValidation,!0).then((e=>!Z(e)&&s._subjects.state.next({errors:we(s._formState.errors,e,a)})))}s._subjects.state.next({name:a,values:d(s._formValues)}),s._names.focus&&Ve(s._fields,((e,t)=>{if(s._names.focus&&t.startsWith(s._names.focus)&&e.focus)return e.focus(),1})),s._names.focus="",s._setValid(),m.current=!1}),[l,a,s]),e.useEffect((()=>(!b(s._formValues,a)&&s._setFieldArray(a),()=>{s._options.shouldUnregister||n?s.unregister(a):((e,t)=>{const r=b(s._fields,e);r&&r._f&&(r._f.mount=t)})(a,!1)})),[a,s,i,n]),{swap:e.useCallback(((e,t)=>{const r=s._getFieldArray(a);Pe(r,e,t),Pe(c.current,e,t),y(r),u(r),s._setFieldArray(a,r,Pe,{argA:e,argB:t},!1)}),[y,a,s]),move:e.useCallback(((e,t)=>{const r=s._getFieldArray(a);Re(r,e,t),Re(c.current,e,t),y(r),u(r),s._setFieldArray(a,r,Re,{argA:e,argB:t},!1)}),[y,a,s]),prepend:e.useCallback(((e,t)=>{const r=K(d(e)),i=Ne(s._getFieldArray(a),r);s._names.focus=Ue(a,0,t),c.current=Ne(c.current,r.map(Le)),y(i),u(i),s._setFieldArray(a,i,Ne,{argA:Be(e)})}),[y,a,s]),append:e.useCallback(((e,t)=>{const r=K(d(e)),i=je(s._getFieldArray(a),r);s._names.focus=Ue(a,i.length-1,t),c.current=je(c.current,r.map(Le)),y(i),u(i),s._setFieldArray(a,i,je,{argA:Be(e)})}),[y,a,s]),remove:e.useCallback((e=>{const t=Ie(s._getFieldArray(a),e);c.current=Ie(c.current,e),y(t),u(t),!Array.isArray(b(s._fields,a))&&g(s._fields,a,void 0),s._setFieldArray(a,t,Ie,{argA:e})}),[y,a,s]),insert:e.useCallback(((e,t,r)=>{const i=K(d(t)),n=Te(s._getFieldArray(a),e,i);s._names.focus=Ue(a,e,r),c.current=Te(c.current,e,i.map(Le)),y(n),u(n),s._setFieldArray(a,n,Te,{argA:e,argB:Be(t)})}),[y,a,s]),update:e.useCallback(((e,t)=>{const r=d(t),i=qe(s._getFieldArray(a),e,r);c.current=[...i].map(((t,r)=>t&&r!==e?c.current[r]:Le())),y(i),u([...i]),s._setFieldArray(a,i,qe,{argA:e,argB:r},!0,!1)}),[y,a,s]),replace:e.useCallback((e=>{const t=K(d(e));c.current=t.map(Le),y([...t]),u([...t]),s._setFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,s]),fields:e.useMemo((()=>l.map(((e,t)=>({...e,[i]:c.current[t]||Le()})))),[l,i])}},exports.useForm=function(t={}){var r;const s=e.useRef(void 0),a=e.useRef(void 0),[i,n]=e.useState({isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isValidating:!1,isLoading:t.isLoading||te(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},focusedField:void 0,validatingFields:{},errors:t.errors||{},disabled:!Array.isArray(t.disabled)&&(t.disabled||!1),isReady:!1,defaultValues:te(t.defaultValues)?void 0:t.defaultValues,metadata:t.defaultMetadata||(null===(r=t.formControl)||void 0===r?void 0:r.control._options.defaultMetadata)||{}});if(!s.current)if(t.formControl)s.current={...t.formControl,formState:i},t.defaultValues&&!te(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions);else{const{formControl:e,...r}=Me(t);s.current={...r,formState:i}}const o=s.current.control;return o._options=t,R((()=>{const e=o._subscribe({formState:o._proxyFormState,callback:()=>n({...o._formState}),reRenderRoot:!0});return n((e=>({...e,isReady:!0}))),o._formState.isReady=!0,e}),[o]),e.useEffect((()=>o._disableForm(t.disabled)),[o,t.disabled]),e.useEffect((()=>{o._updateIsLoading(t.isLoading)}),[o,t.isLoading]),e.useEffect((()=>{t.mode&&(o._options.mode=t.mode),t.reValidateMode&&(o._options.reValidateMode=t.reValidateMode)}),[o,t.mode,t.reValidateMode]),e.useEffect((()=>{t.errors&&(o._setErrors(t.errors),o._focusError())}),[o,t.errors]),e.useEffect((()=>{t.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})}),[o,t.shouldUnregister]),e.useEffect((()=>{if(o._proxyFormState.isDirty){const e=o._getDirty();e!==i.isDirty&&o._subjects.state.next({isDirty:e})}}),[o,i.isDirty]),e.useEffect((()=>{t.values&&!W(t.values,a.current)?(o._reset(t.values,{keepFieldsRef:!0,...o._options.resetOptions}),a.current=t.values,n((e=>({...e})))):o._resetDefaultValues()}),[o,t.values]),e.useEffect((()=>{o._state.mount||(o._setValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()})),e.useEffect((()=>{if(s.current&&void 0!==t.id&&s.current.id!==t.id){const e=Q(t.id);s.current.id=e,s.current.submit=()=>{ne(e)},n((e=>({...e})))}}),[t.id]),s.current.formState=T(i,o),s.current},exports.useFormContext=B,exports.useFormState=N,exports.useWatch=$;
1
+ "use strict";var e=require("react"),t=require("crypto"),r=e=>"checkbox"===e.type,s=e=>e instanceof Date,a=e=>null==e;const i=e=>"object"==typeof e;var n=e=>!a(e)&&!Array.isArray(e)&&i(e)&&!s(e),o=e=>n(e)&&e.target?r(e.target)?e.target.checked:e.target.value:e,l=(e,t)=>e.has((e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e)(t)),u="undefined"!=typeof window&&void 0!==window.HTMLElement&&"undefined"!=typeof document;function d(e){let t;const r=Array.isArray(e),s="undefined"!=typeof FileList&&e instanceof FileList;if(e instanceof Date)t=new Date(e);else{if(u&&(e instanceof Blob||s)||!r&&!n(e))return e;if(t=r?[]:Object.create(Object.getPrototypeOf(e)),r||(e=>{const t=e.constructor&&e.constructor.prototype;return n(t)&&t.hasOwnProperty("isPrototypeOf")})(e))for(const r in e)e.hasOwnProperty(r)&&(t[r]=d(e[r]));else t=e}return t}var c=e=>/^\w*$/.test(e),f=e=>void 0===e,m=e=>Array.isArray(e)?e.filter(Boolean):[],y=e=>m(e.replace(/["|']|\]/g,"").split(/\.|\[/)),b=(e,t,r)=>{if(!t||!n(e))return r;const s=(c(t)?[t]:y(t)).reduce(((e,t)=>a(e)?e:e[t]),e);return f(s)||s===e?f(e[t])?r:e[t]:s},p=e=>"boolean"==typeof e;var _=(e,t,r)=>{let s=-1;const a=c(t)?[t]:y(t),i=a.length,o=i-1;for(;++s<i;){const t=a[s];let i=r;if(s!==o){const r=e[t];i=n(r)||Array.isArray(r)?r:isNaN(+a[s+1])?{}:[]}if("__proto__"===t||"constructor"===t||"prototype"===t)return;e[t]=i,e=e[t]}};const g="blur",v="focusout",h="focus",S="focusin",V="change",F="onBlur",A="onChange",x="onSubmit",w="onTouched",D="all",k="max",E="min",O="maxLength",C="minLength",M="pattern",L="required",R="validate",j=e.createContext(null);j.displayName="HookFormContext";const B=()=>e.useContext(j);var U=(e,t,r,s=!0)=>{const a={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(a,i,{get:()=>{const a=i;return t._proxyFormState[a]!==D&&(t._proxyFormState[a]=!s||D),r&&(r[a]=!0),e[a]}});return a};const T="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;function N(t){const r=B(),{control:s=r.control,disabled:a,name:i,exact:n}=t||{},[o,l]=e.useState(s._formState),u=e.useRef({isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,focusedField:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return T((()=>s._subscribe({name:i,formState:u.current,exact:n,callback:e=>{!a&&l({...s._formState,...e})}})),[i,a,n]),e.useEffect((()=>{u.current.isValid&&s._setValid(!0)}),[s]),e.useMemo((()=>U(o,s,u.current,!1)),[o,s])}var I=e=>"string"==typeof e,P=(e,t,r,s,a)=>I(e)?(s&&t.watch.add(e),b(r,e,a)):Array.isArray(e)?e.map((e=>(s&&t.watch.add(e),b(r,e)))):(s&&(t.watchAll=!0),r),q=e=>a(e)||!i(e);function W(e,t,r=new WeakSet){if(q(e)||q(t))return e===t;if(s(e)&&s(t))return e.getTime()===t.getTime();const a=Object.keys(e),i=Object.keys(t);if(a.length!==i.length)return!1;if(r.has(e)||r.has(t))return!0;r.add(e),r.add(t);for(const o of a){const a=e[o];if(!i.includes(o))return!1;if("ref"!==o){const e=t[o];if(s(a)&&s(e)||n(a)&&n(e)||Array.isArray(a)&&Array.isArray(e)?!W(a,e,r):a!==e)return!1}}return!0}function $(t){const r=B(),{control:s=r.control,name:a,defaultValue:i,disabled:n,exact:o,compute:l}=t||{},u=e.useRef(i),d=e.useRef(l),c=e.useRef(void 0);d.current=l;const f=e.useMemo((()=>s._getWatch(a,u.current)),[s,a]),[m,y]=e.useState(d.current?d.current(f):f);return T((()=>s._subscribe({name:a,formState:{values:!0},exact:o,callback:e=>{if(!n){const t=P(a,s._names,e.values||s._formValues,!1,u.current);if(d.current){const e=d.current(t);W(e,c.current)||(y(e),c.current=e)}else y(t)}}})),[s,n,a,o]),e.useEffect((()=>s._removeUnmounted())),m}function H(t){const r=B(),{name:s,disabled:a,control:i=(null==r?void 0:r.control),shouldUnregister:n,defaultValue:u}=t;if(!i)throw new Error("useController: missing `control`. Pass `control` as a prop or provide it via FormProvider.");const c=l(i._names.array,s),m=e.useMemo((()=>b(i._formValues,s,b(i._defaultValues,s,u))),[i,s,u]),y=$({control:i,name:s,defaultValue:m,exact:!0}),v=N({control:i,name:s,exact:!0}),S=e.useRef(t),F=e.useRef(t.rules),A=e.useRef(void 0),x=e.useRef(i.register(s,{...t.rules,value:y,...p(t.disabled)?{disabled:t.disabled}:{}})),w=e.useMemo((()=>function(e,t){if(!t)return t;const r={...t};if(e)for(const t in e)t in r||(r[t]=void 0);return r}(F.current,t.rules)),[t.rules]);e.useEffect((()=>{x.current=i.register(s,{...w,value:y,...p(t.disabled)?{disabled:t.disabled}:{}}),F.current=t.rules}),[w,t.rules,y,t.disabled,i,s]),S.current=t;const D=e.useMemo((()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!b(v.errors,s)},isDirty:{enumerable:!0,get:()=>!!b(v.dirtyFields,s)},isTouched:{enumerable:!0,get:()=>!!b(v.touchedFields,s)},isFocused:{enumerable:!0,get:()=>v.focusedField===s},isValidating:{enumerable:!0,get:()=>!!b(v.validatingFields,s)},error:{enumerable:!0,get:()=>b(v.errors,s)}})),[v,s]),k=e.useCallback((e=>x.current.onChange({target:{value:o(e),name:s},type:V})),[s]),E=e.useCallback((()=>x.current.onBlur({target:{value:b(i._formValues,s),name:s},type:g})),[s,i._formValues]),O=e.useCallback((()=>x.current.onFocus({target:{value:b(i._formValues,s),name:s},type:h})),[s,i._formValues]),C=e.useRef(null),M=e.useCallback((e=>{C.current=e;const t=b(i._fields,s);t&&e&&(t._f.ref={focus:()=>{var t;return null===(t=e.focus)||void 0===t?void 0:t.call(e)},select:()=>{var t;return null===(t=e.select)||void 0===t?void 0:t.call(e)},setCustomValidity:t=>e.setCustomValidity(t),reportValidity:()=>e.reportValidity()})}),[i._fields,s]);M.scrollIntoView=e.useCallback((e=>{C.current&&"function"==typeof C.current.scrollIntoView&&C.current.scrollIntoView(e)}),[]);const L=e.useMemo((()=>{let e;return p(a)?e=a:p(i._options.disabled)?e=i._options.disabled:Array.isArray(i._options.disabled)&&(e=i._options.disabled.includes(s)),{name:s,value:y,...p(e)?{disabled:e}:{},onChange:k,onBlur:E,onFocus:O,ref:M}}),[s,a,i._options.disabled,k,E,O,M,y]);return e.useEffect((()=>{const e=i._options.shouldUnregister||n,t=A.current;t&&t!==s&&!c&&i.unregister(t),i.register(s,{...S.current.rules,...p(S.current.disabled)?{disabled:S.current.disabled}:{}});const r=(e,t)=>{const r=b(i._fields,e);r&&r._f&&(r._f.mount=t)};if(r(s,!0),e){const e=d(b(i._options.defaultValues,s));_(i._defaultValues,s,e),f(b(i._formValues,s))&&_(i._formValues,s,e)}return!c&&i.register(s),A.current=s,()=>{(c?e&&!i._state.action:e)?i.unregister(s):r(s,!1)}}),[s,i,c,n]),e.useEffect((()=>{i._setDisabledField({disabled:a,name:s})}),[a,s,i]),e.useMemo((()=>({field:L,formState:v,fieldState:D})),[L,v,D])}const J=e=>{const t={};for(const r of Object.keys(e))if(i(e[r])&&null!==e[r]){const s=J(e[r]);for(const e of Object.keys(s))t[`${r}.${e}`]=s[e]}else t[r]=e[r];return t},z="post";var G=(e,t,r,s,a)=>t?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[s]:a||!0}}:{},K=e=>Array.isArray(e)?e:[e],Q=e=>e||`form-${"undefined"!=typeof window&&"function"==typeof window.crypto.randomUUID?window.crypto.randomUUID():t.randomBytes(16).toString("hex")}`,X=()=>{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=[]}}};function Y(e,t){if(q(e)||q(t))return t;for(const r in t){const s=e[r],a=t[r];try{e[r]=n(s)&&n(a)||Array.isArray(s)&&Array.isArray(a)?Y(s,a):a}catch(e){}}return e}function Z(e,t){const r={};for(const s in e)if(e.hasOwnProperty(s)){const a=e[s],i=t[s];if(a&&n(a)&&i){const e=Z(a,i);n(e)&&(r[s]=e)}else e[s]&&(r[s]=i)}return r}var ee=e=>n(e)&&!Object.keys(e).length,te=e=>"file"===e.type,re=e=>"function"==typeof e,se=e=>{if(!u)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},ae=e=>"select-multiple"===e.type,ie=e=>"radio"===e.type,ne=e=>se(e)&&e.isConnected,oe=e=>{var t;try{null===(t=null===document||void 0===document?void 0:document.getElementById(e))||void 0===t||t.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0}))}catch(e){}};function le(e,t){const r=Array.isArray(t)?t:c(t)?[t]:y(t),s=1===r.length?e:function(e,t){const r=t.slice(0,-1).length;let s=0;for(;s<r;)e=f(e)?s++:e[t[s++]];return e}(e,r),a=r.length-1,i=r[a];return s&&delete s[i],0!==a&&(n(s)&&ee(s)||Array.isArray(s)&&function(e){for(const t in e)if(e.hasOwnProperty(t)&&!f(e[t]))return!1;return!0}(s))&&le(e,r.slice(0,-1)),e}function ue(e){return Array.isArray(e)||n(e)&&!(e=>{for(const t in e)if(re(e[t]))return!0;return!1})(e)}function de(e,t={}){for(const r in e)ue(e[r])?(t[r]=Array.isArray(e[r])?[]:{},de(e[r],t[r])):a(e[r])||(t[r]=!0);return t}function ce(e,t,r){r||(r=de(t));for(const s in e)ue(e[s])?f(t)||q(r[s])?r[s]=de(e[s],Array.isArray(e[s])?[]:{}):ce(e[s],a(t)?{}:t[s],r[s]):r[s]=!W(e[s],t[s]);return r}const fe={value:!1,isValid:!1},me={value:!0,isValid:!0};var ye=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter((e=>e&&e.checked&&!e.disabled)).map((e=>e.value));return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!f(e[0].attributes.value)?f(e[0].value)||""===e[0].value?me:{value:e[0].value,isValid:!0}:me:fe}return fe},be=(e,{valueAsNumber:t,valueAsDate:r,setValueAs:s})=>f(e)?e:t?""===e?NaN:e?+e:e:r&&I(e)?new Date(e):s?s(e):e;const pe={isValid:!1,value:null};var _e=e=>Array.isArray(e)?e.reduce(((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e),pe):pe;function ge(e){const t=e.ref;return te(t)?t.files:ie(t)?_e(e.refs).value:ae(t)?[...t.selectedOptions].map((({value:e})=>e)):r(t)?ye(e.refs).value:be(f(t.value)?e.ref.value:t.value,e)}var ve=e=>e instanceof RegExp,he=e=>f(e)?e:ve(e)?e.source:n(e)?ve(e.value)?e.value.source:e.value:e,Se=e=>({isOnSubmit:!e||e===x,isOnBlur:e===F,isOnChange:e===A,isOnAll:e===D,isOnTouch:e===w});const Ve="AsyncFunction";var Fe=(e,t,r)=>!r&&(t.watchAll||t.watch.has(e)||[...t.watch].some((t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))));const Ae=(e,t,r,s)=>{for(const a of r||Object.keys(e)){const r=b(e,a);if(r){const{_f:e,...i}=r;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],a)&&!s)return!0;if(e.ref&&t(e.ref,e.name)&&!s)return!0;if(Ae(i,t))break}else if(n(i)&&Ae(i,t))break}}};function xe(e,t,r){const s=b(e,r);if(s||c(r))return{error:s,name:r};const a=r.split(".");for(;a.length;){const s=a.join("."),i=b(t,s),n=b(e,s);if(i&&!Array.isArray(i)&&r!==s)return{name:r};if(n&&n.type)return{name:s,error:n};if(n&&n.root&&n.root.type)return{name:`${s}.root`,error:n.root};a.pop()}return{name:r}}var we=(e,t,r)=>{const s=K(b(e,r));return _(s,"root",t[r]),_(e,r,s),e},De=t=>!!I(t)||!!e.isValidElement(t);function ke(e,t,r="validate"){if(De(e)||Array.isArray(e)&&e.every(De)||p(e)&&!e)return{type:r,message:De(e)?e:"",ref:t}}var Ee=e=>n(e)&&!ve(e)?e:{value:e,message:""},Oe=async(e,t,s,i,o,l)=>{const{ref:u,refs:d,required:c,maxLength:m,minLength:y,min:_,max:g,pattern:v,validate:h,name:S,valueAsNumber:V,mount:F}=e._f,A=b(s,S);if(!F||t.has(S))return{};const x=d?d[0]:u,w=e=>{o&&x.reportValidity&&(p(e)?x.setCustomValidity(""):"string"==typeof e?x.setCustomValidity(e||""):x.setCustomValidity(""),x.reportValidity())},D={},j=ie(u),B=r(u),U=j||B,T=(V||te(u))&&f(u.value)&&f(A)||se(u)&&""===u.value||""===A||Array.isArray(A)&&!A.length,N=G.bind(null,S,i,D),P=(e,t,r,s=O,a=C)=>{const i=e?t:r;D[S]={type:e?s:a,message:i,ref:u,...N(e?s:a,i)}};if(l?!Array.isArray(A)||!A.length:c&&(!U&&(T||a(A))||p(A)&&!A||B&&!ye(d).isValid||j&&!_e(d).isValid)){const{value:e,message:t}=De(c)?{value:!!c,message:c}:Ee(c);if(e&&(D[S]={type:L,message:t,ref:x,...N(L,t)},!i))return w(t),D}if(!(T||a(_)&&a(g))){let e,t;const r=Ee(g),s=Ee(_);if(a(A)||isNaN(A)){const a=u.valueAsDate||new Date(A),i=e=>new Date((new Date).toDateString()+" "+e),n="time"==u.type,o="week"==u.type;I(r.value)&&A&&(e=n?i(A)>i(r.value):o?A>r.value:a>new Date(r.value)),I(s.value)&&A&&(t=n?i(A)<i(s.value):o?A<s.value:a<new Date(s.value))}else{const i=u.valueAsNumber||(A?+A:A);a(r.value)||(e=i>r.value),a(s.value)||(t=i<s.value)}if((e||t)&&(P(!!e,r.message,s.message,k,E),!i))return w(D[S].message),D}if((m||y)&&!T&&(I(A)||l&&Array.isArray(A))){const e=Ee(m),t=Ee(y),r=!a(e.value)&&A.length>+e.value,s=!a(t.value)&&A.length<+t.value;if((r||s)&&(P(r,e.message,t.message),!i))return w(D[S].message),D}if(v&&!T&&I(A)){const{value:e,message:t}=Ee(v);if(ve(e)&&!A.match(e)&&(D[S]={type:M,message:t,ref:u,...N(M,t)},!i))return w(t),D}if(h)if(re(h)){const e=ke(await h(A,s),x);if(e&&(D[S]={...e,...N(R,e.message)},!i))return w(e.message),D}else if(n(h)){let e={};for(const t in h){if(!ee(e)&&!i)break;const r=ke(await h[t](A,s),x,t);r&&(e={...r,...N(t,r.message)},w(r.message),i&&(D[S]=e))}if(!ee(e)&&(D[S]={ref:x,...e},!i))return D}return w(!0),D};const Ce={mode:x,reValidateMode:A,shouldFocusError:!0,shouldSkipReadOnlyValidation:!1};function Me(e={}){let t,i={...Ce,...e},c=i.isLoading||re(i.defaultValues),y={submitCount:0,isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isReady:!1,isLoading:c,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},focusedField:void 0,validatingFields:{},errors:i.errors||{},disabled:!Array.isArray(i.disabled)&&(i.disabled||!1),metadata:i.defaultMetadata||{}},V={},F=(n(i.defaultValues)||n(i.values))&&d(i.defaultValues||i.values)||{},A=i.shouldUnregister?{}:d(F),x={action:!1,mount:!1,watch:!1},w={mount:new Set,disabled:new Set,readonly:new Set,unMount:new Set,array:new Set,watch:new Set},k=0;const E={isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,focusedField:!1,isValidating:!1,isValid:!1,errors:!1};let O={...E};const C={array:X(),state:X()},M=i.criteriaMode===D,L=Q(e.id);let R=!1;const j=async e=>{if((Array.isArray(i.disabled)||!i.disabled)&&(E.isValid||O.isValid||e)){const e=i.resolver?ee((await q()).errors):await $(V,!0);e!==y.isValid&&C.state.next({isValid:e})}},B=(e,t)=>{!i.disabled&&(E.isValidating||E.validatingFields||O.isValidating||O.validatingFields)&&((e||Array.from(w.mount)).forEach((e=>{e&&(t?_(y.validatingFields,e,t):le(y.validatingFields,e))})),C.state.next({validatingFields:y.validatingFields,isValidating:!ee(y.validatingFields)}))},U=(e,t,r,s)=>{const a=b(V,e);if(a){const i=b(A,e,f(r)?b(F,e):r);f(i)||s&&s.defaultChecked||t?_(A,e,t?i:ge(a._f)):z(e,i),x.mount&&j()}},T=(e,t,r,s,a,n)=>{let o=!1,l=!1;const u={name:e};if(!i.disabled){if(!r||a){(E.isDirty||O.isDirty)&&(l=y.isDirty,y.isDirty=u.isDirty=H(),o=l!==u.isDirty);const r=W(b(F,e),t);l=!!b(y.dirtyFields,e),r?le(y.dirtyFields,e):_(y.dirtyFields,e,!0),u.dirtyFields=y.dirtyFields,o=o||(E.dirtyFields||O.dirtyFields)&&l!==!r}if(!y.isSubmitted&&!R||y.isDirtySinceSubmit||r||s||!a||(y.isDirtySinceSubmit=u.isDirtySinceSubmit=!0,o=o||!(!E.isDirtySinceSubmit&&!O.isDirtySinceSubmit)),r){const t=b(y.touchedFields,e);t||(_(y.touchedFields,e,r),u.touchedFields=y.touchedFields,o=o||(E.touchedFields||O.touchedFields)&&t!==r)}if(s||r){const t=y.focusedField===e,a=s&&!r;t!==a&&(y.focusedField=a?e:void 0,u.focusedField=y.focusedField,o=o||(E.focusedField||O.focusedField)&&t!==a)}o&&n&&C.state.next(u)}return o?u:{}},N=(e,r,s,a)=>{const n=b(y.errors,e),o=(E.isValid||O.isValid)&&p(r)&&y.isValid!==r;var l;if(i.delayError&&s?(l=()=>((e,t)=>{_(y.errors,e,t),C.state.next({errors:y.errors})})(e,s),t=e=>{clearTimeout(k),k=setTimeout(l,e)},t(i.delayError)):(clearTimeout(k),t=null,s?_(y.errors,e,s):le(y.errors,e)),(s?!W(n,s):n)||!ee(a)||o){const t={...a,...o&&p(r)?{isValid:r}:{},errors:y.errors,name:e};y={...y,...t},C.state.next(t)}},q=async e=>{B(e,!0);const t=await i.resolver(A,i.context,((e,t,r,s)=>{const a={};for(const r of e){const e=b(t,r);e&&_(a,r,e._f)}return{criteriaMode:r,names:[...e],fields:a,shouldUseNativeValidation:s}})(e||w.mount,V,i.criteriaMode,i.shouldUseNativeValidation));return B(e),t},$=async(e,t,r={valid:!0})=>{for(const a in e){const o=e[a];if(o){const{_f:e,...a}=o;if(e){const a=w.array.has(e.name),l=o._f&&(!!(s=o._f)&&!!s.validate&&!!(re(s.validate)&&s.validate.constructor.name===Ve||n(s.validate)&&Object.values(s.validate).find((e=>e.constructor.name===Ve))));l&&E.validatingFields&&B([e.name],!0);const u=new Set([...w.disabled,...w.readonly]),d=await Oe(o,u,A,M,i.shouldUseNativeValidation&&!t,a);if(l&&E.validatingFields&&B([e.name]),d[e.name]&&(r.valid=!1,t))break;!t&&(b(d,e.name)?a?we(y.errors,d,e.name):_(y.errors,e.name,d[e.name]):le(y.errors,e.name))}!ee(a)&&await $(a,t,r)}}var s;return r.valid},H=(e,t)=>!i.disabled&&(e&&t&&_(A,e,t),!W(ye(),F)),J=(e,t,r)=>P(e,w,{...x.mount?A:f(t)?F:I(e)?{[e]:t}:t},r,t),z=(e,t,s={})=>{const i=b(V,e);let n=t;if(i){const s=i._f;s&&(!s.disabled&&_(A,e,be(t,s)),n=se(s.ref)&&a(t)?"":t,ae(s.ref)?[...s.ref.options].forEach((e=>e.selected=n.includes(e.value))):s.refs?r(s.ref)?s.refs.forEach((e=>{e.defaultChecked&&e.disabled||(Array.isArray(n)?e.checked=!!n.find((t=>t===e.value)):e.checked=n===e.value||!!n)})):s.refs.forEach((e=>e.checked=e.value===n)):te(s.ref)?s.ref.value="":(s.ref.value=n,s.ref.type||C.state.next({name:e,values:d(A)})))}const o=(y.isSubmitted||R)&&!W(b(F,e),n);(s.shouldDirty||s.shouldTouch||o)&&T(e,n,s.shouldTouch,!1,s.shouldDirty||o,!0),s.shouldValidate&&me(e)},G=(e,t,r)=>{for(const a in t){if(!t.hasOwnProperty(a))return;const i=t[a],o=e+"."+a,l=b(V,o);(w.array.has(e)||n(i)||l&&!l._f)&&!s(i)?G(o,i,r):z(o,i,r)}},ue=(e,t,r={})=>{const s=b(V,e),i=w.array.has(e),n=d(t);_(A,e,n),i?(C.array.next({name:e,values:d(A)}),(E.isDirty||E.dirtyFields||O.isDirty||O.dirtyFields||E.isDirtySinceSubmit||O.isDirtySinceSubmit)&&r.shouldDirty?C.state.next({name:e,dirtyFields:ce(F,A),isDirty:H(e,n),...!y.isSubmitted&&!R||y.isDirtySinceSubmit?{}:{isDirtySinceSubmit:!0}}):!y.isSubmitted&&!R||y.isDirtySinceSubmit||C.state.next({name:e,isDirtySinceSubmit:!0})):!s||s._f||a(n)?z(e,n,r):G(e,n,r),Fe(e,w)&&C.state.next({...y,name:e}),C.state.next({name:x.mount?e:void 0,values:d(A)}),r.shouldValidate&&me(e)},de=async e=>{x.mount=!0;const r=e.target;let a=r.name,n=!0;const l=b(V,a),u=e=>{n=Number.isNaN(e)||s(e)&&isNaN(e.getTime())||W(e,b(A,a,e))},c=Se(i.mode),f=Se(i.reValidateMode);if(l){if(p(l._f.disabled)?l._f.disabled:p(i.disabled)?i.disabled:!!Array.isArray(i.disabled)&&new Set(i.disabled).has(a)){const e=b(A,a);return void(r.value!==e&&(r.value=e))}if(i.shouldSkipReadOnlyValidation&&r&&r.readOnly){w.readonly.add(a);const t=r.type?ge(l._f):o(e),s=e.type===g||e.type===v,i=e.type===h||e.type===S,n=Fe(a,w,s||i);_(A,a,t);const u=T(a,t,s,i,!s),c=!ee(u)||n;return!s&&C.state.next({name:a,type:e.type,values:d(A)}),c&&C.state.next({name:a,...n?{}:u})}let s,F;i.shouldSkipReadOnlyValidation&&w.readonly.delete(a);const x=r.type?ge(l._f):o(e),D=e.type===g||e.type===v,k=e.type===h||e.type===S,L=!((m=l._f).mount&&(m.required||m.min||m.max||m.maxLength||m.minLength||m.pattern||m.validate)||i.resolver||b(y.errors,a)||l._f.deps)||((e,t,r,s,a,i)=>!!i||!a.isOnAll&&(!r&&a.isOnTouch?!(t||e):(r?s.isOnBlur:a.isOnBlur)?!e:!(r?s.isOnChange:a.isOnChange)||e))(D,b(y.touchedFields,a),y.isSubmitted,f,c,k),R=Fe(a,w,D||k);_(A,a,x),D?r&&r.readOnly||(l._f.onBlur&&l._f.onBlur(e),t&&t(0)):l._f.onChange&&l._f.onChange(e);const U=T(a,x,D,k,!D),I=!ee(U)||R;if(!D&&C.state.next({name:a,type:e.type,values:d(A)}),L)return(E.isValid||O.isValid)&&("onBlur"===i.mode?D&&j():D||j()),I&&C.state.next({name:a,...R?{}:U});if(!D&&R&&C.state.next({...y}),i.resolver){const{errors:e}=await q([a]);if(u(x),n){const t=xe(y.errors,V,a),r=xe(e,V,t.name||a);s=r.error,a=r.name,F=ee(e)}}else{B([a],!0);const e=new Set([...w.disabled,...w.readonly]);s=(await Oe(l,e,A,M,i.shouldUseNativeValidation,!1))[a],B([a]),u(x),n&&(s?F=!1:(E.isValid||O.isValid)&&(F=await $(V,!0)))}n&&(l._f.deps&&(!Array.isArray(l._f.deps)||l._f.deps.length>0)&&me(l._f.deps),N(a,F,s,U))}var m},fe=(e,t)=>{if(b(y.errors,t)&&e.focus)return e.focus(),1},me=async(e,t={})=>{let r,s;const a=K(e);if(i.resolver){const t=await(async e=>{const{errors:t}=await q(e);if(e)for(const r of e){const e=b(t,r);e?_(y.errors,r,e):le(y.errors,r)}else y.errors=t;return t})(f(e)?e:a);r=ee(t),s=e?!a.some((e=>b(t,e))):r}else e?(s=(await Promise.all(a.map((async e=>{const t=b(V,e);return await $(t&&t._f?{[e]:t}:t)})))).every(Boolean),(s||y.isValid)&&j()):s=r=await $(V);return C.state.next({...!I(e)||(E.isValid||O.isValid)&&r!==y.isValid?{}:{name:e},...i.resolver||!e?{isValid:r}:{},errors:y.errors}),t.shouldFocus&&!s&&Ae(V,fe,e?a:w.mount),s},ye=(e,t)=>{let r={...x.mount?A:F};return t&&(r=Z(t.dirtyFields?y.dirtyFields:y.touchedFields,r)),f(e)?r:I(e)?b(r,e):e.map((e=>b(r,e)))},pe=(e,t)=>({invalid:!!b((t||y).errors,e),isDirty:!!b((t||y).dirtyFields,e),error:b((t||y).errors,e),isValidating:!!b(y.validatingFields,e),isTouched:!!b((t||y).touchedFields,e),isFocused:(t||y).focusedField===e}),_e=(e,t,r)=>{const s=(b(V,e,{_f:{}})._f||{}).ref,a=b(y.errors,e)||{},{ref:i,message:n,type:o,...l}=a;_(y.errors,e,{...l,...t,ref:s}),C.state.next({name:e,errors:y.errors,isValid:!1}),r&&r.shouldFocus&&s&&s.focus&&s.focus()},ve=e=>C.state.subscribe({next:t=>{var r,s,a;r=e.name,s=t.name,a=e.exact,r&&s&&r!==s&&!K(r).some((e=>e&&(a?e===s:e.startsWith(s)||s.startsWith(e))))||!((e,t,r,s)=>{r(e);const{name:a,...i}=e;return ee(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find((e=>t[e]===(!s||D)))})(t,e.formState||E,Be,e.reRenderRoot)||e.callback({values:{...A},...y,...t,defaultValues:F})}}).unsubscribe,De=(e,t={})=>{for(const r of e?K(e):w.mount)w.mount.delete(r),w.array.delete(r),t.keepValue||(le(V,r),le(A,r)),!t.keepError&&le(y.errors,r),!t.keepDirty&&le(y.dirtyFields,r),!t.keepTouched&&le(y.touchedFields,r),!t.keepIsValidating&&le(y.validatingFields,r),!i.shouldUnregister&&!t.keepDefaultValue&&le(F,r);C.state.next({values:d(A)}),C.state.next({...y,...t.keepDirty?{isDirty:H()}:{}}),!t.keepIsValid&&j()},ke=({disabled:e,name:t})=>{(p(e)&&x.mount||e||w.disabled.has(t))&&(e?w.disabled.add(t):w.disabled.delete(t))},Ee=(e,t={})=>{let s=b(V,e);const a=p(t.disabled)||p(i.disabled)||Array.isArray(i.disabled);return _(V,e,{...s||{},_f:{...s&&s._f?s._f:{ref:{name:e}},name:e,mount:!0,...t}}),w.mount.add(e),s?ke({disabled:p(t.disabled)?t.disabled:Array.isArray(i.disabled)?new Set(i.disabled).has(e):i.disabled,name:e}):U(e,!0,t.value),{...a?{disabled:p(t.disabled)?t.disabled:Array.isArray(i.disabled)?new Set(i.disabled).has(e):!!i.disabled}:{},...i.progressive?{required:!!t.required,min:he(t.min),max:he(t.max),minLength:he(t.minLength),maxLength:he(t.maxLength),pattern:he(t.pattern)}:{},name:e,onChange:de,onBlur:de,onFocus:de,ref:a=>{if(a){Ee(e,t),s=b(V,e);const n=f(a.value)&&a.querySelectorAll&&a.querySelectorAll("input,select,textarea")[0]||a,o=(e=>ie(e)||r(e))(n),l=s._f.refs||[];if(o?l.find((e=>e===n)):n===s._f.ref)return;_(V,e,{_f:{...s._f,...o?{refs:[...l.filter(ne),n,...Array.isArray(b(F,e))?[{}]:[]],ref:{type:n.type,name:e}}:{ref:n}}}),U(e,!1,void 0,n),i.shouldSkipReadOnlyValidation&&n&&"readOnly"in n&&n.readOnly&&w.readonly.add(e)}else s=b(V,e,{}),s._f&&(s._f.mount=!1),(i.shouldUnregister||t.shouldUnregister)&&(!l(w.array,e)||!x.action)&&w.unMount.add(e)}}},Me=()=>i.shouldFocusError&&Ae(V,fe,w.mount),Le=(e,t)=>async r=>{let s;r&&(r.preventDefault&&r.preventDefault(),r.persist&&r.persist());let a=d(A);if(C.state.next({isSubmitting:!0}),i.resolver){const{errors:e,values:t}=await q();y.errors=e,a=d(t)}else await $(V);if(w.disabled.size)for(const e of w.disabled)le(a,e);if(le(y.errors,"root"),ee(y.errors)){C.state.next({errors:{}});try{await e(a,r)}catch(e){s=e}}else t&&await t({...y.errors},r),Me(),setTimeout(Me);if(R=!0,C.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:ee(y.errors)&&!s,submitCount:y.submitCount+1,isDirtySinceSubmit:!1,hasBeenSubmitted:R,errors:y.errors}),s)throw s},Re=(e,t={})=>{const r=e?d(e):F,s=d(r),a=ee(e),n=a?F:s;if(t.keepDefaultValues||(F=r),!t.keepValues){if(t.keepDirtyValues){const e=new Set([...w.mount,...Object.keys(ce(F,A))]);for(const t of Array.from(e))b(y.dirtyFields,t)?_(n,t,b(A,t)):ue(t,b(n,t))}else{if(u&&f(e))for(const e of w.mount){const t=b(V,e);if(t&&t._f){const e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(se(e)){const t=e.closest("form");if(t){HTMLFormElement.prototype.reset.call(t);break}}}}if(t.keepFieldsRef)for(const e of w.mount)ue(e,b(n,e));else V={}}A=i.shouldUnregister?t.keepDefaultValues?d(F):{}:d(n),C.array.next({values:{...n}}),C.state.next({values:{...n}})}w={mount:t.keepDirtyValues?w.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,readonly:new Set,watch:new Set,watchAll:!1,focus:""},x.mount=!E.isValid||!!t.keepIsValid||!!t.keepDirtyValues,x.watch=!!i.shouldUnregister,C.state.next({submitCount:t.keepSubmitCount?y.submitCount:0,isDirty:!a&&(t.keepDirty?y.isDirty:!(!t.keepDefaultValues||W(e,F))),isDirtySinceSubmit:!1,hasBeenSubmitted:R,isSubmitted:!!t.keepIsSubmitted&&y.isSubmitted,dirtyFields:a?{}:t.keepDirtyValues?t.keepDefaultValues&&A?ce(F,A):y.dirtyFields:t.keepDefaultValues&&e?ce(F,e):t.keepDirty?y.dirtyFields:{},touchedFields:t.keepTouched?y.touchedFields:{},focusedField:void 0,errors:t.keepErrors?y.errors:{},isSubmitSuccessful:!!t.keepIsSubmitSuccessful&&y.isSubmitSuccessful,isSubmitting:!1,defaultValues:F})},je=(e,t)=>Re(re(e)?e(A):e,t),Be=e=>{y={...y,...e}},Ue={control:{register:Ee,unregister:De,getFieldState:pe,handleSubmit:Le,setError:_e,_subscribe:ve,_runSchema:q,_focusError:Me,_getWatch:J,_getDirty:H,_setValid:j,_setFieldArray:(e,t=[],r,s,a=!0,n=!0)=>{if(s&&r&&!i.disabled){if(x.action=!0,n&&Array.isArray(b(V,e))){const t=r(b(V,e),s.argA,s.argB);a&&_(V,e,t)}if(n&&Array.isArray(b(y.errors,e))){const t=r(b(y.errors,e),s.argA,s.argB);a&&_(y.errors,e,t),((e,t)=>{!m(b(e,t)).length&&le(e,t)})(y.errors,e)}if((E.touchedFields||O.touchedFields)&&n&&Array.isArray(b(y.touchedFields,e))){const t=r(b(y.touchedFields,e),s.argA,s.argB);a&&_(y.touchedFields,e,t)}(E.dirtyFields||O.dirtyFields)&&(y.dirtyFields=ce(F,A)),C.state.next({name:e,isDirty:H(e,t),dirtyFields:y.dirtyFields,errors:y.errors,isValid:y.isValid})}else _(A,e,t)},_setDisabledField:ke,_setErrors:e=>{y.errors=e,C.state.next({errors:y.errors,isValid:!1})},_getFieldArray:e=>m(b(x.mount?A:F,e,i.shouldUnregister?b(F,e,[]):[])),_reset:Re,_resetDefaultValues:()=>re(i.defaultValues)&&i.defaultValues().then((e=>{je(e,i.resetOptions),C.state.next({isLoading:!1}),c=!1})),_removeUnmounted:()=>{for(const e of w.unMount){const t=b(V,e);t&&(t._f.refs?t._f.refs.every((e=>!ne(e))):!ne(t._f.ref))&&De(e)}w.unMount=new Set},_disableForm:e=>{p(e)?(C.state.next({disabled:e}),Ae(V,((t,r)=>{const s=b(V,r);s&&(t.disabled=p(s._f.disabled)?s._f.disabled:e,Array.isArray(s._f.refs)&&s._f.refs.forEach((t=>{t.disabled=p(s._f.disabled)?s._f.disabled:e})))}),0,!1)):Array.isArray(e)&&Ae(V,((t,r)=>{const s=b(V,r);if(s){const a=p(s._f.disabled)?s._f.disabled:new Set(e).has(r);t.disabled=a,Array.isArray(s._f.refs)&&s._f.refs.forEach((e=>{e.disabled=a}))}}),0,!1)},_updateIsLoading:e=>{if(f(e))!!e!==y.isLoading&&(y.isLoading=c,C.state.next({isLoading:c}));else{const t=e||c;y.isLoading!==t&&(y.isLoading=t,C.state.next({isLoading:t}))}},_updateReadonlyFieldTracking:()=>{Object.keys(V).forEach((e=>{const t=b(V,e);if(t&&t._f){const r=t._f.refs?t._f.refs[0]:t._f.ref;if(r&&"readOnly"in r){const t=Boolean(r.readOnly);i.shouldSkipReadOnlyValidation&&t?w.readonly.add(e):w.readonly.delete(e)}}}))},_subjects:C,_proxyFormState:E,get _fields(){return V},get _formValues(){return A},get _state(){return x},set _state(e){x=e},get _defaultValues(){return F},get _names(){return w},set _names(e){w=e},get _formState(){return y},get _options(){return i},set _options(e){i={...i,...e}}},subscribe:e=>(x.mount=!0,O={...O,...e.formState},ve({...e,formState:O})),trigger:me,register:Ee,handleSubmit:Le,watch:(e,t)=>re(e)?C.state.subscribe({next:r=>"values"in r&&e(J(void 0,t),r)}):J(e,t,!0),setValue:ue,getValues:ye,reset:je,resetField:(e,t={})=>{b(V,e)&&(f(t.defaultValue)?ue(e,d(b(F,e))):(ue(e,t.defaultValue),_(F,e,d(t.defaultValue))),t.keepTouched||le(y.touchedFields,e),t.keepDirty||(le(y.dirtyFields,e),y.isDirty=t.defaultValue?H(e,d(b(F,e))):H()),t.keepError||(le(y.errors,e),E.isValid&&j()),C.state.next({...y}))},clearErrors:e=>{e&&K(e).forEach((e=>le(y.errors,e))),C.state.next({errors:e?y.errors:{}})},unregister:De,setError:_e,setFocus:(e,t={})=>{const r=b(V,e),s=r&&r._f;if(s){const e=s.refs?s.refs[0]:s.ref;e.focus&&(e.focus(),t.shouldSelect&&re(e.select)&&e.select())}},getFieldState:pe,id:L,submit:()=>{oe(L)},setMetadata:e=>{let t;t=e||(i.defaultMetadata?d(i.defaultMetadata):{}),y.metadata=t,C.state.next({metadata:t})},updateMetadata:e=>{const t=Y(y.metadata,e);y.metadata=t,C.state.next({metadata:t})}};return{...Ue,formControl:Ue}}var Le=()=>{if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();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)}))},Re=(e,t,r={})=>r.shouldFocus||f(r.shouldFocus)?r.focusName||`${e}.${f(r.focusIndex)?t:r.focusIndex}.`:"",je=(e,t)=>[...e,...K(t)],Be=e=>Array.isArray(e)?e.map((()=>{})):void 0;function Ue(e,t,r){return[...e.slice(0,t),...K(r),...e.slice(t)]}var Te=(e,t,r)=>Array.isArray(e)?(f(e[r])&&(e[r]=void 0),e.splice(r,0,e.splice(t,1)[0]),e):[],Ne=(e,t)=>[...K(t),...K(e)];var Ie=(e,t)=>f(t)?[]:function(e,t){let r=0;const s=[...e];for(const e of t)s.splice(e-r,1),r++;return m(s).length?s:[]}(e,K(t).sort(((e,t)=>e-t))),Pe=(e,t,r)=>{[e[t],e[r]]=[e[r],e[t]]},qe=(e,t,r)=>(e[t]=r,e);exports.Controller=e=>{const t=H(e);return("children"in e?e.children:e.render)(t)},exports.Form=function(t){const r=B(),[s,a]=e.useState(!1),{control:i=r.control,onSubmit:n,children:o,action:l,method:u=z,headers:d,encType:c,onError:f,render:m,onSuccess:y,validateStatus:b,...p}=t,_=async e=>{let r=!1,s="";await i.handleSubmit((async t=>{const a=new FormData;let o="";try{o=JSON.stringify(t)}catch(e){}const m=J(i._formValues);for(const e in m)a.append(e,m[e]);if(n&&await n({data:t,event:e,method:u,formData:a,formDataJson:o}),l)try{const e=[d&&d["Content-Type"],c].some((e=>e&&e.includes("json"))),t=await fetch(String(l),{method:u,headers:{...d,...c&&"multipart/form-data"!==c?{"Content-Type":c}:{}},body:e?o:a});t&&(b?!b(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})}}))(e),r&&t.control&&(t.control._subjects.state.next({isSubmitSuccessful:!1}),t.control.setError("root.server",{type:s}))};return e.useEffect((()=>{a(!0)}),[]),m?e.createElement(e.Fragment,null,m({submit:_})):e.createElement("form",{noValidate:s,action:l,method:u,encType:c,onSubmit:_,...p},o)},exports.FormProvider=t=>{const{children:r,...s}=t;return e.createElement(j.Provider,{value:s},r)},exports.appendErrors=G,exports.createFormControl=Me,exports.get=b,exports.set=_,exports.submit=oe,exports.useController=H,exports.useFieldArray=function(t){const r=B(),{control:s=r.control,name:a,keyName:i="id",shouldUnregister:n,rules:o}=t,[l,u]=e.useState(s._getFieldArray(a)),c=e.useRef(s._getFieldArray(a).map(Le)),f=e.useRef(l),m=e.useRef(!1);f.current=l,s._names.array.add(a),e.useMemo((()=>o&&s.register(a,o)),[s,o,a]),T((()=>s._subjects.array.subscribe({next:({values:e,name:t})=>{if(t===a||!t){const t=b(e,a);Array.isArray(t)&&(u(t),c.current=t.map(Le))}}}).unsubscribe),[s,a]);const y=e.useCallback((e=>{m.current=!0,s._setFieldArray(a,e)}),[s,a]);return e.useEffect((()=>{if(s._state.action=!1,Fe(a,s._names)&&s._subjects.state.next({...s._formState}),m.current&&(!Se(s._options.mode).isOnSubmit||s._formState.isSubmitted)&&!Se(s._options.reValidateMode).isOnSubmit)if(s._options.resolver)s._runSchema([a]).then((e=>{const t=b(e.errors,a),r=b(s._formState.errors,a);(r?!t&&r.type||t&&(r.type!==t.type||r.message!==t.message):t&&t.type)&&(t?_(s._formState.errors,a,t):le(s._formState.errors,a),s._subjects.state.next({errors:s._formState.errors}))}));else{const e=b(s._fields,a);!e||!e._f||Se(s._options.reValidateMode).isOnSubmit&&Se(s._options.mode).isOnSubmit||Oe(e,s._names.disabled,s._formValues,s._options.criteriaMode===D,s._options.shouldUseNativeValidation,!0).then((e=>!ee(e)&&s._subjects.state.next({errors:we(s._formState.errors,e,a)})))}s._subjects.state.next({name:a,values:d(s._formValues)}),s._names.focus&&Ae(s._fields,((e,t)=>{if(s._names.focus&&t.startsWith(s._names.focus)&&e.focus)return e.focus(),1})),s._names.focus="",s._setValid(),m.current=!1}),[l,a,s]),e.useEffect((()=>(!b(s._formValues,a)&&s._setFieldArray(a),()=>{s._options.shouldUnregister||n?s.unregister(a):((e,t)=>{const r=b(s._fields,e);r&&r._f&&(r._f.mount=t)})(a,!1)})),[a,s,i,n]),{swap:e.useCallback(((e,t)=>{const r=s._getFieldArray(a);Pe(r,e,t),Pe(c.current,e,t),y(r),u(r),s._setFieldArray(a,r,Pe,{argA:e,argB:t},!1)}),[y,a,s]),move:e.useCallback(((e,t)=>{const r=s._getFieldArray(a);Te(r,e,t),Te(c.current,e,t),y(r),u(r),s._setFieldArray(a,r,Te,{argA:e,argB:t},!1)}),[y,a,s]),prepend:e.useCallback(((e,t)=>{const r=K(d(e)),i=Ne(s._getFieldArray(a),r);s._names.focus=Re(a,0,t),c.current=Ne(c.current,r.map(Le)),y(i),u(i),s._setFieldArray(a,i,Ne,{argA:Be(e)})}),[y,a,s]),append:e.useCallback(((e,t)=>{const r=K(d(e)),i=je(s._getFieldArray(a),r);s._names.focus=Re(a,i.length-1,t),c.current=je(c.current,r.map(Le)),y(i),u(i),s._setFieldArray(a,i,je,{argA:Be(e)})}),[y,a,s]),remove:e.useCallback((e=>{const t=Ie(s._getFieldArray(a),e);c.current=Ie(c.current,e),y(t),u(t),!Array.isArray(b(s._fields,a))&&_(s._fields,a,void 0),s._setFieldArray(a,t,Ie,{argA:e})}),[y,a,s]),insert:e.useCallback(((e,t,r)=>{const i=K(d(t)),n=Ue(s._getFieldArray(a),e,i);s._names.focus=Re(a,e,r),c.current=Ue(c.current,e,i.map(Le)),y(n),u(n),s._setFieldArray(a,n,Ue,{argA:e,argB:Be(t)})}),[y,a,s]),update:e.useCallback(((e,t)=>{const r=d(t),i=qe(s._getFieldArray(a),e,r);c.current=[...i].map(((t,r)=>t&&r!==e?c.current[r]:Le())),y(i),u([...i]),s._setFieldArray(a,i,qe,{argA:e,argB:r},!0,!1)}),[y,a,s]),replace:e.useCallback((e=>{const t=K(d(e));c.current=t.map(Le),y([...t]),u([...t]),s._setFieldArray(a,[...t],(e=>e),{},!0,!1)}),[y,a,s]),fields:e.useMemo((()=>l.map(((e,t)=>({...e,[i]:c.current[t]||Le()})))),[l,i])}},exports.useForm=function(t={}){var r;const s=e.useRef(void 0),a=e.useRef(void 0),[i,n]=e.useState({isDirty:!1,isDirtySinceSubmit:!1,hasBeenSubmitted:!1,isValidating:!1,isLoading:t.isLoading||re(t.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},focusedField:void 0,validatingFields:{},errors:t.errors||{},disabled:!Array.isArray(t.disabled)&&(t.disabled||!1),isReady:!1,defaultValues:re(t.defaultValues)?void 0:t.defaultValues,metadata:t.defaultMetadata||(null===(r=t.formControl)||void 0===r?void 0:r.control._options.defaultMetadata)||{}});if(!s.current)if(t.formControl)s.current={...t.formControl,formState:i},t.defaultValues&&!re(t.defaultValues)&&t.formControl.reset(t.defaultValues,t.resetOptions);else{const{formControl:e,...r}=Me(t);s.current={...r,formState:i}}const o=s.current.control;return o._options=t,T((()=>{const e=o._subscribe({formState:o._proxyFormState,callback:()=>n({...o._formState}),reRenderRoot:!0});return n((e=>({...e,isReady:!0}))),o._formState.isReady=!0,e}),[o]),e.useEffect((()=>o._disableForm(t.disabled)),[o,t.disabled]),e.useEffect((()=>{o._updateReadonlyFieldTracking()}),[o,t.shouldSkipReadOnlyValidation]),e.useEffect((()=>{o._updateIsLoading(t.isLoading)}),[o,t.isLoading]),e.useEffect((()=>{t.mode&&(o._options.mode=t.mode),t.reValidateMode&&(o._options.reValidateMode=t.reValidateMode)}),[o,t.mode,t.reValidateMode]),e.useEffect((()=>{t.errors&&(o._setErrors(t.errors),o._focusError())}),[o,t.errors]),e.useEffect((()=>{t.shouldUnregister&&o._subjects.state.next({values:o._getWatch()})}),[o,t.shouldUnregister]),e.useEffect((()=>{if(o._proxyFormState.isDirty){const e=o._getDirty();e!==i.isDirty&&o._subjects.state.next({isDirty:e})}}),[o,i.isDirty]),e.useEffect((()=>{t.values&&!W(t.values,a.current)?(o._reset(t.values,{keepFieldsRef:!0,...o._options.resetOptions}),a.current=t.values,n((e=>({...e})))):o._resetDefaultValues()}),[o,t.values]),e.useEffect((()=>{o._state.mount||(o._setValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()})),e.useEffect((()=>{if(s.current&&void 0!==t.id&&s.current.id!==t.id){const e=Q(t.id);s.current.id=e,s.current.submit=()=>{oe(e)},n((e=>({...e})))}}),[t.id]),s.current.formState=U(i,o),s.current},exports.useFormContext=B,exports.useFormState=N,exports.useWatch=$;
2
2
  //# sourceMappingURL=index.cjs.js.map