suprform 1.0.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 +21 -0
- package/README.md +244 -0
- package/dist/components/form/SuprForm.d.ts +10 -0
- package/dist/components/form/SuprForm.d.ts.map +1 -0
- package/dist/components/form/index.d.ts +2 -0
- package/dist/components/form/index.d.ts.map +1 -0
- package/dist/components/form/type.d.ts +21 -0
- package/dist/components/form/type.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/suprform.cjs.js +2 -0
- package/dist/suprform.cjs.js.map +1 -0
- package/dist/suprform.es.js +1233 -0
- package/dist/suprform.es.js.map +1 -0
- package/dist/test/setup.d.ts +2 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sahana
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# suprform
|
|
2
|
+
|
|
3
|
+
A headless React form library for managing complex state, validation, and error handling with a clean, scalable architecture.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐จ **Headless Architecture** - Complete control over your UI and styling
|
|
8
|
+
- ๐ **TypeScript First** - Full type safety and IntelliSense support
|
|
9
|
+
- โ
**Flexible Validation** - Built-in validators and custom validation rules
|
|
10
|
+
- ๐ฏ **Field-Level Control** - Manage individual fields with ease
|
|
11
|
+
- ๐ **Form State Management** - Track dirty, touched, valid states automatically
|
|
12
|
+
- โก **Async Validation** - Support for asynchronous validation
|
|
13
|
+
- ๐ฆ **Zero Dependencies** - Only requires React as peer dependency
|
|
14
|
+
- ๐งช **Well Tested** - Comprehensive test suite included
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install suprform
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { useForm, required, email } from 'suprform';
|
|
26
|
+
|
|
27
|
+
function LoginForm() {
|
|
28
|
+
const form = useForm({
|
|
29
|
+
initialValues: {
|
|
30
|
+
email: '',
|
|
31
|
+
password: '',
|
|
32
|
+
},
|
|
33
|
+
onSubmit: async (values) => {
|
|
34
|
+
console.log('Form submitted:', values);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Register fields with validators
|
|
39
|
+
form.registerField('email', {
|
|
40
|
+
validators: [{ rule: required('Email is required') }, { rule: email('Invalid email format') }],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
form.registerField('password', {
|
|
44
|
+
validators: [{ rule: required('Password is required') }],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const emailState = form.getFieldState('email');
|
|
48
|
+
const emailHandlers = form.getFieldHandlers('email');
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<form
|
|
52
|
+
onSubmit={(e) => {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
form.submitForm();
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<div>
|
|
58
|
+
<input
|
|
59
|
+
type='email'
|
|
60
|
+
value={emailState.value || ''}
|
|
61
|
+
onChange={(e) => emailHandlers.onChange(e.target.value)}
|
|
62
|
+
onBlur={emailHandlers.onBlur}
|
|
63
|
+
/>
|
|
64
|
+
{emailState.touched && emailState.error && <span>{emailState.error}</span>}
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<button type='submit' disabled={!form.isValid || form.submitting}>
|
|
68
|
+
{form.submitting ? 'Submitting...' : 'Login'}
|
|
69
|
+
</button>
|
|
70
|
+
</form>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Publishing
|
|
76
|
+
|
|
77
|
+
To publish a new version to the npm registry:
|
|
78
|
+
|
|
79
|
+
1. Ensure you are logged in to npm:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm login
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
2. Build the package (also runs automatically via `prepublishOnly`):
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run build
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
3. Bump the version in `package.json` and publish:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm version patch # or minor/major
|
|
95
|
+
npm publish --access public
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The published package contains only the compiled `dist/` files with ESM/CJS builds and TypeScript declarations.
|
|
99
|
+
|
|
100
|
+
## Using useField Hook
|
|
101
|
+
|
|
102
|
+
For simpler field management, use the `useField` hook:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import { useForm, useField, required } from 'suprform';
|
|
106
|
+
|
|
107
|
+
function TextField({ name, label, form }) {
|
|
108
|
+
const { field, meta } = useField({ name, form });
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div>
|
|
112
|
+
<label>{label}</label>
|
|
113
|
+
<input
|
|
114
|
+
value={field.value || ''}
|
|
115
|
+
onChange={(e) => field.onChange(e.target.value)}
|
|
116
|
+
onBlur={field.onBlur}
|
|
117
|
+
/>
|
|
118
|
+
{meta.touched && meta.error && <span>{meta.error}</span>}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function MyForm() {
|
|
124
|
+
const form = useForm({
|
|
125
|
+
initialValues: { name: '', email: '' },
|
|
126
|
+
onSubmit: (values) => console.log(values),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
form.registerField('name', {
|
|
130
|
+
validators: [{ rule: required() }],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<form
|
|
135
|
+
onSubmit={(e) => {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
form.submitForm();
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<TextField name='name' label='Name' form={form} />
|
|
141
|
+
<button type='submit'>Submit</button>
|
|
142
|
+
</form>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Built-in Validators
|
|
148
|
+
|
|
149
|
+
- `required(message?)` - Validates that a field is not empty
|
|
150
|
+
- `minLength(min, message?)` - Validates minimum string length
|
|
151
|
+
- `maxLength(max, message?)` - Validates maximum string length
|
|
152
|
+
- `email(message?)` - Validates email format
|
|
153
|
+
- `pattern(regex, message?)` - Validates against a regex pattern
|
|
154
|
+
- `min(value, message?)` - Validates minimum numeric value
|
|
155
|
+
- `max(value, message?)` - Validates maximum numeric value
|
|
156
|
+
- `matches(fieldName, message?)` - Validates that a field matches another field
|
|
157
|
+
- `combine(...validators)` - Combines multiple validators
|
|
158
|
+
|
|
159
|
+
## Custom Validators
|
|
160
|
+
|
|
161
|
+
Create custom validators easily:
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import { ValidationRule } from 'suprform';
|
|
165
|
+
|
|
166
|
+
const isStrongPassword: ValidationRule = (value: string) => {
|
|
167
|
+
if (!value) return undefined;
|
|
168
|
+
|
|
169
|
+
const hasUpperCase = /[A-Z]/.test(value);
|
|
170
|
+
const hasLowerCase = /[a-z]/.test(value);
|
|
171
|
+
const hasNumbers = /\d/.test(value);
|
|
172
|
+
const hasSpecialChar = /[!@#$%^&*]/.test(value);
|
|
173
|
+
|
|
174
|
+
if (!hasUpperCase || !hasLowerCase || !hasNumbers || !hasSpecialChar) {
|
|
175
|
+
return 'Password must contain uppercase, lowercase, numbers, and special characters';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return undefined;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// Use in your form
|
|
182
|
+
form.registerField('password', {
|
|
183
|
+
validators: [{ rule: isStrongPassword }],
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## API Reference
|
|
188
|
+
|
|
189
|
+
### useForm(config)
|
|
190
|
+
|
|
191
|
+
Creates a form instance with state management and validation.
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
|
|
195
|
+
- `config.initialValues` - Initial form values
|
|
196
|
+
- `config.onSubmit` - Submit handler function
|
|
197
|
+
- `config.validateOnChange` - Validate fields on change (default: true)
|
|
198
|
+
- `config.validateOnBlur` - Validate fields on blur (default: true)
|
|
199
|
+
|
|
200
|
+
**Returns:**
|
|
201
|
+
|
|
202
|
+
- `values` - Current form values
|
|
203
|
+
- `errors` - Field errors
|
|
204
|
+
- `touched` - Touched field states
|
|
205
|
+
- `dirty` - Whether form has been modified
|
|
206
|
+
- `submitting` - Whether form is being submitted
|
|
207
|
+
- `submitCount` - Number of submission attempts
|
|
208
|
+
- `isValid` - Whether form is valid
|
|
209
|
+
- `setFieldValue(name, value)` - Set a field value
|
|
210
|
+
- `setFieldError(name, error)` - Set a field error
|
|
211
|
+
- `setFieldTouched(name, touched)` - Set field touched state
|
|
212
|
+
- `resetForm()` - Reset form to initial state
|
|
213
|
+
- `validateField(name)` - Validate a single field
|
|
214
|
+
- `validateForm()` - Validate all fields
|
|
215
|
+
- `submitForm()` - Submit the form
|
|
216
|
+
- `getFieldState(name)` - Get field state
|
|
217
|
+
- `getFieldHandlers(name)` - Get field handlers
|
|
218
|
+
- `registerField(name, config)` - Register a field
|
|
219
|
+
- `unregisterField(name)` - Unregister a field
|
|
220
|
+
|
|
221
|
+
### useField(props)
|
|
222
|
+
|
|
223
|
+
Hook for managing individual fields.
|
|
224
|
+
|
|
225
|
+
**Parameters:**
|
|
226
|
+
|
|
227
|
+
- `name` - Field name
|
|
228
|
+
- `form` - Form instance from useForm
|
|
229
|
+
- `defaultValue` - Default field value
|
|
230
|
+
- `validators` - Array of validators
|
|
231
|
+
|
|
232
|
+
**Returns:**
|
|
233
|
+
|
|
234
|
+
- `field` - Field props (value, onChange, onBlur, onFocus)
|
|
235
|
+
- `meta` - Field metadata (error, touched, dirty, validating)
|
|
236
|
+
- `helpers` - Field helper functions
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
MIT
|
|
241
|
+
|
|
242
|
+
## Contributing
|
|
243
|
+
|
|
244
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { FieldValues, FieldPath } from 'react-hook-form';
|
|
3
|
+
import { SuprFormProps, FormControlProps } from './type';
|
|
4
|
+
type SuprFormBase = <TFieldValues extends FieldValues = FieldValues>(props: SuprFormProps<TFieldValues>) => ReactElement;
|
|
5
|
+
type SuprFormComponent = SuprFormBase & {
|
|
6
|
+
Control: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: FormControlProps<TFieldValues, TName>) => ReactElement;
|
|
7
|
+
};
|
|
8
|
+
declare const SuprForm: SuprFormComponent;
|
|
9
|
+
export default SuprForm;
|
|
10
|
+
//# sourceMappingURL=SuprForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuprForm.d.ts","sourceRoot":"","sources":["../../../src/components/form/SuprForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAKL,WAAW,EACX,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAwB,MAAM,QAAQ,CAAC;AAE/E,KAAK,YAAY,GAAG,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,EACjE,KAAK,EAAE,aAAa,CAAC,YAAY,CAAC,KAC/B,YAAY,CAAC;AAElB,KAAK,iBAAiB,GAAG,YAAY,GAAG;IACtC,OAAO,EAAE,CACP,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,EAE/D,KAAK,EAAE,gBAAgB,CAAC,YAAY,EAAE,KAAK,CAAC,KACzC,YAAY,CAAC;CACnB,CAAC;AAEF,QAAA,MAAM,QAAQ,EAAE,iBA0Bf,CAAC;AAiEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/form/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
import { ControllerFieldState, ControllerRenderProps, FieldValues, FieldPath, RegisterOptions, SubmitHandler, UseFormProps } from 'react-hook-form';
|
|
3
|
+
export interface SuprFormProps<TFieldValues extends FieldValues = FieldValues> {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onSubmit?: SubmitHandler<TFieldValues>;
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
className?: string;
|
|
8
|
+
formOptions?: UseFormProps<TFieldValues>;
|
|
9
|
+
}
|
|
10
|
+
export interface FormControlProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
|
11
|
+
children: ReactElement<any>;
|
|
12
|
+
rules?: RegisterOptions<TFieldValues, TName>;
|
|
13
|
+
name: TName;
|
|
14
|
+
label?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ControlledFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
|
17
|
+
field: ControllerRenderProps<TFieldValues, TName>;
|
|
18
|
+
fieldState: ControllerFieldState;
|
|
19
|
+
children: ReactElement<any>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/components/form/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,eAAe,EACf,aAAa,EACb,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW;IAC3E,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACvC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,gBAAgB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC;IAE/D,QAAQ,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC7C,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB,CACnC,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC;IAE/D,KAAK,EAAE,qBAAqB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAClD,UAAU,EAAE,oBAAoB,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;CAC7B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("react/jsx-runtime"),_=require("react");var he=e=>e.type==="checkbox",ae=e=>e instanceof Date,j=e=>e==null;const nt=e=>typeof e=="object";var M=e=>!j(e)&&!Array.isArray(e)&&nt(e)&&!ae(e),ut=e=>M(e)&&e.target?he(e.target)?e.target.checked:e.target.value:e,St=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,lt=(e,s)=>e.has(St(s)),Et=e=>{const s=e.constructor&&e.constructor.prototype;return M(s)&&s.hasOwnProperty("isPrototypeOf")},Te=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function U(e){let s;const t=Array.isArray(e),i=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)s=new Date(e);else if(!(Te&&(e instanceof Blob||i))&&(t||M(e)))if(s=t?[]:Object.create(Object.getPrototypeOf(e)),!t&&!Et(e))s=e;else for(const u in e)e.hasOwnProperty(u)&&(s[u]=U(e[u]));else return e;return s}var Fe=e=>/^\w*$/.test(e),O=e=>e===void 0,Le=e=>Array.isArray(e)?e.filter(Boolean):[],Me=e=>Le(e.replace(/["|']|\]/g,"").split(/\.|\[/)),y=(e,s,t)=>{if(!s||!M(e))return t;const i=(Fe(s)?[s]:Me(s)).reduce((u,n)=>j(u)?u:u[n],e);return O(i)||i===e?O(e[s])?t:e[s]:i},z=e=>typeof e=="boolean",C=(e,s,t)=>{let i=-1;const u=Fe(s)?[s]:Me(s),n=u.length,d=n-1;for(;++i<n;){const c=u[i];let w=t;if(i!==d){const S=e[c];w=M(S)||Array.isArray(S)?S:isNaN(+u[i+1])?{}:[]}if(c==="__proto__"||c==="constructor"||c==="prototype")return;e[c]=w,e=e[c]}};const be={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},J={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},re={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Ue=_.createContext(null);Ue.displayName="HookFormContext";const xe=()=>_.useContext(Ue),Ct=e=>{const{children:s,...t}=e;return _.createElement(Ue.Provider,{value:t},s)};var ot=(e,s,t,i=!0)=>{const u={defaultValues:s._defaultValues};for(const n in e)Object.defineProperty(u,n,{get:()=>{const d=n;return s._proxyFormState[d]!==J.all&&(s._proxyFormState[d]=!i||J.all),t&&(t[d]=!0),e[d]}});return u};const pe=typeof window<"u"?_.useLayoutEffect:_.useEffect;function Rt(e){const s=xe(),{control:t=s.control,disabled:i,name:u,exact:n}=e||{},[d,c]=_.useState(t._formState),w=_.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return pe(()=>t._subscribe({name:u,formState:w.current,exact:n,callback:S=>{!i&&c({...t._formState,...S})}}),[u,i,n]),_.useEffect(()=>{w.current.isValid&&t._setValid(!0)},[t]),_.useMemo(()=>ot(d,t,w.current,!1),[d,t])}var G=e=>typeof e=="string",Ce=(e,s,t,i,u)=>G(e)?(i&&s.watch.add(e),y(t,e,u)):Array.isArray(e)?e.map(n=>(i&&s.watch.add(n),y(t,n))):(i&&(s.watchAll=!0),t),Re=e=>j(e)||!nt(e);function Q(e,s,t=new WeakSet){if(Re(e)||Re(s))return Object.is(e,s);if(ae(e)&&ae(s))return e.getTime()===s.getTime();const i=Object.keys(e),u=Object.keys(s);if(i.length!==u.length)return!1;if(t.has(e)||t.has(s))return!0;t.add(e),t.add(s);for(const n of i){const d=e[n];if(!u.includes(n))return!1;if(n!=="ref"){const c=s[n];if(ae(d)&&ae(c)||M(d)&&M(c)||Array.isArray(d)&&Array.isArray(c)?!Q(d,c,t):!Object.is(d,c))return!1}}return!0}function Ot(e){const s=xe(),{control:t=s.control,name:i,defaultValue:u,disabled:n,exact:d,compute:c}=e||{},w=_.useRef(u),S=_.useRef(c),V=_.useRef(void 0),b=_.useRef(t),v=_.useRef(i);S.current=c;const[p,W]=_.useState(()=>{const F=t._getWatch(i,w.current);return S.current?S.current(F):F}),R=_.useCallback(F=>{const x=Ce(i,t._names,F||t._formValues,!1,w.current);return S.current?S.current(x):x},[t._formValues,t._names,i]),B=_.useCallback(F=>{if(!n){const x=Ce(i,t._names,F||t._formValues,!1,w.current);if(S.current){const $=S.current(x);Q($,V.current)||(W($),V.current=$)}else W(x)}},[t._formValues,t._names,n,i]);pe(()=>((b.current!==t||!Q(v.current,i))&&(b.current=t,v.current=i,B()),t._subscribe({name:i,formState:{values:!0},exact:d,callback:F=>{B(F.values)}})),[t,d,i,B]),_.useEffect(()=>t._removeUnmounted());const Z=b.current!==t,m=v.current,N=_.useMemo(()=>{if(n)return null;const F=!Z&&!Q(m,i);return Z||F?R():null},[n,Z,i,m,R]);return N!==null?N:p}function Tt(e){const s=xe(),{name:t,disabled:i,control:u=s.control,shouldUnregister:n,defaultValue:d,exact:c=!0}=e,w=lt(u._names.array,t),S=_.useMemo(()=>y(u._formValues,t,y(u._defaultValues,t,d)),[u,t,d]),V=Ot({control:u,name:t,defaultValue:S,exact:c}),b=Rt({control:u,name:t,exact:c}),v=_.useRef(e),p=_.useRef(void 0),W=_.useRef(u.register(t,{...e.rules,value:V,...z(e.disabled)?{disabled:e.disabled}:{}}));v.current=e;const R=_.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!y(b.errors,t)},isDirty:{enumerable:!0,get:()=>!!y(b.dirtyFields,t)},isTouched:{enumerable:!0,get:()=>!!y(b.touchedFields,t)},isValidating:{enumerable:!0,get:()=>!!y(b.validatingFields,t)},error:{enumerable:!0,get:()=>y(b.errors,t)}}),[b,t]),B=_.useCallback(F=>W.current.onChange({target:{value:ut(F),name:t},type:be.CHANGE}),[t]),Z=_.useCallback(()=>W.current.onBlur({target:{value:y(u._formValues,t),name:t},type:be.BLUR}),[t,u._formValues]),m=_.useCallback(F=>{const x=y(u._fields,t);x&&F&&(x._f.ref={focus:()=>F.focus&&F.focus(),select:()=>F.select&&F.select(),setCustomValidity:$=>F.setCustomValidity($),reportValidity:()=>F.reportValidity()})},[u._fields,t]),N=_.useMemo(()=>({name:t,value:V,...z(i)||b.disabled?{disabled:b.disabled||i}:{},onChange:B,onBlur:Z,ref:m}),[t,i,b.disabled,B,Z,m,V]);return _.useEffect(()=>{const F=u._options.shouldUnregister||n,x=p.current;x&&x!==t&&!w&&u.unregister(x),u.register(t,{...v.current.rules,...z(v.current.disabled)?{disabled:v.current.disabled}:{}});const $=(K,oe)=>{const P=y(u._fields,K);P&&P._f&&(P._f.mount=oe)};if($(t,!0),F){const K=U(y(u._options.defaultValues,t,v.current.defaultValue));C(u._defaultValues,t,K),O(y(u._formValues,t))&&C(u._formValues,t,K)}return!w&&u.register(t),p.current=t,()=>{(w?F&&!u._state.action:F)?u.unregister(t):$(t,!1)}},[t,u,w,n]),_.useEffect(()=>{u._setDisabledField({disabled:i,name:t})},[i,t,u]),_.useMemo(()=>({field:N,formState:b,fieldState:R}),[N,b,R])}const Lt=e=>e.render(Tt(e));var Mt=(e,s,t,i,u)=>s?{...t[e],types:{...t[e]&&t[e].types?t[e].types:{},[i]:u||!0}}:{},fe=e=>Array.isArray(e)?e:[e],Ye=()=>{let e=[];return{get observers(){return e},next:u=>{for(const n of e)n.next&&n.next(u)},subscribe:u=>(e.push(u),{unsubscribe:()=>{e=e.filter(n=>n!==u)}}),unsubscribe:()=>{e=[]}}};function dt(e,s){const t={};for(const i in e)if(e.hasOwnProperty(i)){const u=e[i],n=s[i];if(u&&M(u)&&n){const d=dt(u,n);M(d)&&(t[i]=d)}else e[i]&&(t[i]=n)}return t}var q=e=>M(e)&&!Object.keys(e).length,Be=e=>e.type==="file",X=e=>typeof e=="function",me=e=>{if(!Te)return!1;const s=e?e.ownerDocument:0;return e instanceof(s&&s.defaultView?s.defaultView.HTMLElement:HTMLElement)},ct=e=>e.type==="select-multiple",Ne=e=>e.type==="radio",Ut=e=>Ne(e)||he(e),Ee=e=>me(e)&&e.isConnected;function pt(e,s){const t=s.slice(0,-1).length;let i=0;for(;i<t;)e=O(e)?i++:e[s[i++]];return e}function Bt(e){for(const s in e)if(e.hasOwnProperty(s)&&!O(e[s]))return!1;return!0}function L(e,s){const t=Array.isArray(s)?s:Fe(s)?[s]:Me(s),i=t.length===1?e:pt(e,t),u=t.length-1,n=t[u];return i&&delete i[n],u!==0&&(M(i)&&q(i)||Array.isArray(i)&&Bt(i))&&L(e,t.slice(0,-1)),e}var Nt=e=>{for(const s in e)if(X(e[s]))return!0;return!1};function ft(e){return Array.isArray(e)||M(e)&&!Nt(e)}function Oe(e,s={}){for(const t in e){const i=e[t];ft(i)?(s[t]=Array.isArray(i)?[]:{},Oe(i,s[t])):O(i)||(s[t]=!0)}return s}function le(e,s,t){t||(t=Oe(s));for(const i in e){const u=e[i];if(ft(u))O(s)||Re(t[i])?t[i]=Oe(u,Array.isArray(u)?[]:{}):le(u,j(s)?{}:s[i],t[i]);else{const n=s[i];t[i]=!Q(u,n)}}return t}const Je={value:!1,isValid:!1},Qe={value:!0,isValid:!0};var yt=e=>{if(Array.isArray(e)){if(e.length>1){const s=e.filter(t=>t&&t.checked&&!t.disabled).map(t=>t.value);return{value:s,isValid:!!s.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!O(e[0].attributes.value)?O(e[0].value)||e[0].value===""?Qe:{value:e[0].value,isValid:!0}:Qe:Je}return Je},ht=(e,{valueAsNumber:s,valueAsDate:t,setValueAs:i})=>O(e)?e:s?e===""?NaN:e&&+e:t&&G(e)?new Date(e):i?i(e):e;const Xe={isValid:!1,value:null};var gt=e=>Array.isArray(e)?e.reduce((s,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:s,Xe):Xe;function Ze(e){const s=e.ref;return Be(s)?s.files:Ne(s)?gt(e.refs).value:ct(s)?[...s.selectedOptions].map(({value:t})=>t):he(s)?yt(e.refs).value:ht(O(s.value)?e.ref.value:s.value,e)}var Pt=(e,s,t,i)=>{const u={};for(const n of e){const d=y(s,n);d&&C(u,n,d._f)}return{criteriaMode:t,names:[...e],fields:u,shouldUseNativeValidation:i}},Ve=e=>e instanceof RegExp,ce=e=>O(e)?e:Ve(e)?e.source:M(e)?Ve(e.value)?e.value.source:e.value:e,et=e=>({isOnSubmit:!e||e===J.onSubmit,isOnBlur:e===J.onBlur,isOnChange:e===J.onChange,isOnAll:e===J.all,isOnTouch:e===J.onTouched});const tt="AsyncFunction";var It=e=>!!e&&!!e.validate&&!!(X(e.validate)&&e.validate.constructor.name===tt||M(e.validate)&&Object.values(e.validate).find(s=>s.constructor.name===tt)),qt=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),rt=(e,s,t)=>!t&&(s.watchAll||s.watch.has(e)||[...s.watch].some(i=>e.startsWith(i)&&/^\.\w+/.test(e.slice(i.length))));const ye=(e,s,t,i)=>{for(const u of t||Object.keys(e)){const n=y(e,u);if(n){const{_f:d,...c}=n;if(d){if(d.refs&&d.refs[0]&&s(d.refs[0],u)&&!i)return!0;if(d.ref&&s(d.ref,d.name)&&!i)return!0;if(ye(c,s))break}else if(M(c)&&ye(c,s))break}}};function st(e,s,t){const i=y(e,t);if(i||Fe(t))return{error:i,name:t};const u=t.split(".");for(;u.length;){const n=u.join("."),d=y(s,n),c=y(e,n);if(d&&!Array.isArray(d)&&t!==n)return{name:t};if(c&&c.type)return{name:n,error:c};if(c&&c.root&&c.root.type)return{name:`${n}.root`,error:c.root};u.pop()}return{name:t}}var Wt=(e,s,t,i)=>{t(e);const{name:u,...n}=e;return q(n)||Object.keys(n).length>=Object.keys(s).length||Object.keys(n).find(d=>s[d]===(!i||J.all))},Ht=(e,s,t)=>!e||!s||e===s||fe(e).some(i=>i&&(t?i===s:i.startsWith(s)||s.startsWith(i))),jt=(e,s,t,i,u)=>u.isOnAll?!1:!t&&u.isOnTouch?!(s||e):(t?i.isOnBlur:u.isOnBlur)?!e:(t?i.isOnChange:u.isOnChange)?e:!0,$t=(e,s)=>!Le(y(e,s)).length&&L(e,s),Kt=(e,s,t)=>{const i=fe(y(e,t));return C(i,"root",s[t]),C(e,t,i),e};function it(e,s,t="validate"){if(G(e)||Array.isArray(e)&&e.every(G)||z(e)&&!e)return{type:t,message:G(e)?e:"",ref:s}}var ue=e=>M(e)&&!Ve(e)?e:{value:e,message:""},at=async(e,s,t,i,u,n)=>{const{ref:d,refs:c,required:w,maxLength:S,minLength:V,min:b,max:v,pattern:p,validate:W,name:R,valueAsNumber:B,mount:Z}=e._f,m=y(t,R);if(!Z||s.has(R))return{};const N=c?c[0]:d,F=A=>{u&&N.reportValidity&&(N.setCustomValidity(z(A)?"":A||""),N.reportValidity())},x={},$=Ne(d),K=he(d),oe=$||K,P=(B||Be(d))&&O(d.value)&&O(m)||me(d)&&d.value===""||m===""||Array.isArray(m)&&!m.length,ie=Mt.bind(null,R,i,x),ee=(A,D,T,I=re.maxLength,H=re.minLength)=>{const te=A?D:T;x[R]={type:A?I:H,message:te,ref:d,...ie(A?I:H,te)}};if(n?!Array.isArray(m)||!m.length:w&&(!oe&&(P||j(m))||z(m)&&!m||K&&!yt(c).isValid||$&&!gt(c).isValid)){const{value:A,message:D}=G(w)?{value:!!w,message:w}:ue(w);if(A&&(x[R]={type:re.required,message:D,ref:N,...ie(re.required,D)},!i))return F(D),x}if(!P&&(!j(b)||!j(v))){let A,D;const T=ue(v),I=ue(b);if(!j(m)&&!isNaN(m)){const H=d.valueAsNumber||m&&+m;j(T.value)||(A=H>T.value),j(I.value)||(D=H<I.value)}else{const H=d.valueAsDate||new Date(m),te=ge=>new Date(new Date().toDateString()+" "+ge),de=d.type=="time",ne=d.type=="week";G(T.value)&&m&&(A=de?te(m)>te(T.value):ne?m>T.value:H>new Date(T.value)),G(I.value)&&m&&(D=de?te(m)<te(I.value):ne?m<I.value:H<new Date(I.value))}if((A||D)&&(ee(!!A,T.message,I.message,re.max,re.min),!i))return F(x[R].message),x}if((S||V)&&!P&&(G(m)||n&&Array.isArray(m))){const A=ue(S),D=ue(V),T=!j(A.value)&&m.length>+A.value,I=!j(D.value)&&m.length<+D.value;if((T||I)&&(ee(T,A.message,D.message),!i))return F(x[R].message),x}if(p&&!P&&G(m)){const{value:A,message:D}=ue(p);if(Ve(A)&&!m.match(A)&&(x[R]={type:re.pattern,message:D,ref:d,...ie(re.pattern,D)},!i))return F(D),x}if(W){if(X(W)){const A=await W(m,t),D=it(A,N);if(D&&(x[R]={...D,...ie(re.validate,D.message)},!i))return F(D.message),x}else if(M(W)){let A={};for(const D in W){if(!q(A)&&!i)break;const T=it(await W[D](m,t),N,D);T&&(A={...T,...ie(D,T.message)},F(T.message),i&&(x[R]=A))}if(!q(A)&&(x[R]={ref:N,...A},!i))return x}}return F(!0),x};const zt={mode:J.onSubmit,reValidateMode:J.onChange,shouldFocusError:!0};function Gt(e={}){let s={...zt,...e},t={submitCount:0,isDirty:!1,isReady:!1,isLoading:X(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:s.errors||{},disabled:s.disabled||!1},i={},u=M(s.defaultValues)||M(s.values)?U(s.defaultValues||s.values)||{}:{},n=s.shouldUnregister?{}:U(u),d={action:!1,mount:!1,watch:!1},c={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},w,S=0;const V={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1};let b={...V};const v={array:Ye(),state:Ye()},p=s.criteriaMode===J.all,W=r=>a=>{clearTimeout(S),S=setTimeout(r,a)},R=async r=>{if(!s.disabled&&(V.isValid||b.isValid||r)){const a=s.resolver?q((await K()).errors):await P(i,!0);a!==t.isValid&&v.state.next({isValid:a})}},B=(r,a)=>{!s.disabled&&(V.isValidating||V.validatingFields||b.isValidating||b.validatingFields)&&((r||Array.from(c.mount)).forEach(l=>{l&&(a?C(t.validatingFields,l,a):L(t.validatingFields,l))}),v.state.next({validatingFields:t.validatingFields,isValidating:!q(t.validatingFields)}))},Z=(r,a=[],l,h,f=!0,o=!0)=>{if(h&&l&&!s.disabled){if(d.action=!0,o&&Array.isArray(y(i,r))){const g=l(y(i,r),h.argA,h.argB);f&&C(i,r,g)}if(o&&Array.isArray(y(t.errors,r))){const g=l(y(t.errors,r),h.argA,h.argB);f&&C(t.errors,r,g),$t(t.errors,r)}if((V.touchedFields||b.touchedFields)&&o&&Array.isArray(y(t.touchedFields,r))){const g=l(y(t.touchedFields,r),h.argA,h.argB);f&&C(t.touchedFields,r,g)}(V.dirtyFields||b.dirtyFields)&&(t.dirtyFields=le(u,n)),v.state.next({name:r,isDirty:ee(r,a),dirtyFields:t.dirtyFields,errors:t.errors,isValid:t.isValid})}else C(n,r,a)},m=(r,a)=>{C(t.errors,r,a),v.state.next({errors:t.errors})},N=r=>{t.errors=r,v.state.next({errors:t.errors,isValid:!1})},F=(r,a,l,h)=>{const f=y(i,r);if(f){const o=y(n,r,O(l)?y(u,r):l);O(o)||h&&h.defaultChecked||a?C(n,r,a?o:Ze(f._f)):T(r,o),d.mount&&!d.action&&R()}},x=(r,a,l,h,f)=>{let o=!1,g=!1;const k={name:r};if(!s.disabled){if(!l||h){(V.isDirty||b.isDirty)&&(g=t.isDirty,t.isDirty=k.isDirty=ee(),o=g!==k.isDirty);const E=Q(y(u,r),a);g=!!y(t.dirtyFields,r),E?L(t.dirtyFields,r):C(t.dirtyFields,r,!0),k.dirtyFields=t.dirtyFields,o=o||(V.dirtyFields||b.dirtyFields)&&g!==!E}if(l){const E=y(t.touchedFields,r);E||(C(t.touchedFields,r,l),k.touchedFields=t.touchedFields,o=o||(V.touchedFields||b.touchedFields)&&E!==l)}o&&f&&v.state.next(k)}return o?k:{}},$=(r,a,l,h)=>{const f=y(t.errors,r),o=(V.isValid||b.isValid)&&z(a)&&t.isValid!==a;if(s.delayError&&l?(w=W(()=>m(r,l)),w(s.delayError)):(clearTimeout(S),w=null,l?C(t.errors,r,l):L(t.errors,r)),(l?!Q(f,l):f)||!q(h)||o){const g={...h,...o&&z(a)?{isValid:a}:{},errors:t.errors,name:r};t={...t,...g},v.state.next(g)}},K=async r=>{B(r,!0);const a=await s.resolver(n,s.context,Pt(r||c.mount,i,s.criteriaMode,s.shouldUseNativeValidation));return B(r),a},oe=async r=>{const{errors:a}=await K(r);if(r)for(const l of r){const h=y(a,l);h?C(t.errors,l,h):L(t.errors,l)}else t.errors=a;return a},P=async(r,a,l={valid:!0})=>{for(const h in r){const f=r[h];if(f){const{_f:o,...g}=f;if(o){const k=c.array.has(o.name),E=f._f&&It(f._f);E&&V.validatingFields&&B([o.name],!0);const Y=await at(f,c.disabled,n,p,s.shouldUseNativeValidation&&!a,k);if(E&&V.validatingFields&&B([o.name]),Y[o.name]&&(l.valid=!1,a))break;!a&&(y(Y,o.name)?k?Kt(t.errors,Y,o.name):C(t.errors,o.name,Y[o.name]):L(t.errors,o.name))}!q(g)&&await P(g,a,l)}}return l.valid},ie=()=>{for(const r of c.unMount){const a=y(i,r);a&&(a._f.refs?a._f.refs.every(l=>!Ee(l)):!Ee(a._f.ref))&&Ae(r)}c.unMount=new Set},ee=(r,a)=>!s.disabled&&(r&&a&&C(n,r,a),!Q(ge(),u)),A=(r,a,l)=>Ce(r,c,{...d.mount?n:O(a)?u:G(r)?{[r]:a}:a},l,a),D=r=>Le(y(d.mount?n:u,r,s.shouldUnregister?y(u,r,[]):[])),T=(r,a,l={})=>{const h=y(i,r);let f=a;if(h){const o=h._f;o&&(!o.disabled&&C(n,r,ht(a,o)),f=me(o.ref)&&j(a)?"":a,ct(o.ref)?[...o.ref.options].forEach(g=>g.selected=f.includes(g.value)):o.refs?he(o.ref)?o.refs.forEach(g=>{(!g.defaultChecked||!g.disabled)&&(Array.isArray(f)?g.checked=!!f.find(k=>k===g.value):g.checked=f===g.value||!!f)}):o.refs.forEach(g=>g.checked=g.value===f):Be(o.ref)?o.ref.value="":(o.ref.value=f,o.ref.type||v.state.next({name:r,values:U(n)})))}(l.shouldDirty||l.shouldTouch)&&x(r,f,l.shouldTouch,l.shouldDirty,!0),l.shouldValidate&&ne(r)},I=(r,a,l)=>{for(const h in a){if(!a.hasOwnProperty(h))return;const f=a[h],o=r+"."+h,g=y(i,o);(c.array.has(r)||M(f)||g&&!g._f)&&!ae(f)?I(o,f,l):T(o,f,l)}},H=(r,a,l={})=>{const h=y(i,r),f=c.array.has(r),o=U(a);C(n,r,o),f?(v.array.next({name:r,values:U(n)}),(V.isDirty||V.dirtyFields||b.isDirty||b.dirtyFields)&&l.shouldDirty&&v.state.next({name:r,dirtyFields:le(u,n),isDirty:ee(r,o)})):h&&!h._f&&!j(o)?I(r,o,l):T(r,o,l),rt(r,c)&&v.state.next({...t,name:r}),v.state.next({name:d.mount?r:void 0,values:U(n)})},te=async r=>{d.mount=!0;const a=r.target;let l=a.name,h=!0;const f=y(i,l),o=E=>{h=Number.isNaN(E)||ae(E)&&isNaN(E.getTime())||Q(E,y(n,l,E))},g=et(s.mode),k=et(s.reValidateMode);if(f){let E,Y;const ve=a.type?Ze(f._f):ut(r),se=r.type===be.BLUR||r.type===be.FOCUS_OUT,wt=!qt(f._f)&&!s.resolver&&!y(t.errors,l)&&!f._f.deps||jt(se,y(t.touchedFields,l),t.isSubmitted,k,g),De=rt(l,c,se);C(n,l,ve),se?(!a||!a.readOnly)&&(f._f.onBlur&&f._f.onBlur(r),w&&w(0)):f._f.onChange&&f._f.onChange(r);const Se=x(l,ve,se),kt=!q(Se)||De;if(!se&&v.state.next({name:l,type:r.type,values:U(n)}),wt)return(V.isValid||b.isValid)&&(s.mode==="onBlur"?se&&R():se||R()),kt&&v.state.next({name:l,...De?{}:Se});if(!se&&De&&v.state.next({...t}),s.resolver){const{errors:ze}=await K([l]);if(o(ve),h){const Dt=st(t.errors,i,l),Ge=st(ze,i,Dt.name||l);E=Ge.error,l=Ge.name,Y=q(ze)}}else B([l],!0),E=(await at(f,c.disabled,n,p,s.shouldUseNativeValidation))[l],B([l]),o(ve),h&&(E?Y=!1:(V.isValid||b.isValid)&&(Y=await P(i,!0)));h&&(f._f.deps&&(!Array.isArray(f._f.deps)||f._f.deps.length>0)&&ne(f._f.deps),$(l,Y,E,Se))}},de=(r,a)=>{if(y(t.errors,a)&&r.focus)return r.focus(),1},ne=async(r,a={})=>{let l,h;const f=fe(r);if(s.resolver){const o=await oe(O(r)?r:f);l=q(o),h=r?!f.some(g=>y(o,g)):l}else r?(h=(await Promise.all(f.map(async o=>{const g=y(i,o);return await P(g&&g._f?{[o]:g}:g)}))).every(Boolean),!(!h&&!t.isValid)&&R()):h=l=await P(i);return v.state.next({...!G(r)||(V.isValid||b.isValid)&&l!==t.isValid?{}:{name:r},...s.resolver||!r?{isValid:l}:{},errors:t.errors}),a.shouldFocus&&!h&&ye(i,de,r?f:c.mount),h},ge=(r,a)=>{let l={...d.mount?n:u};return a&&(l=dt(a.dirtyFields?t.dirtyFields:t.touchedFields,l)),O(r)?l:G(r)?y(l,r):r.map(h=>y(l,h))},Pe=(r,a)=>({invalid:!!y((a||t).errors,r),isDirty:!!y((a||t).dirtyFields,r),error:y((a||t).errors,r),isValidating:!!y(t.validatingFields,r),isTouched:!!y((a||t).touchedFields,r)}),_t=r=>{r&&fe(r).forEach(a=>L(t.errors,a)),v.state.next({errors:r?t.errors:{}})},Ie=(r,a,l)=>{const h=(y(i,r,{_f:{}})._f||{}).ref,f=y(t.errors,r)||{},{ref:o,message:g,type:k,...E}=f;C(t.errors,r,{...E,...a,ref:h}),v.state.next({name:r,errors:t.errors,isValid:!1}),l&&l.shouldFocus&&h&&h.focus&&h.focus()},bt=(r,a)=>X(r)?v.state.subscribe({next:l=>"values"in l&&r(A(void 0,a),l)}):A(r,a,!0),qe=r=>v.state.subscribe({next:a=>{Ht(r.name,a.name,r.exact)&&Wt(a,r.formState||V,At,r.reRenderRoot)&&r.callback({values:{...n},...t,...a,defaultValues:u})}}).unsubscribe,mt=r=>(d.mount=!0,b={...b,...r.formState},qe({...r,formState:b})),Ae=(r,a={})=>{for(const l of r?fe(r):c.mount)c.mount.delete(l),c.array.delete(l),a.keepValue||(L(i,l),L(n,l)),!a.keepError&&L(t.errors,l),!a.keepDirty&&L(t.dirtyFields,l),!a.keepTouched&&L(t.touchedFields,l),!a.keepIsValidating&&L(t.validatingFields,l),!s.shouldUnregister&&!a.keepDefaultValue&&L(u,l);v.state.next({values:U(n)}),v.state.next({...t,...a.keepDirty?{isDirty:ee()}:{}}),!a.keepIsValid&&R()},We=({disabled:r,name:a})=>{(z(r)&&d.mount||r||c.disabled.has(a))&&(r?c.disabled.add(a):c.disabled.delete(a))},we=(r,a={})=>{let l=y(i,r);const h=z(a.disabled)||z(s.disabled);return C(i,r,{...l||{},_f:{...l&&l._f?l._f:{ref:{name:r}},name:r,mount:!0,...a}}),c.mount.add(r),l?We({disabled:z(a.disabled)?a.disabled:s.disabled,name:r}):F(r,!0,a.value),{...h?{disabled:a.disabled||s.disabled}:{},...s.progressive?{required:!!a.required,min:ce(a.min),max:ce(a.max),minLength:ce(a.minLength),maxLength:ce(a.maxLength),pattern:ce(a.pattern)}:{},name:r,onChange:te,onBlur:te,ref:f=>{if(f){we(r,a),l=y(i,r);const o=O(f.value)&&f.querySelectorAll&&f.querySelectorAll("input,select,textarea")[0]||f,g=Ut(o),k=l._f.refs||[];if(g?k.find(E=>E===o):o===l._f.ref)return;C(i,r,{_f:{...l._f,...g?{refs:[...k.filter(Ee),o,...Array.isArray(y(u,r))?[{}]:[]],ref:{type:o.type,name:r}}:{ref:o}}}),F(r,!1,void 0,o)}else l=y(i,r,{}),l._f&&(l._f.mount=!1),(s.shouldUnregister||a.shouldUnregister)&&!(lt(c.array,r)&&d.action)&&c.unMount.add(r)}}},ke=()=>s.shouldFocusError&&ye(i,de,c.mount),Vt=r=>{z(r)&&(v.state.next({disabled:r}),ye(i,(a,l)=>{const h=y(i,l);h&&(a.disabled=h._f.disabled||r,Array.isArray(h._f.refs)&&h._f.refs.forEach(f=>{f.disabled=h._f.disabled||r}))},0,!1))},He=(r,a)=>async l=>{let h;l&&(l.preventDefault&&l.preventDefault(),l.persist&&l.persist());let f=U(n);if(v.state.next({isSubmitting:!0}),s.resolver){const{errors:o,values:g}=await K();t.errors=o,f=U(g)}else await P(i);if(c.disabled.size)for(const o of c.disabled)L(f,o);if(L(t.errors,"root"),q(t.errors)){v.state.next({errors:{}});try{await r(f,l)}catch(o){h=o}}else a&&await a({...t.errors},l),ke(),setTimeout(ke);if(v.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:q(t.errors)&&!h,submitCount:t.submitCount+1,errors:t.errors}),h)throw h},Ft=(r,a={})=>{y(i,r)&&(O(a.defaultValue)?H(r,U(y(u,r))):(H(r,a.defaultValue),C(u,r,U(a.defaultValue))),a.keepTouched||L(t.touchedFields,r),a.keepDirty||(L(t.dirtyFields,r),t.isDirty=a.defaultValue?ee(r,U(y(u,r))):ee()),a.keepError||(L(t.errors,r),V.isValid&&R()),v.state.next({...t}))},je=(r,a={})=>{const l=r?U(r):u,h=U(l),f=q(r),o=f?u:h;if(a.keepDefaultValues||(u=l),!a.keepValues){if(a.keepDirtyValues){const g=new Set([...c.mount,...Object.keys(le(u,n))]);for(const k of Array.from(g))y(t.dirtyFields,k)?C(o,k,y(n,k)):H(k,y(o,k))}else{if(Te&&O(r))for(const g of c.mount){const k=y(i,g);if(k&&k._f){const E=Array.isArray(k._f.refs)?k._f.refs[0]:k._f.ref;if(me(E)){const Y=E.closest("form");if(Y){Y.reset();break}}}}if(a.keepFieldsRef)for(const g of c.mount)H(g,y(o,g));else i={}}n=s.shouldUnregister?a.keepDefaultValues?U(u):{}:U(o),v.array.next({values:{...o}}),v.state.next({values:{...o}})}c={mount:a.keepDirtyValues?c.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},d.mount=!V.isValid||!!a.keepIsValid||!!a.keepDirtyValues||!s.shouldUnregister&&!q(o),d.watch=!!s.shouldUnregister,d.action=!1,a.keepErrors||(t.errors={}),v.state.next({submitCount:a.keepSubmitCount?t.submitCount:0,isDirty:f?!1:a.keepDirty?t.isDirty:!!(a.keepDefaultValues&&!Q(r,u)),isSubmitted:a.keepIsSubmitted?t.isSubmitted:!1,dirtyFields:f?{}:a.keepDirtyValues?a.keepDefaultValues&&n?le(u,n):t.dirtyFields:a.keepDefaultValues&&r?le(u,r):a.keepDirty?t.dirtyFields:{},touchedFields:a.keepTouched?t.touchedFields:{},errors:a.keepErrors?t.errors:{},isSubmitSuccessful:a.keepIsSubmitSuccessful?t.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:u})},$e=(r,a)=>je(X(r)?r(n):r,a),xt=(r,a={})=>{const l=y(i,r),h=l&&l._f;if(h){const f=h.refs?h.refs[0]:h.ref;f.focus&&(f.focus(),a.shouldSelect&&X(f.select)&&f.select())}},At=r=>{t={...t,...r}},Ke={control:{register:we,unregister:Ae,getFieldState:Pe,handleSubmit:He,setError:Ie,_subscribe:qe,_runSchema:K,_focusError:ke,_getWatch:A,_getDirty:ee,_setValid:R,_setFieldArray:Z,_setDisabledField:We,_setErrors:N,_getFieldArray:D,_reset:je,_resetDefaultValues:()=>X(s.defaultValues)&&s.defaultValues().then(r=>{$e(r,s.resetOptions),v.state.next({isLoading:!1})}),_removeUnmounted:ie,_disableForm:Vt,_subjects:v,_proxyFormState:V,get _fields(){return i},get _formValues(){return n},get _state(){return d},set _state(r){d=r},get _defaultValues(){return u},get _names(){return c},set _names(r){c=r},get _formState(){return t},get _options(){return s},set _options(r){s={...s,...r}}},subscribe:mt,trigger:ne,register:we,handleSubmit:He,watch:bt,setValue:H,getValues:ge,reset:$e,resetField:Ft,clearErrors:_t,unregister:Ae,setError:Ie,setFocus:xt,getFieldState:Pe};return{...Ke,formControl:Ke}}function Yt(e={}){const s=_.useRef(void 0),t=_.useRef(void 0),[i,u]=_.useState({isDirty:!1,isValidating:!1,isLoading:X(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:X(e.defaultValues)?void 0:e.defaultValues});if(!s.current)if(e.formControl)s.current={...e.formControl,formState:i},e.defaultValues&&!X(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:d,...c}=Gt(e);s.current={...c,formState:i}}const n=s.current.control;return n._options=e,pe(()=>{const d=n._subscribe({formState:n._proxyFormState,callback:()=>u({...n._formState}),reRenderRoot:!0});return u(c=>({...c,isReady:!0})),n._formState.isReady=!0,d},[n]),_.useEffect(()=>n._disableForm(e.disabled),[n,e.disabled]),_.useEffect(()=>{e.mode&&(n._options.mode=e.mode),e.reValidateMode&&(n._options.reValidateMode=e.reValidateMode)},[n,e.mode,e.reValidateMode]),_.useEffect(()=>{e.errors&&(n._setErrors(e.errors),n._focusError())},[n,e.errors]),_.useEffect(()=>{e.shouldUnregister&&n._subjects.state.next({values:n._getWatch()})},[n,e.shouldUnregister]),_.useEffect(()=>{if(n._proxyFormState.isDirty){const d=n._getDirty();d!==i.isDirty&&n._subjects.state.next({isDirty:d})}},[n,i.isDirty]),_.useEffect(()=>{var d;e.values&&!Q(e.values,t.current)?(n._reset(e.values,{keepFieldsRef:!0,...n._options.resetOptions}),!((d=n._options.resetOptions)===null||d===void 0)&&d.keepIsValid||n._setValid(),t.current=e.values,u(c=>({...c}))):n._resetDefaultValues()},[n,e.values]),_.useEffect(()=>{n._state.mount||(n._setValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()}),s.current.formState=ot(i,n),s.current}const vt=({children:e,onSubmit:s=()=>{},style:t={},className:i="",formOptions:u})=>{const n=Yt({mode:"onSubmit",reValidateMode:"onChange",shouldFocusError:!0,...u});return _e.jsx(Ct,{...n,children:_e.jsx("form",{noValidate:!0,onSubmit:n.handleSubmit(s),style:t,className:i,children:e})})},Jt=({children:e,name:s,rules:t})=>{const{control:i}=xe();return _e.jsx(Lt,{control:i,name:s,rules:t,render:u=>_e.jsx(Qt,{...u,children:e})})},Qt=({field:e,fieldState:s,children:t})=>{const{onChange:i,onBlur:u,value:n,name:d,disabled:c}=e,{error:w}=s,S=t.props.onChange,V=t.props.onBlur,b=_.useCallback((...p)=>{i(...p),S==null||S(...p)},[i,S]),v=_.useCallback((...p)=>{u(),V==null||V(...p)},[u,V]);return _.cloneElement(t,{...t.props,name:d,disabled:c,onChange:b,value:n||t.props.value,onBlur:v,error:w})};vt.Control=Jt;exports.SuprForm=vt;
|
|
2
|
+
//# sourceMappingURL=suprform.cjs.js.map
|