react-simple-formkit 2.2.4 → 2.2.6
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/README.md +47 -39
- package/dist/react-simple-formkit.js +4 -4
- package/dist/react-simple-formkit.mjs +186 -180
- package/dist/react-simple-formkit.umd.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,10 @@ Supports managing forms as uncontrolled. State updates only when watched. Simple
|
|
|
15
15
|
- [Get value](#get-value)
|
|
16
16
|
- [Set value](#set-value)
|
|
17
17
|
- [Default values and reset](#default-values-and-reset)
|
|
18
|
-
- [Manage
|
|
18
|
+
- [Manage form state](#manage-form-state)
|
|
19
|
+
- [Get form state](#get-form-state)
|
|
20
|
+
- [Set form state](#set-form-state)
|
|
21
|
+
- [Manage field states](#manage-field-states)
|
|
19
22
|
- [Get field states](#get-field-states)
|
|
20
23
|
- [Set field states](#set-field-states)
|
|
21
24
|
- [Manage errors](#manage-errors)
|
|
@@ -78,24 +81,35 @@ return (
|
|
|
78
81
|
|
|
79
82
|
## Modes of input field
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
React Simple FormKit provides three flexible modes to help you balance performance and feature requirements.
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
`<input type="text">`, `<input type="checkbox">`, `<select>`, or `<textarea>`.
|
|
86
|
+
### 1. `Uncontrolled`:
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
**Best for**: High Performance.
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
- **Use Cases**:
|
|
91
|
+
- Standard HTML inputs (e.g. `<input>`, `<textarea>`, `<select>`...)
|
|
92
|
+
- UI library components that are simple wrappers around these native elements that still follow the browser's standard behavior
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
- **How it works**: The browser manages form by default. However, you still maintain **full visibility**: you can [watch](#watching-for-updates) the entire form state, field states, and values.
|
|
95
|
+
|
|
96
|
+
- **`onBlur` Behavior**: Works automatically by default.
|
|
97
|
+
|
|
98
|
+
### 2. `Controlled`:
|
|
99
|
+
|
|
100
|
+
**Best for**: Absolute control over input or complex UIs.
|
|
101
|
+
|
|
102
|
+
**Use Cases**: Advanced UI components with complex **INPUT AND OUTPUT** . For example, a multiple select component expects an array as its input/output, but your form state might need to store the value as a string.
|
|
91
103
|
|
|
92
104
|
By using `Controller`, you can transform the value in both directions:
|
|
93
105
|
|
|
94
106
|
- On `input`: split the stored string into an array to pass to the UI component.
|
|
95
107
|
- On `change`: join the selected array back into a string before updating the form state.
|
|
96
108
|
|
|
97
|
-
> **Note:**
|
|
98
|
-
>
|
|
109
|
+
> **Note:**
|
|
110
|
+
> whenever you want to **control the value of a field** (e.g. by calling **`actions.setValue`**), you **must** wrap that field with a **`Controller`**.
|
|
111
|
+
> Without **`Controller`**, the field will not respond to external value changes.
|
|
112
|
+
> You should explicitly pass the **`onBlur`** prop during rendering for the library to track the field's state.
|
|
99
113
|
|
|
100
114
|
Example:
|
|
101
115
|
|
|
@@ -123,23 +137,6 @@ Example:
|
|
|
123
137
|
/>
|
|
124
138
|
```
|
|
125
139
|
|
|
126
|
-
### `Captured`
|
|
127
|
-
|
|
128
|
-
Advanced UI components with complex **OUTPUT ONLY**
|
|
129
|
-
|
|
130
|
-
In these cases, the field is **captured**:
|
|
131
|
-
|
|
132
|
-
- You only listen to its value changes through a custom `onChange`.
|
|
133
|
-
- You can sync the final value into the form when needed (via `actions.setValue`).
|
|
134
|
-
|
|
135
|
-
Example:
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
139
|
-
<DatePicker name="date" onChange={(newValue) => actions.setValue("date", newValue.format("MM/DD/YYYY"))} />
|
|
140
|
-
</LocalizationProvider>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
140
|
### `Full Example`
|
|
144
141
|
|
|
145
142
|
```
|
|
@@ -171,10 +168,6 @@ return (
|
|
|
171
168
|
);
|
|
172
169
|
}}
|
|
173
170
|
/>
|
|
174
|
-
{/* Captured: This datepicker component changes value immediately with a click with custom onChange */}
|
|
175
|
-
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
176
|
-
<DatePicker name="date" onChange={(newValue) => actions.setValue("date", newValue.format("MM/DD/YYYY"))} />
|
|
177
|
-
</LocalizationProvider>
|
|
178
171
|
<button type="button" onClick={() => alert(JSON.stringify(actions.getValues()))}>
|
|
179
172
|
Get value
|
|
180
173
|
</button>
|
|
@@ -298,7 +291,14 @@ return (
|
|
|
298
291
|
|
|
299
292
|
# Manage form state
|
|
300
293
|
|
|
301
|
-
##
|
|
294
|
+
## Set form state
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
actions.setFormState("custom", { hello: "world" })
|
|
298
|
+
actions.setFormState("custom.hello", "world2")
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Get form state
|
|
302
302
|
|
|
303
303
|
```
|
|
304
304
|
const isFormDirty = watch("formState.isDirty")
|
|
@@ -306,35 +306,43 @@ const isFormError = watch("formState.isError")
|
|
|
306
306
|
const dirtyFields = watch("formState.dirtyFields")
|
|
307
307
|
const touchedFields = watch("formState.touchedFields")
|
|
308
308
|
const errorFields = watch("formState.errorFields")
|
|
309
|
+
const customFormState = watch("formState.custom.hello")
|
|
309
310
|
// actions.getFormState()
|
|
310
311
|
const { actions } = useForm()
|
|
311
312
|
console.log(actions.getFormState())
|
|
313
|
+
console.log(actions.getFormState("isDirty"))
|
|
314
|
+
console.log(actions.getFormState("custom.hello"))
|
|
315
|
+
console.log(actions.getFormState(["isDirty", "isError"]))
|
|
312
316
|
```
|
|
313
317
|
|
|
314
318
|
> **Note\*:** watch(), useWatch(), and subscribe() share the same name format.
|
|
315
319
|
|
|
316
320
|
# Manage field states
|
|
317
321
|
|
|
322
|
+
## Set field states
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
actions.setFieldState('fieldName', 'custom', { hello: "world" })
|
|
326
|
+
actions.setFieldState('fieldName', 'custom.hello', "world2")
|
|
327
|
+
```
|
|
328
|
+
|
|
318
329
|
## Get field states
|
|
319
330
|
|
|
320
331
|
```
|
|
321
332
|
const { fieldName: {...}, fieldName2: {...} } = watch("fieldStates")
|
|
322
333
|
const { isDirty, isTouched } = watch("fieldStates.fieldName")
|
|
323
334
|
const isFieldDirty = watch("fieldStates.fieldName.isDirty")
|
|
324
|
-
const fieldCustomState = watch("fieldStates.fieldName.
|
|
335
|
+
const fieldCustomState = watch("fieldStates.fieldName.custom.hello")
|
|
325
336
|
// actions.getFieldStates()
|
|
326
337
|
const { actions } = useForm()
|
|
327
338
|
console.log(actions.getFieldStates())
|
|
339
|
+
console.log(actions.getFieldStates("fieldStates.fieldName.isDirty"))
|
|
340
|
+
console.log(actions.getFieldStates("fieldStates.fieldName.custom.hello"))
|
|
341
|
+
console.log(actions.getFieldStates(["fieldStates.fieldName.isDirty", "fieldStates.fieldName.isError"]))
|
|
328
342
|
```
|
|
329
343
|
|
|
330
344
|
> **Note\*:** watch(), useWatch(), and subscribe() share the same name format.
|
|
331
345
|
|
|
332
|
-
## Set field states
|
|
333
|
-
|
|
334
|
-
```
|
|
335
|
-
actions.setFieldState('fieldName', 'customState', { hello: "world" })
|
|
336
|
-
```
|
|
337
|
-
|
|
338
346
|
# Manage errors
|
|
339
347
|
|
|
340
348
|
## Get field error
|
|
@@ -387,7 +395,7 @@ Return:
|
|
|
387
395
|
- `control`: contains methods and utilities to control the form.
|
|
388
396
|
- `watch(name)`: `Function` [Example](#manage-values)
|
|
389
397
|
- `actions` is an object that contains utilities
|
|
390
|
-
- `actions.reset()`: `(newDefaultValues?: Object) => void` [Example](#default-values-and-reset)
|
|
398
|
+
- `actions.reset()`: `(newDefaultValues?: Object, options?: { clearCustomFormStates?: Boolean, clearCustomFieldStates?: Boolean }) => void` [Example](#default-values-and-reset)
|
|
391
399
|
- `actions.getValues()`: `(name?: String | Array) => Object` [Example](#manage-values)
|
|
392
400
|
- `actions.getErrors()`: `(name?: String | Array) => Object` [Example](#manage-errors)
|
|
393
401
|
- `actions.getFormState()`: `(name?: String | Array) => Object` [Example](#manage-form-state)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react");var oe={exports:{}},
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react");var oe={exports:{}},K={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ie;function Se(){if(ie)return
|
|
9
|
+
*/var ie;function Se(){if(ie)return K;ie=1;var s=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function i(f,h,E){var g=null;if(E!==void 0&&(g=""+E),h.key!==void 0&&(g=""+h.key),"key"in h){E={};for(var m in h)m!=="key"&&(E[m]=h[m])}else E=h;return h=E.ref,{$$typeof:s,type:f,key:g,ref:h!==void 0?h:null,props:E}}return K.Fragment=u,K.jsx=i,K.jsxs=i,K}var ee={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var fe;function Ce(){return fe||(fe=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===D?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case
|
|
17
|
+
*/var fe;function Ce(){return fe||(fe=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===D?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case x:return"Profiler";case O:return"StrictMode";case se:return"Suspense";case ne:return"SuspenseList";case G:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case a:return"Portal";case z:return(e.displayName||"Context")+".Provider";case J:return(e._context.displayName||"Context")+".Consumer";case te:var l=e.render;return e=e.displayName,e||(e=l.displayName||l.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ue:return l=e.displayName||null,l!==null?l:s(e.type)||"Memo";case P:l=e._payload,e=e._init;try{return s(e(l))}catch{}}return null}function u(e){return""+e}function i(e){try{u(e);var l=!1}catch{l=!0}if(l){l=console;var k=l.error,F=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return k.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",F),u(e)}}function f(e){if(e===y)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===P)return"<...>";try{var l=s(e);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function h(){var e=W.A;return e===null?null:e.getOwner()}function E(){return Error("react-stack-top-frame")}function g(e){if($.call(e,"key")){var l=Object.getOwnPropertyDescriptor(e,"key").get;if(l&&l.isReactWarning)return!1}return e.key!==void 0}function m(e,l){function k(){H||(H=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}k.isReactWarning=!0,Object.defineProperty(e,"key",{get:k,configurable:!0})}function R(){var e=s(this.type);return X[e]||(X[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function C(e,l,k,F,j,_,B,I){return k=_.ref,e={$$typeof:c,type:e,key:l,props:_,_owner:j},(k!==void 0?k:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function b(e,l,k,F,j,_,B,I){var w=l.children;if(w!==void 0)if(F)if(M(w)){for(F=0;F<w.length;F++)d(w[F]);Object.freeze&&Object.freeze(w)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else d(w);if($.call(l,"key")){w=s(e);var V=Object.keys(l).filter(function(ae){return ae!=="key"});F=0<V.length?"{key: someKey, "+V.join(": ..., ")+": ...}":"{key: someKey}",Q[w+F]||(V=0<V.length?"{"+V.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,F,w,V,w),Z[w+F]=!0)}if(w=null,k!==void 0&&(i(k),w=""+k),g(l)&&(i(l.key),w=""+l.key),"key"in l){k={};for(var N in l)N!=="key"&&(k[N]=l[N])}else k=l;return w&&m(k,typeof e=="function"?e.displayName||e.name||"Unknown":e),S(e,w,_,j,h(),k,B,I)}function d(e){typeof e=="object"&&e!==null&&e.$$typeof===c&&e._store&&(e._store.validated=1)}var o=t,c=Symbol.for("react.transitional.element"),a=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),q=Symbol.for("react.consumer"),J=Symbol.for("react.context"),re=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),z=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),W=o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,M=Array.isArray,Y=console.createTask?console.createTask:function(){return null};o={"react-stack-bottom-frame":function(e){return e()}};var G,H={},X=o["react-stack-bottom-frame"].bind(o,E)(),p=Y(f(E)),Z={};K.Fragment=C,K.jsx=function(e,l,k,F,j){var _=1e4>W.recentlyCreatedOwnerStacks++;return b(e,l,k,!1,F,j,_?Error("react-stack-top-frame"):X,_?Y(f(e)):p)},K.jsxs=function(e,l,k,F,j){var _=1e4>W.recentlyCreatedOwnerStacks++;return b(e,l,k,!0,F,j,_?Error("react-stack-top-frame"):X,_?Y(f(e)):p)}}()),K}var be;function ye(){return be||(be=1,process.env.NODE_ENV==="production"?oe.exports=Se():oe.exports=Ce()),oe.exports}var de=ye();const v=()=>{},me=t.createContext({ref:null,watch:v,actions:{reset:v,resetField:v,setValue:v,getValues:v,getErrors:v,getFieldStates:v,getFormStates:v,setError:v,clearError:v,clearErrors:v,checkValidity:v,getNumberFields:v,getFieldValidity:v,getDefaultValues:v,setFieldState:v,resetFieldState:v,getControlledFields:v},registerController:v,registerHookWatcher:v,lastReloadedAt:v,loadFormValues:v,getWatchValue:v,channels:{}}),le=()=>t.useContext(me),pe=({id:s,control:u,method:i,action:f,children:h,onSubmit:E=()=>{},onInput:g=()=>{},onChange:m=()=>{},onBlur:R=()=>{},onReset:S=()=>{},numberFields:b=[],className:d,...o})=>(t.useEffect(()=>{const c=u.channels.subscribe("onChange",m),a=u.channels.subscribe("onBlur",R);return()=>{c(),a()}},[u.lastReloadedAt]),de.jsx(me.Provider,{value:u,children:de.jsx("form",{id:s,ref:u.ref,action:f,method:i,className:d,onInput:g,onSubmit:c=>{i||c.preventDefault();const a=u.loadFormValues();E(a)},onChange:c=>{const a=c.target.name;!a||u.actions.getControlledFields().has(a)||u.actions.setValue(a,c.target.value)},onBlur:c=>{const a=c.target.name;if(!a||u.actions.getControlledFields().has(a))return;const C=c.target.value;u.channels.publish("onBlur",a,C,u.actions.getValues())},onReset:c=>{u.actions.reset(),S(c)},...o,children:h},u.lastReloadedAt)})),Re=({control:s,name:u,compute:i})=>{const{getWatchValue:f,registerHookWatcher:h}=s||le(),E=f({name:u,compute:i}),[g,m]=t.useState(E);return t.useEffect(()=>{const R=h({name:u,compute:i,value:g,setValue:m});return()=>R.forEach(S=>S())},[]),g},ke=({name:s,defaultValue:u})=>{const{actions:i,registerController:f,channels:h}=le(),E=t.useRef(),g=i.getDefaultValues()[s]||u||"",[m,R]=t.useState(g),S=Re({name:`fieldStates.${s}`}),b=t.useCallback((o,{shouldDirty:c=!0,shouldOnChange:a=!0}={})=>{var O,x;let C=o;(O=o==null?void 0:o.target)!=null&&O.value&&(C=o.target.value),(x=o==null?void 0:o.target)!=null&&x.checked&&(C=o.target.checked+""),R(C),i.setValue(s,C,{shouldDirty:c,shouldOnChange:a})},[i.setValue]),d=t.useCallback(o=>{const c=i.getValues(),a=o??c[s];h.publish("onBlur",s,a,c)},[]);return t.useEffect(()=>f(s,R),[]),{ref:E,name:s,defaultValue:g,value:m,onChange:b,onBlur:d,fieldState:S}},Fe=({name:s,defaultValue:u,render:i=({ref:f,name:h,defaultValue:E,value:g,onChange:m,onBlur:R,fieldState:S})=>null})=>{const f=ke({name:s,defaultValue:u});return i(f)},we=["errors","fieldStates","formState"],ee=(s={},u="")=>u.split(".").reduce((i,f)=>i&&i[f]!==void 0?i[f]:void 0,s),he=(s={},u="",i)=>{let f=s;const h=u.split(".");return h.forEach((E,g)=>{g<h.length-1&&(f[E]||(f[E]={}),g===h.length-2&&(f[E]={...f[E]}),f=f[E]),f[E]=i}),s},U=s=>we.some(u=>s.startsWith(u))?s:"values."+s,Te=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],Ee=s=>{typeof s.setCustomValidity=="function"&&s.setCustomValidity("");let u=s.validity,i=Te.find(f=>u[f]);if(i)return{type:i,message:s.validationMessage}};class _e{constructor(){this.events=new Map,this.watchEvents=new Map}getWatchEvents(){return this.watchEvents}getEvents(){return this.events}subscribe(u,i){return this.events.has(u)||this.events.set(u,new Set),this.events.get(u).add(i),()=>{var f;return(f=this.events.get(u))==null?void 0:f.delete(i)}}subscribeWatch(u,i){this.watchEvents.has(u)||(this.watchEvents.set(u,new Set),this.watchEvents.get(u).add(i))}publish(u,...i){this.events.forEach((f,h)=>{u.includes(h)&&f.forEach(E=>E(...i))}),this.watchEvents.forEach((f,h)=>{u.includes(h)&&f.forEach(E=>E(...i))})}reset(){this.events.clear(),this.watchEvents.clear()}}const Ae=()=>{const s=t.useRef(new _e),u=t.useCallback((m,...R)=>{s.current.publish(m,...R)},[]),i=t.useCallback((m,R)=>s.current.subscribe(m,R),[]),f=t.useCallback((m,R)=>{s.current.subscribeWatch(m,R)},[]),h=t.useCallback(()=>s.current.getEvents(),[]),E=t.useCallback(()=>s.current.getWatchEvents(),[]),g=t.useCallback(()=>{s.current.reset()},[]);return{publish:u,subscribe:i,reset:g,getEvents:h,subscribeWatch:f,getWatchEvents:E}},Oe=()=>{const[s,u]=t.useState(),i=t.useCallback(()=>u(new Date().toString()),[]);return[s,i]},Pe=()=>{const[,s]=t.useState({});return t.useCallback(()=>s({}),[])},je=({channels:s,getValues:u,getErrors:i,getFieldStates:f,getFormState:h})=>{const E=Pe(),g=t.useCallback(({name:b,compute:d})=>{if(typeof d=="function")return d(u());if(Array.isArray(b)){const o={};return b.forEach(c=>{o[c]=g({name:c})}),o}return ee({...u(),errors:{...i()},formState:{...h()},fieldStates:{...f()}},b)},[]),m=t.useCallback(b=>{if(!b)return s.subscribeWatch("values",()=>E()),u();if(typeof b=="string"){const d=U(b);return s.subscribeWatch(d,()=>E()),g({name:b})}if(Array.isArray(b)){const d={};return b.forEach(o=>{const c=U(o);s.subscribeWatch(c,()=>E()),d[o]=g({name:o})}),{...d}}throw new Error("Parameters of watch must be string or array of string")},[]),R=t.useCallback(({name:b,compute:d,setValue:o})=>{if(typeof d=="function")return[s.subscribe("values",()=>{const a=g({compute:d});o(a)})];if(!b)return[s.subscribe("values",()=>{o(u())})];if(typeof b=="string"){const c=U(b);return[s.subscribe(c,()=>{const C=g({name:b});o(C)})]}if(Array.isArray(b)){const c=g({name:b}),a=[];return b.forEach(C=>{const O=U(C),x=s.subscribe(O,()=>{const q=g({name:C});c[C]=q,o({...c})});a.push(x)}),a}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),S=t.useCallback((b,d)=>{if(!b)return s.subscribe("values",d);if(typeof b=="string"){const o=U(b);return s.subscribe(o,d)}if(Array.isArray(b)){const o={},c=[];return b.forEach(a=>{const C=U(a),O=s.subscribe(C,()=>{o[a]=g({name:a}),d({...o})});c.push(O)}),c}throw new Error("Parameters of name must be string or array of string")},[s]);return{watch:m,registerHookWatcher:R,getWatchValue:g,subscribe:S}},ge={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},ce={isDirty:!1,isTouched:!1,error:null},xe=[],Ne={},Ve=({numberFields:s=xe,defaultValues:u=Ne,shouldUnRegister:i=!1,shouldConvertNumber:f=!1}={})=>{const[h,E]=Oe(),g=t.useRef(),m=t.useRef(s),R=t.useRef(new Map),S=t.useRef({}),b=t.useRef({}),d=t.useRef({...ge}),o=t.useRef({...u}),c=t.useRef({...u}),a=Ae(),C=t.useCallback(()=>{b.current=Object.keys(c.current).reduce((r,n)=>({...r,[n]:{...ce}}),{})},[]),O=t.useCallback((r={})=>{c.current={...c.current,...r},o.current={...c.current},R.current.forEach((n,y)=>{n(c.current[y])}),S.current={},d.current={...ge},m.current=s,R.current=new Map,a.reset(),C(),s.length>0&&(f=!0),E()},[]),x=t.useCallback(()=>{const r=Object.fromEntries(new FormData(g.current));return R.current.forEach((y,T)=>{r[T]=o.current[T]}),f&&m.current.forEach(y=>r.hasOwnProperty(y)&&(r[y]=Number(r[y])||0)),{...o.current,...r}},[]),q=t.useCallback(()=>!!Object.values(W()).find(r=>r.isDirty),[]),J=t.useCallback(()=>!!Object.values(D()).find(r=>!!r),[]),re=t.useCallback(r=>Ee(r.target),[]),te=t.useCallback(()=>c.current,[]),se=t.useCallback(()=>m.current,[]),ne=t.useCallback(()=>R.current,[]),P=t.useCallback((r,n)=>n?Array.isArray(n)?n.reduce((y,T)=>({...y,[T]:ee(r,T)}),{}):ee(r,n):{...r},[]),z=t.useCallback(r=>P(o.current,r),[P]),D=t.useCallback(r=>P(S.current,r),[P]),W=t.useCallback(r=>P(b.current,r),[P]),$=t.useCallback(r=>P({...d.current,lastReset:h},r),[P,h]),{watch:M,registerHookWatcher:Y,getWatchValue:G,subscribe:H}=je({channels:a,getValues:z,getErrors:D,getFieldStates:W,getFormState:$}),X=t.useCallback((r,n)=>{const y=d.current;ee(y,r)!==n&&(he(d.current,r,n),a.publish(`formState.${r}`,n))},[]),p=t.useCallback((r,n,y)=>{const T=b.current[r]||{...ce};ee(T,n)!==y&&(he(b.current,`${r}.${n}`,y),a.publish(`fieldStates.${r}.${n}`,y),n==="error"&&(d.current.errorFields=Object.keys(S.current).filter(A=>!!S.current[A]),a.publish("formState.errorFields",d.current.errorFields)),n==="isDirty"&&(d.current.dirtyFields=Object.keys(b.current).filter(A=>b.current[A].isDirty),a.publish("formState.dirtyFields",d.current.dirtyFields)),n==="isTouched"&&(d.current.touchedFields=Object.keys(b.current).filter(A=>b.current[A].isTouched),a.publish("formState.touchedFields",d.current.touchedFields)))},[]),Z=t.useCallback(r=>{p(r,"isDirty",!1),p(r,"isTouched",!1),p(r,"error",null)},[p]),e=t.useCallback((r,n)=>{if(S.current[r]===n)return;S.current[r]=n,p(r,"error",n),a.publish(`errors.${r}`,n);const T=J();d.current.isError!==T&&(d.current.isError=T,a.publish("formState.isError",T))},[p]),l=t.useCallback(r=>{if(!S.current[r])return;S.current[r]=null,p(r,"error",null),a.publish(`errors.${r}`,null);const n=J();d.current.isError!==n&&(d.current.isError=n,a.publish("formState.isError",n))},[p]),k=t.useCallback(()=>{if(Object.keys(S.current)===0)return;Object.keys(S.current).forEach(n=>l(n)),S.current={};const r=J();d.current.isError!==r&&(d.current.isError=r,a.publish("formState.isError",r))},[]),F=t.useCallback(r=>{const n=Ee(r.target);n?e(r.target.name,n):l(r.target.name)},[e,l]),j=t.useCallback((r,n,{shouldDirty:y=!0,shouldOnChange:T=!0}={})=>{if(n===o.current[r])return;f&&m.current.includes(r)&&(n=Number(n)||void 0),p(r,"isTouched",!0);const ae=n!==c.current[r];y&&b.current[r].isDirty!==ae&&p(r,"isDirty",ae);const A=q();d.current.isDirty!==A&&(d.current.isDirty=A,a.publish("formState.isDirty",A)),o.current[r]=n;const L=R.current.get(r);L&&L(n),a.publish(`values.${r}`,n,{shouldDirty:y,shouldOnChange:T}),T&&a.publish("onChange",r,n,o.current)},[p]),_=t.useCallback((r,n)=>(R.current.set(r,n),b.current[r]={...ce},()=>{i&&R.current.delete(r)}),[]),B=t.useCallback((r,{keepError:n,keepDirty:y,keepTouched:T,keepCustomState:ae,defaultValue:A})=>{const L=R.current.get(r);if(!L)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);c.current[r]=A,o.current[r]=A,L&&L(A),n||l(r),y||p(r,"isDirty",!1),T||p(r,"isTouched",!1)},[l,p]),I=t.useCallback((r,n=N.getValues(r))=>{a.publish("onBlur",r,n,N.getValues())},[]),w=t.useCallback(r=>a.subscribe("onChange",r),[]),V=t.useCallback(r=>a.subscribe("onBlur",r),[]),N=t.useMemo(()=>({subscribe:H,reset:O,resetField:B,setValue:j,getValues:z,getErrors:D,getFieldStates:W,getFormState:$,setError:e,clearError:l,clearErrors:k,checkValidity:F,getNumberFields:se,getFieldValidity:re,getDefaultValues:te,setFieldState:p,triggerFieldBlur:I,resetFieldState:Z,getControlledFields:ne,subscribeChange:w,subscribeBlur:V,setFormState:X,getEvents:a.getEvents,getWatchEvents:a.getWatchEvents}),[H,O,B,j,z,D,W,$,e,l,k,F,se,re,te,p,Z,I,ne,w,V,X]),ue=t.useMemo(()=>({ref:g,watch:M,actions:N,registerController:_,registerHookWatcher:Y,lastReloadedAt:h,loadFormValues:x,getWatchValue:G,channels:a}),[g,M,N,_,Y,h,x,G,a]),ve=t.useMemo(()=>({control:ue,actions:N,watch:M}),[h,ue,N,M]);return t.useLayoutEffect(()=>{if([...g.current.querySelectorAll("[name]")].forEach(n=>{!n.defaultValue&&!R.current.has(n.name)&&c.current[n.name]&&(n.defaultValue=c.current[n.name]),n.type==="number"&&!m.current.includes(n.name)&&m.current.push(n.name)}),g.current){const n=x();o.current={...n},c.current={...n}}},[h]),t.useLayoutEffect(()=>{C()},[]),ve};exports.Controller=Fe;exports.Form=pe;exports.useController=ke;exports.useForm=Ve;exports.useFormContext=le;exports.useWatch=Re;
|
|
22
|
+
<%s key={someKey} {...props} />`,F,w,V,w),Q[w+F]=!0)}if(w=null,k!==void 0&&(i(k),w=""+k),g(l)&&(i(l.key),w=""+l.key),"key"in l){k={};for(var N in l)N!=="key"&&(k[N]=l[N])}else k=l;return w&&m(k,typeof e=="function"?e.displayName||e.name||"Unknown":e),C(e,w,_,j,h(),k,B,I)}function d(e){typeof e=="object"&&e!==null&&e.$$typeof===c&&e._store&&(e._store.validated=1)}var o=t,c=Symbol.for("react.transitional.element"),a=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),J=Symbol.for("react.consumer"),z=Symbol.for("react.context"),te=Symbol.for("react.forward_ref"),se=Symbol.for("react.suspense"),ne=Symbol.for("react.suspense_list"),ue=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),W=o.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,M=Array.isArray,Y=console.createTask?console.createTask:function(){return null};o={"react-stack-bottom-frame":function(e){return e()}};var H,X={},Z=o["react-stack-bottom-frame"].bind(o,E)(),p=Y(f(E)),Q={};ee.Fragment=y,ee.jsx=function(e,l,k,F,j){var _=1e4>W.recentlyCreatedOwnerStacks++;return b(e,l,k,!1,F,j,_?Error("react-stack-top-frame"):Z,_?Y(f(e)):p)},ee.jsxs=function(e,l,k,F,j){var _=1e4>W.recentlyCreatedOwnerStacks++;return b(e,l,k,!0,F,j,_?Error("react-stack-top-frame"):Z,_?Y(f(e)):p)}}()),ee}var be;function ye(){return be||(be=1,process.env.NODE_ENV==="production"?oe.exports=Se():oe.exports=Ce()),oe.exports}var de=ye();const S=()=>{},me=t.createContext({ref:null,watch:S,actions:{reset:S,resetField:S,setValue:S,getValues:S,getErrors:S,getFieldStates:S,getFormStates:S,setError:S,clearError:S,clearErrors:S,checkValidity:S,getNumberFields:S,getFieldValidity:S,getDefaultValues:S,setFieldState:S,resetFieldState:S,getControlledFields:S},registerController:S,registerHookWatcher:S,lastReloadedAt:S,loadFormValues:S,getWatchValue:S,channels:{}}),le=()=>t.useContext(me),pe=({id:s,control:u,method:i,action:f,children:h,onSubmit:E=()=>{},onInput:g=()=>{},onChange:m=()=>{},onBlur:R=()=>{},onReset:C=()=>{},numberFields:b=[],className:d,...o})=>(t.useEffect(()=>{const c=u.channels.subscribe("onChange",m),a=u.channels.subscribe("onBlur",R);return()=>{c(),a()}},[u.lastReloadedAt]),de.jsx(me.Provider,{value:u,children:de.jsx("form",{id:s,ref:u.ref,action:f,method:i,className:d,onInput:g,onSubmit:c=>{i||c.preventDefault();const a=u.loadFormValues();E(a)},onChange:c=>{const a=c.target.name;!a||u.actions.getControlledFields().has(a)||u.actions.setValue(a,c.target.value)},onBlur:c=>{const a=c.target.name;if(!a||u.actions.getControlledFields().has(a))return;const y=c.target.value;u.channels.publish("onBlur",a,y,u.actions.getValues())},onReset:c=>{u.actions.reset(),C(c)},...o,children:h},u.lastReloadedAt)})),Re=({control:s,name:u,compute:i})=>{const{getWatchValue:f,registerHookWatcher:h}=s||le(),E=f({name:u,compute:i}),[g,m]=t.useState(E);return t.useEffect(()=>{const R=h({name:u,compute:i,value:g,setValue:m});return()=>R.forEach(C=>C())},[]),g},ke=({name:s,defaultValue:u})=>{const{actions:i,registerController:f,channels:h}=le(),E=t.useRef(),g=i.getDefaultValues()[s]||u||"",[m,R]=t.useState(g),C=Re({name:`fieldStates.${s}`}),b=t.useCallback((o,{shouldDirty:c=!0,shouldOnChange:a=!0}={})=>{var O,x;let y=o;(O=o==null?void 0:o.target)!=null&&O.value&&(y=o.target.value),(x=o==null?void 0:o.target)!=null&&x.checked&&(y=o.target.checked+""),R(y),i.setValue(s,y,{shouldDirty:c,shouldOnChange:a})},[i.setValue]),d=t.useCallback(o=>{const c=i.getValues(),a=o??c[s];h.publish("onBlur",s,a,c)},[]);return t.useEffect(()=>f(s,R),[]),{ref:E,name:s,defaultValue:g,value:m,onChange:b,onBlur:d,fieldState:C}},Fe=({name:s,defaultValue:u,render:i=({ref:f,name:h,defaultValue:E,value:g,onChange:m,onBlur:R,fieldState:C})=>null})=>{const f=ke({name:s,defaultValue:u});return i(f)},we=["errors","fieldStates","formState"],re=(s={},u="")=>u.split(".").reduce((i,f)=>i&&i[f]!==void 0?i[f]:void 0,s),he=(s={},u="",i)=>{let f=s;const h=u.split(".");return h.forEach((E,g)=>{g<h.length-1&&(f[E]||(f[E]={}),g===h.length-2&&(f[E]={...f[E]}),f=f[E]),f[E]=i}),s},q=s=>we.some(u=>s.startsWith(u))?s:"values."+s,Te=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],Ee=s=>{typeof s.setCustomValidity=="function"&&s.setCustomValidity("");let u=s.validity,i=Te.find(f=>u[f]);if(i)return{type:i,message:s.validationMessage}};class _e{constructor(){this.events=new Map,this.watchEvents=new Map}getWatchEvents(){return this.watchEvents}getEvents(){return this.events}subscribe(u,i){return this.events.has(u)||this.events.set(u,new Set),this.events.get(u).add(i),()=>{var f;return(f=this.events.get(u))==null?void 0:f.delete(i)}}subscribeWatch(u,i){this.watchEvents.has(u)||(this.watchEvents.set(u,new Set),this.watchEvents.get(u).add(i))}publish(u,...i){this.events.forEach((f,h)=>{u.includes(h)&&f.forEach(E=>E(...i))}),this.watchEvents.forEach((f,h)=>{u.includes(h)&&f.forEach(E=>E(...i))})}reset(){this.events.clear(),this.watchEvents.clear()}}const Ae=()=>{const s=t.useRef(new _e),u=t.useCallback((m,...R)=>{s.current.publish(m,...R)},[]),i=t.useCallback((m,R)=>s.current.subscribe(m,R),[]),f=t.useCallback((m,R)=>{s.current.subscribeWatch(m,R)},[]),h=t.useCallback(()=>s.current.getEvents(),[]),E=t.useCallback(()=>s.current.getWatchEvents(),[]),g=t.useCallback(()=>{s.current.reset()},[]);return{publish:u,subscribe:i,reset:g,getEvents:h,subscribeWatch:f,getWatchEvents:E}},Oe=()=>{const[s,u]=t.useState(),i=t.useCallback(()=>u(new Date().toString()),[]);return[s,i]},Pe=()=>{const[,s]=t.useState({});return t.useCallback(()=>s({}),[])},je=({channels:s,getValues:u,getErrors:i,getFieldStates:f,getFormState:h})=>{const E=Pe(),g=t.useCallback(({name:b,compute:d})=>{if(typeof d=="function")return d(u());if(Array.isArray(b)){const o={};return b.forEach(c=>{o[c]=g({name:c})}),o}return re({...u(),errors:{...i()},formState:{...h()},fieldStates:{...f()}},b)},[]),m=t.useCallback(b=>{if(!b)return s.subscribeWatch("values",()=>E()),u();if(typeof b=="string"){const d=q(b);return s.subscribeWatch(d,()=>E()),g({name:b})}if(Array.isArray(b)){const d={};return b.forEach(o=>{const c=q(o);s.subscribeWatch(c,()=>E()),d[o]=g({name:o})}),{...d}}throw new Error("Parameters of watch must be string or array of string")},[]),R=t.useCallback(({name:b,compute:d,setValue:o})=>{if(typeof d=="function")return[s.subscribe("values",()=>{const a=g({compute:d});o(a)})];if(!b)return[s.subscribe("values",()=>{o(u())})];if(typeof b=="string"){const c=q(b);return[s.subscribe(c,()=>{const y=g({name:b});o(y)})]}if(Array.isArray(b)){const c=g({name:b}),a=[];return b.forEach(y=>{const O=q(y),x=s.subscribe(O,()=>{const J=g({name:y});c[y]=J,o({...c})});a.push(x)}),a}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),C=t.useCallback((b,d)=>{if(!b)return s.subscribe("values",d);if(typeof b=="string"){const o=q(b);return s.subscribe(o,d)}if(Array.isArray(b)){const o={},c=[];return b.forEach(a=>{const y=q(a),O=s.subscribe(y,()=>{o[a]=g({name:a}),d({...o})});c.push(O)}),c}throw new Error("Parameters of name must be string or array of string")},[s]);return{watch:m,registerHookWatcher:R,getWatchValue:g,subscribe:C}},ge={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},ce={isDirty:!1,isTouched:!1,error:null},xe=[],Ne={},Ve=({numberFields:s=xe,defaultValues:u=Ne,shouldUnRegister:i=!1,shouldConvertNumber:f=!1}={})=>{const[h,E]=Oe(),g=t.useRef(),m=t.useRef(s),R=t.useRef(new Map),C=t.useRef({}),b=t.useRef({}),d=t.useRef({...ge}),o=t.useRef({...u}),c=t.useRef({...u}),a=Ae(),y=t.useCallback(r=>{b.current=Object.keys(c.current).reduce((n,v)=>({...n,[v]:{...r?{}:b.current[v]||{},...ce}}),{})},[]),O=t.useCallback((r={},{clearCustomFormStates:n=!1,clearCustomFieldStates:v=!1}={})=>{c.current={...c.current,...r},o.current={...c.current},R.current.forEach((T,L)=>{T(c.current[L])}),C.current={},d.current={...n?{}:d.current,...ge},m.current=s,R.current=new Map,a.reset(),y(v),s.length>0&&(f=!0),E()},[]),x=t.useCallback(()=>{const r=Object.fromEntries(new FormData(g.current));return R.current.forEach((v,T)=>{r[T]=o.current[T]}),f&&m.current.forEach(v=>r.hasOwnProperty(v)&&(r[v]=Number(r[v])||0)),{...o.current,...r}},[]),J=t.useCallback(()=>!!Object.values(W()).find(r=>r.isDirty),[]),z=t.useCallback(()=>!!Object.values(D()).find(r=>!!r),[]),te=t.useCallback(r=>Ee(r.target),[]),se=t.useCallback(()=>c.current,[]),ne=t.useCallback(()=>m.current,[]),ue=t.useCallback(()=>R.current,[]),P=t.useCallback((r,n)=>n?Array.isArray(n)?n.reduce((v,T)=>({...v,[T]:re(r,T)}),{}):re(r,n):{...r},[]),G=t.useCallback(r=>P(o.current,r),[P]),D=t.useCallback(r=>P(C.current,r),[P]),W=t.useCallback(r=>P(b.current,r),[P]),$=t.useCallback(r=>P({...d.current,lastReset:h},r),[P,h]),{watch:M,registerHookWatcher:Y,getWatchValue:H,subscribe:X}=je({channels:a,getValues:G,getErrors:D,getFieldStates:W,getFormState:$}),Z=t.useCallback((r,n)=>{const v=d.current;re(v,r)!==n&&(he(d.current,r,n),a.publish(`formState.${r}`,n))},[]),p=t.useCallback((r,n,v)=>{const T=b.current[r]||{...ce};re(T,n)!==v&&(he(b.current,`${r}.${n}`,v),a.publish(`fieldStates.${r}.${n}`,v),n==="error"&&(d.current.errorFields=Object.keys(C.current).filter(A=>!!C.current[A]),a.publish("formState.errorFields",d.current.errorFields)),n==="isDirty"&&(d.current.dirtyFields=Object.keys(b.current).filter(A=>b.current[A].isDirty),a.publish("formState.dirtyFields",d.current.dirtyFields)),n==="isTouched"&&(d.current.touchedFields=Object.keys(b.current).filter(A=>b.current[A].isTouched),a.publish("formState.touchedFields",d.current.touchedFields)))},[]),Q=t.useCallback(r=>{p(r,"isDirty",!1),p(r,"isTouched",!1),p(r,"error",null)},[p]),e=t.useCallback((r,n)=>{if(C.current[r]===n)return;C.current[r]=n,p(r,"error",n),a.publish(`errors.${r}`,n);const T=z();d.current.isError!==T&&(d.current.isError=T,a.publish("formState.isError",T))},[p]),l=t.useCallback(r=>{if(!C.current[r])return;C.current[r]=null,p(r,"error",null),a.publish(`errors.${r}`,null);const n=z();d.current.isError!==n&&(d.current.isError=n,a.publish("formState.isError",n))},[p]),k=t.useCallback(()=>{if(Object.keys(C.current)===0)return;Object.keys(C.current).forEach(n=>l(n)),C.current={};const r=z();d.current.isError!==r&&(d.current.isError=r,a.publish("formState.isError",r))},[]),F=t.useCallback(r=>{const n=Ee(r.target);n?e(r.target.name,n):l(r.target.name)},[e,l]),j=t.useCallback((r,n,{shouldDirty:v=!0,shouldOnChange:T=!0}={})=>{if(n===o.current[r])return;f&&m.current.includes(r)&&(n=Number(n)||void 0),p(r,"isTouched",!0);const L=n!==c.current[r];v&&b.current[r].isDirty!==L&&p(r,"isDirty",L);const A=J();d.current.isDirty!==A&&(d.current.isDirty=A,a.publish("formState.isDirty",A)),o.current[r]=n;const U=R.current.get(r);U&&U(n),a.publish(`values.${r}`,n,{shouldDirty:v,shouldOnChange:T}),T&&a.publish("onChange",r,n,o.current)},[p]),_=t.useCallback((r,n)=>(R.current.set(r,n),b.current[r]={...ce},()=>{i&&R.current.delete(r)}),[]),B=t.useCallback((r,{keepError:n,keepDirty:v,keepTouched:T,keepCustomState:L,defaultValue:A})=>{const U=R.current.get(r);if(!U)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);c.current[r]=A,o.current[r]=A,U&&U(A),n||l(r),v||p(r,"isDirty",!1),T||p(r,"isTouched",!1)},[l,p]),I=t.useCallback((r,n=N.getValues(r))=>{a.publish("onBlur",r,n,N.getValues())},[]),w=t.useCallback(r=>a.subscribe("onChange",r),[]),V=t.useCallback(r=>a.subscribe("onBlur",r),[]),N=t.useMemo(()=>({subscribe:X,reset:O,resetField:B,setValue:j,getValues:G,getErrors:D,getFieldStates:W,getFormState:$,setError:e,clearError:l,clearErrors:k,checkValidity:F,getNumberFields:ne,getFieldValidity:te,getDefaultValues:se,setFieldState:p,triggerFieldBlur:I,resetFieldState:Q,getControlledFields:ue,subscribeChange:w,subscribeBlur:V,setFormState:Z,getEvents:a.getEvents,getWatchEvents:a.getWatchEvents}),[X,O,B,j,G,D,W,$,e,l,k,F,ne,te,se,p,Q,I,ue,w,V,Z]),ae=t.useMemo(()=>({ref:g,watch:M,actions:N,registerController:_,registerHookWatcher:Y,lastReloadedAt:h,loadFormValues:x,getWatchValue:H,channels:a}),[g,M,N,_,Y,h,x,H,a]),ve=t.useMemo(()=>({control:ae,actions:N,watch:M}),[h,ae,N,M]);return t.useLayoutEffect(()=>{if([...g.current.querySelectorAll("[name]")].forEach(n=>{!n.defaultValue&&!R.current.has(n.name)&&c.current[n.name]&&(n.defaultValue=c.current[n.name]),n.type==="number"&&!m.current.includes(n.name)&&m.current.push(n.name)}),g.current){const n=x();o.current={...n},c.current={...n}}},[h]),t.useLayoutEffect(()=>{y()},[]),ve};exports.Controller=Fe;exports.Form=pe;exports.useController=ke;exports.useForm=Ve;exports.useFormContext=le;exports.useWatch=Re;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import we, { createContext as Te, useContext as _e, useEffect as de, useState as ie, useRef as V, useCallback as
|
|
2
|
-
var ae = { exports: {} },
|
|
1
|
+
import we, { createContext as Te, useContext as _e, useEffect as de, useState as ie, useRef as V, useCallback as b, useMemo as le, useLayoutEffect as be } from "react";
|
|
2
|
+
var ae = { exports: {} }, ee = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -11,7 +11,7 @@ var ae = { exports: {} }, K = {};
|
|
|
11
11
|
*/
|
|
12
12
|
var he;
|
|
13
13
|
function ke() {
|
|
14
|
-
if (he) return
|
|
14
|
+
if (he) return ee;
|
|
15
15
|
he = 1;
|
|
16
16
|
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
17
17
|
function i(l, h, E) {
|
|
@@ -29,9 +29,9 @@ function ke() {
|
|
|
29
29
|
props: E
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return ee.Fragment = n, ee.jsx = i, ee.jsxs = i, ee;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var re = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -50,17 +50,17 @@ function Ae() {
|
|
|
50
50
|
return e.$$typeof === $ ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
|
-
case
|
|
53
|
+
case F:
|
|
54
54
|
return "Fragment";
|
|
55
55
|
case x:
|
|
56
56
|
return "Profiler";
|
|
57
57
|
case C:
|
|
58
58
|
return "StrictMode";
|
|
59
|
-
case se:
|
|
60
|
-
return "Suspense";
|
|
61
59
|
case ne:
|
|
60
|
+
return "Suspense";
|
|
61
|
+
case oe:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
63
|
+
case H:
|
|
64
64
|
return "Activity";
|
|
65
65
|
}
|
|
66
66
|
if (typeof e == "object")
|
|
@@ -69,14 +69,14 @@ function Ae() {
|
|
|
69
69
|
), e.$$typeof) {
|
|
70
70
|
case o:
|
|
71
71
|
return "Portal";
|
|
72
|
-
case
|
|
72
|
+
case G:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case z:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
76
|
+
case se:
|
|
77
77
|
var a = e.render;
|
|
78
78
|
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
79
|
-
case
|
|
79
|
+
case ue:
|
|
80
80
|
return a = e.displayName || null, a !== null ? a : t(e.type) || "Memo";
|
|
81
81
|
case P:
|
|
82
82
|
a = e._payload, e = e._init;
|
|
@@ -108,7 +108,7 @@ function Ae() {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function l(e) {
|
|
111
|
-
if (e ===
|
|
111
|
+
if (e === F) return "<>";
|
|
112
112
|
if (typeof e == "object" && e !== null && e.$$typeof === P)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
@@ -134,7 +134,7 @@ function Ae() {
|
|
|
134
134
|
}
|
|
135
135
|
function m(e, a) {
|
|
136
136
|
function R() {
|
|
137
|
-
|
|
137
|
+
X || (X = !0, console.error(
|
|
138
138
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
139
139
|
a
|
|
140
140
|
));
|
|
@@ -146,11 +146,11 @@ function Ae() {
|
|
|
146
146
|
}
|
|
147
147
|
function v() {
|
|
148
148
|
var e = t(this.type);
|
|
149
|
-
return
|
|
149
|
+
return Z[e] || (Z[e] = !0, console.error(
|
|
150
150
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
151
151
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function y(e, a, R, T, j, A, I, L) {
|
|
154
154
|
return R = A.ref, e = {
|
|
155
155
|
$$typeof: c,
|
|
156
156
|
type: e,
|
|
@@ -188,19 +188,19 @@ function Ae() {
|
|
|
188
188
|
if (T)
|
|
189
189
|
if (Y(_)) {
|
|
190
190
|
for (T = 0; T < _.length; T++)
|
|
191
|
-
|
|
191
|
+
d(_[T]);
|
|
192
192
|
Object.freeze && Object.freeze(_);
|
|
193
193
|
} else
|
|
194
194
|
console.error(
|
|
195
195
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
196
196
|
);
|
|
197
|
-
else
|
|
197
|
+
else d(_);
|
|
198
198
|
if (M.call(a, "key")) {
|
|
199
199
|
_ = t(e);
|
|
200
|
-
var D = Object.keys(a).filter(function(
|
|
201
|
-
return
|
|
200
|
+
var D = Object.keys(a).filter(function(ce) {
|
|
201
|
+
return ce !== "key";
|
|
202
202
|
});
|
|
203
|
-
T = 0 < D.length ? "{key: someKey, " + D.join(": ..., ") + ": ...}" : "{key: someKey}",
|
|
203
|
+
T = 0 < D.length ? "{key: someKey, " + D.join(": ..., ") + ": ...}" : "{key: someKey}", K[_ + T] || (D = 0 < D.length ? "{" + D.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
204
|
`A props object containing a "key" prop is being spread into JSX:
|
|
205
205
|
let props = %s;
|
|
206
206
|
<%s {...props} />
|
|
@@ -211,7 +211,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
211
211
|
_,
|
|
212
212
|
D,
|
|
213
213
|
_
|
|
214
|
-
),
|
|
214
|
+
), K[_ + T] = !0);
|
|
215
215
|
}
|
|
216
216
|
if (_ = null, R !== void 0 && (i(R), _ = "" + R), g(a) && (i(a.key), _ = "" + a.key), "key" in a) {
|
|
217
217
|
R = {};
|
|
@@ -221,7 +221,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
221
221
|
return _ && m(
|
|
222
222
|
R,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
),
|
|
224
|
+
), y(
|
|
225
225
|
e,
|
|
226
226
|
_,
|
|
227
227
|
A,
|
|
@@ -232,10 +232,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
232
232
|
L
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function d(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === c && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var u = we, c = Symbol.for("react.transitional.element"), o = Symbol.for("react.portal"),
|
|
238
|
+
var u = we, c = Symbol.for("react.transitional.element"), o = Symbol.for("react.portal"), F = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), G = Symbol.for("react.context"), se = Symbol.for("react.forward_ref"), ne = Symbol.for("react.suspense"), oe = Symbol.for("react.suspense_list"), ue = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), $ = Symbol.for("react.client.reference"), W = u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, M = Object.prototype.hasOwnProperty, Y = Array.isArray, B = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
241
|
u = {
|
|
@@ -243,11 +243,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
246
|
+
var X, Z = {}, Q = u["react-stack-bottom-frame"].bind(
|
|
247
247
|
u,
|
|
248
248
|
E
|
|
249
|
-
)(), w = B(l(E)),
|
|
250
|
-
|
|
249
|
+
)(), w = B(l(E)), K = {};
|
|
250
|
+
re.Fragment = F, re.jsx = function(e, a, R, T, j) {
|
|
251
251
|
var A = 1e4 > W.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return f(
|
|
253
253
|
e,
|
|
@@ -256,10 +256,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
256
256
|
!1,
|
|
257
257
|
T,
|
|
258
258
|
j,
|
|
259
|
-
A ? Error("react-stack-top-frame") :
|
|
259
|
+
A ? Error("react-stack-top-frame") : Q,
|
|
260
260
|
A ? B(l(e)) : w
|
|
261
261
|
);
|
|
262
|
-
},
|
|
262
|
+
}, re.jsxs = function(e, a, R, T, j) {
|
|
263
263
|
var A = 1e4 > W.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return f(
|
|
265
265
|
e,
|
|
@@ -268,45 +268,45 @@ React keys must be passed directly to JSX without using spread:
|
|
|
268
268
|
!0,
|
|
269
269
|
T,
|
|
270
270
|
j,
|
|
271
|
-
A ? Error("react-stack-top-frame") :
|
|
271
|
+
A ? Error("react-stack-top-frame") : Q,
|
|
272
272
|
A ? B(l(e)) : w
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
}()),
|
|
275
|
+
}()), re;
|
|
276
276
|
}
|
|
277
277
|
var ge;
|
|
278
278
|
function Oe() {
|
|
279
279
|
return ge || (ge = 1, process.env.NODE_ENV === "production" ? ae.exports = ke() : ae.exports = Ae()), ae.exports;
|
|
280
280
|
}
|
|
281
281
|
var me = Oe();
|
|
282
|
-
const
|
|
282
|
+
const p = () => {
|
|
283
283
|
}, pe = Te({
|
|
284
284
|
ref: null,
|
|
285
|
-
watch:
|
|
285
|
+
watch: p,
|
|
286
286
|
actions: {
|
|
287
|
-
reset:
|
|
288
|
-
resetField:
|
|
289
|
-
setValue:
|
|
290
|
-
getValues:
|
|
291
|
-
getErrors:
|
|
292
|
-
getFieldStates:
|
|
293
|
-
getFormStates:
|
|
294
|
-
setError:
|
|
295
|
-
clearError:
|
|
296
|
-
clearErrors:
|
|
297
|
-
checkValidity:
|
|
298
|
-
getNumberFields:
|
|
299
|
-
getFieldValidity:
|
|
300
|
-
getDefaultValues:
|
|
301
|
-
setFieldState:
|
|
302
|
-
resetFieldState:
|
|
303
|
-
getControlledFields:
|
|
287
|
+
reset: p,
|
|
288
|
+
resetField: p,
|
|
289
|
+
setValue: p,
|
|
290
|
+
getValues: p,
|
|
291
|
+
getErrors: p,
|
|
292
|
+
getFieldStates: p,
|
|
293
|
+
getFormStates: p,
|
|
294
|
+
setError: p,
|
|
295
|
+
clearError: p,
|
|
296
|
+
clearErrors: p,
|
|
297
|
+
checkValidity: p,
|
|
298
|
+
getNumberFields: p,
|
|
299
|
+
getFieldValidity: p,
|
|
300
|
+
getDefaultValues: p,
|
|
301
|
+
setFieldState: p,
|
|
302
|
+
resetFieldState: p,
|
|
303
|
+
getControlledFields: p
|
|
304
304
|
},
|
|
305
|
-
registerController:
|
|
306
|
-
registerHookWatcher:
|
|
307
|
-
lastReloadedAt:
|
|
308
|
-
loadFormValues:
|
|
309
|
-
getWatchValue:
|
|
305
|
+
registerController: p,
|
|
306
|
+
registerHookWatcher: p,
|
|
307
|
+
lastReloadedAt: p,
|
|
308
|
+
loadFormValues: p,
|
|
309
|
+
getWatchValue: p,
|
|
310
310
|
channels: {}
|
|
311
311
|
}), ye = () => _e(pe), Le = ({
|
|
312
312
|
id: t,
|
|
@@ -322,10 +322,10 @@ const S = () => {
|
|
|
322
322
|
},
|
|
323
323
|
onBlur: v = () => {
|
|
324
324
|
},
|
|
325
|
-
onReset:
|
|
325
|
+
onReset: y = () => {
|
|
326
326
|
},
|
|
327
327
|
numberFields: f = [],
|
|
328
|
-
className:
|
|
328
|
+
className: d,
|
|
329
329
|
...u
|
|
330
330
|
}) => (de(() => {
|
|
331
331
|
const c = n.channels.subscribe("onChange", m), o = n.channels.subscribe("onBlur", v);
|
|
@@ -339,7 +339,7 @@ const S = () => {
|
|
|
339
339
|
ref: n.ref,
|
|
340
340
|
action: l,
|
|
341
341
|
method: i,
|
|
342
|
-
className:
|
|
342
|
+
className: d,
|
|
343
343
|
onInput: g,
|
|
344
344
|
onSubmit: (c) => {
|
|
345
345
|
i || c.preventDefault();
|
|
@@ -353,11 +353,11 @@ const S = () => {
|
|
|
353
353
|
onBlur: (c) => {
|
|
354
354
|
const o = c.target.name;
|
|
355
355
|
if (!o || n.actions.getControlledFields().has(o)) return;
|
|
356
|
-
const
|
|
357
|
-
n.channels.publish("onBlur", o,
|
|
356
|
+
const F = c.target.value;
|
|
357
|
+
n.channels.publish("onBlur", o, F, n.actions.getValues());
|
|
358
358
|
},
|
|
359
359
|
onReset: (c) => {
|
|
360
|
-
n.actions.reset(),
|
|
360
|
+
n.actions.reset(), y(c);
|
|
361
361
|
},
|
|
362
362
|
...u,
|
|
363
363
|
children: h
|
|
@@ -367,35 +367,35 @@ const S = () => {
|
|
|
367
367
|
const { getWatchValue: l, registerHookWatcher: h } = t || ye(), E = l({ name: n, compute: i }), [g, m] = ie(E);
|
|
368
368
|
return de(() => {
|
|
369
369
|
const v = h({ name: n, compute: i, value: g, setValue: m });
|
|
370
|
-
return () => v.forEach((
|
|
370
|
+
return () => v.forEach((y) => y());
|
|
371
371
|
}, []), g;
|
|
372
372
|
}, Pe = ({ name: t, defaultValue: n }) => {
|
|
373
|
-
const { actions: i, registerController: l, channels: h } = ye(), E = V(), g = i.getDefaultValues()[t] || n || "", [m, v] = ie(g),
|
|
373
|
+
const { actions: i, registerController: l, channels: h } = ye(), E = V(), g = i.getDefaultValues()[t] || n || "", [m, v] = ie(g), y = Ce({ name: `fieldStates.${t}` }), f = b(
|
|
374
374
|
(u, { shouldDirty: c = !0, shouldOnChange: o = !0 } = {}) => {
|
|
375
375
|
var C, x;
|
|
376
|
-
let
|
|
377
|
-
(C = u == null ? void 0 : u.target) != null && C.value && (
|
|
376
|
+
let F = u;
|
|
377
|
+
(C = u == null ? void 0 : u.target) != null && C.value && (F = u.target.value), (x = u == null ? void 0 : u.target) != null && x.checked && (F = u.target.checked + ""), v(F), i.setValue(t, F, { shouldDirty: c, shouldOnChange: o });
|
|
378
378
|
},
|
|
379
379
|
[i.setValue]
|
|
380
|
-
),
|
|
380
|
+
), d = b((u) => {
|
|
381
381
|
const c = i.getValues(), o = u ?? c[t];
|
|
382
382
|
h.publish("onBlur", t, o, c);
|
|
383
383
|
}, []);
|
|
384
|
-
return de(() => l(t, v), []), { ref: E, name: t, defaultValue: g, value: m, onChange: f, onBlur:
|
|
384
|
+
return de(() => l(t, v), []), { ref: E, name: t, defaultValue: g, value: m, onChange: f, onBlur: d, fieldState: y };
|
|
385
385
|
}, Ue = ({
|
|
386
386
|
name: t,
|
|
387
387
|
defaultValue: n,
|
|
388
|
-
render: i = ({ ref: l, name: h, defaultValue: E, value: g, onChange: m, onBlur: v, fieldState:
|
|
388
|
+
render: i = ({ ref: l, name: h, defaultValue: E, value: g, onChange: m, onBlur: v, fieldState: y }) => null
|
|
389
389
|
}) => {
|
|
390
390
|
const l = Pe({ name: t, defaultValue: n });
|
|
391
391
|
return i(l);
|
|
392
|
-
}, je = ["errors", "fieldStates", "formState"],
|
|
392
|
+
}, je = ["errors", "fieldStates", "formState"], te = (t = {}, n = "") => n.split(".").reduce((i, l) => i && i[l] !== void 0 ? i[l] : void 0, t), ve = (t = {}, n = "", i) => {
|
|
393
393
|
let l = t;
|
|
394
394
|
const h = n.split(".");
|
|
395
395
|
return h.forEach((E, g) => {
|
|
396
396
|
g < h.length - 1 && (l[E] || (l[E] = {}), g === h.length - 2 && (l[E] = { ...l[E] }), l = l[E]), l[E] = i;
|
|
397
397
|
}), t;
|
|
398
|
-
},
|
|
398
|
+
}, J = (t) => je.some((n) => t.startsWith(n)) ? t : "values." + t, xe = [
|
|
399
399
|
"badInput",
|
|
400
400
|
"customError",
|
|
401
401
|
"patternMismatch",
|
|
@@ -442,30 +442,30 @@ class Ne {
|
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
const Ve = () => {
|
|
445
|
-
const t = V(new Ne()), n =
|
|
445
|
+
const t = V(new Ne()), n = b((m, ...v) => {
|
|
446
446
|
t.current.publish(m, ...v);
|
|
447
|
-
}, []), i =
|
|
447
|
+
}, []), i = b((m, v) => t.current.subscribe(m, v), []), l = b((m, v) => {
|
|
448
448
|
t.current.subscribeWatch(m, v);
|
|
449
|
-
}, []), h =
|
|
449
|
+
}, []), h = b(() => t.current.getEvents(), []), E = b(() => t.current.getWatchEvents(), []), g = b(() => {
|
|
450
450
|
t.current.reset();
|
|
451
451
|
}, []);
|
|
452
452
|
return { publish: n, subscribe: i, reset: g, getEvents: h, subscribeWatch: l, getWatchEvents: E };
|
|
453
453
|
}, De = () => {
|
|
454
|
-
const [t, n] = ie(), i =
|
|
454
|
+
const [t, n] = ie(), i = b(() => n((/* @__PURE__ */ new Date()).toString()), []);
|
|
455
455
|
return [t, i];
|
|
456
456
|
}, We = () => {
|
|
457
457
|
const [, t] = ie({});
|
|
458
|
-
return
|
|
458
|
+
return b(() => t({}), []);
|
|
459
459
|
}, $e = ({ channels: t, getValues: n, getErrors: i, getFieldStates: l, getFormState: h }) => {
|
|
460
|
-
const E = We(), g =
|
|
461
|
-
if (typeof
|
|
460
|
+
const E = We(), g = b(({ name: f, compute: d }) => {
|
|
461
|
+
if (typeof d == "function") return d(n());
|
|
462
462
|
if (Array.isArray(f)) {
|
|
463
463
|
const u = {};
|
|
464
464
|
return f.forEach((c) => {
|
|
465
465
|
u[c] = g({ name: c });
|
|
466
466
|
}), u;
|
|
467
467
|
}
|
|
468
|
-
return
|
|
468
|
+
return te(
|
|
469
469
|
{
|
|
470
470
|
...n(),
|
|
471
471
|
errors: { ...i() },
|
|
@@ -474,25 +474,25 @@ const Ve = () => {
|
|
|
474
474
|
},
|
|
475
475
|
f
|
|
476
476
|
);
|
|
477
|
-
}, []), m =
|
|
477
|
+
}, []), m = b((f) => {
|
|
478
478
|
if (!f)
|
|
479
479
|
return t.subscribeWatch("values", () => E()), n();
|
|
480
480
|
if (typeof f == "string") {
|
|
481
|
-
const
|
|
482
|
-
return t.subscribeWatch(
|
|
481
|
+
const d = J(f);
|
|
482
|
+
return t.subscribeWatch(d, () => E()), g({ name: f });
|
|
483
483
|
}
|
|
484
484
|
if (Array.isArray(f)) {
|
|
485
|
-
const
|
|
485
|
+
const d = {};
|
|
486
486
|
return f.forEach((u) => {
|
|
487
|
-
const c =
|
|
488
|
-
t.subscribeWatch(c, () => E()),
|
|
489
|
-
}), { ...
|
|
487
|
+
const c = J(u);
|
|
488
|
+
t.subscribeWatch(c, () => E()), d[u] = g({ name: u });
|
|
489
|
+
}), { ...d };
|
|
490
490
|
}
|
|
491
491
|
throw new Error("Parameters of watch must be string or array of string");
|
|
492
|
-
}, []), v =
|
|
493
|
-
if (typeof
|
|
492
|
+
}, []), v = b(({ name: f, compute: d, setValue: u }) => {
|
|
493
|
+
if (typeof d == "function")
|
|
494
494
|
return [t.subscribe("values", () => {
|
|
495
|
-
const o = g({ compute:
|
|
495
|
+
const o = g({ compute: d });
|
|
496
496
|
u(o);
|
|
497
497
|
})];
|
|
498
498
|
if (!f)
|
|
@@ -500,36 +500,36 @@ const Ve = () => {
|
|
|
500
500
|
u(n());
|
|
501
501
|
})];
|
|
502
502
|
if (typeof f == "string") {
|
|
503
|
-
const c =
|
|
503
|
+
const c = J(f);
|
|
504
504
|
return [t.subscribe(c, () => {
|
|
505
|
-
const
|
|
506
|
-
u(
|
|
505
|
+
const F = g({ name: f });
|
|
506
|
+
u(F);
|
|
507
507
|
})];
|
|
508
508
|
}
|
|
509
509
|
if (Array.isArray(f)) {
|
|
510
510
|
const c = g({ name: f }), o = [];
|
|
511
|
-
return f.forEach((
|
|
512
|
-
const C =
|
|
513
|
-
const
|
|
514
|
-
c[
|
|
511
|
+
return f.forEach((F) => {
|
|
512
|
+
const C = J(F), x = t.subscribe(C, () => {
|
|
513
|
+
const z = g({ name: F });
|
|
514
|
+
c[F] = z, u({ ...c });
|
|
515
515
|
});
|
|
516
516
|
o.push(x);
|
|
517
517
|
}), o;
|
|
518
518
|
}
|
|
519
519
|
throw new Error("Parameters of name must be string or array of string or compute must be a function");
|
|
520
|
-
}, []),
|
|
521
|
-
(f,
|
|
520
|
+
}, []), y = b(
|
|
521
|
+
(f, d) => {
|
|
522
522
|
if (!f)
|
|
523
|
-
return t.subscribe("values",
|
|
523
|
+
return t.subscribe("values", d);
|
|
524
524
|
if (typeof f == "string") {
|
|
525
|
-
const u =
|
|
526
|
-
return t.subscribe(u,
|
|
525
|
+
const u = J(f);
|
|
526
|
+
return t.subscribe(u, d);
|
|
527
527
|
}
|
|
528
528
|
if (Array.isArray(f)) {
|
|
529
529
|
const u = {}, c = [];
|
|
530
530
|
return f.forEach((o) => {
|
|
531
|
-
const
|
|
532
|
-
u[o] = g({ name: o }),
|
|
531
|
+
const F = J(o), C = t.subscribe(F, () => {
|
|
532
|
+
u[o] = g({ name: o }), d({ ...u });
|
|
533
533
|
});
|
|
534
534
|
c.push(C);
|
|
535
535
|
}), c;
|
|
@@ -538,7 +538,7 @@ const Ve = () => {
|
|
|
538
538
|
},
|
|
539
539
|
[t]
|
|
540
540
|
);
|
|
541
|
-
return { watch: m, registerHookWatcher: v, getWatchValue: g, subscribe:
|
|
541
|
+
return { watch: m, registerHookWatcher: v, getWatchValue: g, subscribe: y };
|
|
542
542
|
}, Se = {
|
|
543
543
|
lastReset: null,
|
|
544
544
|
isDirty: !1,
|
|
@@ -552,103 +552,109 @@ const Ve = () => {
|
|
|
552
552
|
shouldUnRegister: i = !1,
|
|
553
553
|
shouldConvertNumber: l = !1
|
|
554
554
|
} = {}) => {
|
|
555
|
-
const [h, E] = De(), g = V(), m = V(t), v = V(/* @__PURE__ */ new Map()),
|
|
556
|
-
f.current = Object.keys(c.current).reduce((
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
555
|
+
const [h, E] = De(), g = V(), m = V(t), v = V(/* @__PURE__ */ new Map()), y = V({}), f = V({}), d = V({ ...Se }), u = V({ ...n }), c = V({ ...n }), o = Ve(), F = b((r) => {
|
|
556
|
+
f.current = Object.keys(c.current).reduce((s, S) => ({
|
|
557
|
+
...s,
|
|
558
|
+
[S]: { ...r ? {} : f.current[S] || {}, ...fe }
|
|
559
|
+
}), {});
|
|
560
|
+
}, []), C = b(
|
|
561
|
+
(r = {}, { clearCustomFormStates: s = !1, clearCustomFieldStates: S = !1 } = {}) => {
|
|
562
|
+
c.current = { ...c.current, ...r }, u.current = { ...c.current }, v.current.forEach((k, U) => {
|
|
563
|
+
k(c.current[U]);
|
|
564
|
+
}), y.current = {}, d.current = { ...s ? {} : d.current, ...Se }, m.current = t, v.current = /* @__PURE__ */ new Map(), o.reset(), F(S), t.length > 0 && (l = !0), E();
|
|
565
|
+
},
|
|
566
|
+
[]
|
|
567
|
+
), x = b(() => {
|
|
562
568
|
const r = Object.fromEntries(new FormData(g.current));
|
|
563
|
-
return v.current.forEach((
|
|
569
|
+
return v.current.forEach((S, k) => {
|
|
564
570
|
r[k] = u.current[k];
|
|
565
571
|
}), l && m.current.forEach(
|
|
566
|
-
(
|
|
572
|
+
(S) => r.hasOwnProperty(S) && (r[S] = Number(r[S]) || 0)
|
|
567
573
|
), { ...u.current, ...r };
|
|
568
|
-
}, []),
|
|
569
|
-
(r) => P({ ...
|
|
574
|
+
}, []), z = b(() => !!Object.values(W()).find((r) => r.isDirty), []), G = b(() => !!Object.values($()).find((r) => !!r), []), se = b((r) => Re(r.target), []), ne = b(() => c.current, []), oe = b(() => m.current, []), ue = b(() => v.current, []), P = b((r, s) => s ? Array.isArray(s) ? s.reduce((S, k) => ({ ...S, [k]: te(r, k) }), {}) : te(r, s) : { ...r }, []), H = b((r) => P(u.current, r), [P]), $ = b((r) => P(y.current, r), [P]), W = b((r) => P(f.current, r), [P]), M = b(
|
|
575
|
+
(r) => P({ ...d.current, lastReset: h }, r),
|
|
570
576
|
[P, h]
|
|
571
|
-
), { watch: Y, registerHookWatcher: B, getWatchValue:
|
|
577
|
+
), { watch: Y, registerHookWatcher: B, getWatchValue: X, subscribe: Z } = $e({
|
|
572
578
|
channels: o,
|
|
573
|
-
getValues:
|
|
579
|
+
getValues: H,
|
|
574
580
|
getErrors: $,
|
|
575
581
|
getFieldStates: W,
|
|
576
582
|
getFormState: M
|
|
577
|
-
}),
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
}, []), w =
|
|
583
|
+
}), Q = b((r, s) => {
|
|
584
|
+
const S = d.current;
|
|
585
|
+
te(S, r) !== s && (ve(d.current, r, s), o.publish(`formState.${r}`, s));
|
|
586
|
+
}, []), w = b((r, s, S) => {
|
|
581
587
|
const k = f.current[r] || { ...fe };
|
|
582
|
-
|
|
583
|
-
(O) => !!
|
|
584
|
-
), o.publish("formState.errorFields",
|
|
588
|
+
te(k, s) !== S && (ve(f.current, `${r}.${s}`, S), o.publish(`fieldStates.${r}.${s}`, S), s === "error" && (d.current.errorFields = Object.keys(y.current).filter(
|
|
589
|
+
(O) => !!y.current[O]
|
|
590
|
+
), o.publish("formState.errorFields", d.current.errorFields)), s === "isDirty" && (d.current.dirtyFields = Object.keys(f.current).filter(
|
|
585
591
|
(O) => f.current[O].isDirty
|
|
586
|
-
), o.publish("formState.dirtyFields",
|
|
592
|
+
), o.publish("formState.dirtyFields", d.current.dirtyFields)), s === "isTouched" && (d.current.touchedFields = Object.keys(f.current).filter(
|
|
587
593
|
(O) => f.current[O].isTouched
|
|
588
|
-
), o.publish("formState.touchedFields",
|
|
589
|
-
}, []),
|
|
594
|
+
), o.publish("formState.touchedFields", d.current.touchedFields)));
|
|
595
|
+
}, []), K = b(
|
|
590
596
|
(r) => {
|
|
591
597
|
w(r, "isDirty", !1), w(r, "isTouched", !1), w(r, "error", null);
|
|
592
598
|
},
|
|
593
599
|
[w]
|
|
594
|
-
), e =
|
|
600
|
+
), e = b(
|
|
595
601
|
(r, s) => {
|
|
596
|
-
if (
|
|
597
|
-
|
|
598
|
-
const k =
|
|
599
|
-
|
|
602
|
+
if (y.current[r] === s) return;
|
|
603
|
+
y.current[r] = s, w(r, "error", s), o.publish(`errors.${r}`, s);
|
|
604
|
+
const k = G();
|
|
605
|
+
d.current.isError !== k && (d.current.isError = k, o.publish("formState.isError", k));
|
|
600
606
|
},
|
|
601
607
|
[w]
|
|
602
|
-
), a =
|
|
608
|
+
), a = b(
|
|
603
609
|
(r) => {
|
|
604
|
-
if (!
|
|
605
|
-
|
|
606
|
-
const s =
|
|
607
|
-
|
|
610
|
+
if (!y.current[r]) return;
|
|
611
|
+
y.current[r] = null, w(r, "error", null), o.publish(`errors.${r}`, null);
|
|
612
|
+
const s = G();
|
|
613
|
+
d.current.isError !== s && (d.current.isError = s, o.publish("formState.isError", s));
|
|
608
614
|
},
|
|
609
615
|
[w]
|
|
610
|
-
), R =
|
|
611
|
-
if (Object.keys(
|
|
612
|
-
Object.keys(
|
|
613
|
-
const r =
|
|
614
|
-
|
|
615
|
-
}, []), T =
|
|
616
|
+
), R = b(() => {
|
|
617
|
+
if (Object.keys(y.current) === 0) return;
|
|
618
|
+
Object.keys(y.current).forEach((s) => a(s)), y.current = {};
|
|
619
|
+
const r = G();
|
|
620
|
+
d.current.isError !== r && (d.current.isError = r, o.publish("formState.isError", r));
|
|
621
|
+
}, []), T = b(
|
|
616
622
|
(r) => {
|
|
617
623
|
const s = Re(r.target);
|
|
618
624
|
s ? e(r.target.name, s) : a(r.target.name);
|
|
619
625
|
},
|
|
620
626
|
[e, a]
|
|
621
|
-
), j =
|
|
622
|
-
(r, s, { shouldDirty:
|
|
627
|
+
), j = b(
|
|
628
|
+
(r, s, { shouldDirty: S = !0, shouldOnChange: k = !0 } = {}) => {
|
|
623
629
|
if (s === u.current[r]) return;
|
|
624
630
|
l && m.current.includes(r) && (s = Number(s) || void 0), w(r, "isTouched", !0);
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
const O =
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
+
const U = s !== c.current[r];
|
|
632
|
+
S && f.current[r].isDirty !== U && w(r, "isDirty", U);
|
|
633
|
+
const O = z();
|
|
634
|
+
d.current.isDirty !== O && (d.current.isDirty = O, o.publish("formState.isDirty", O)), u.current[r] = s;
|
|
635
|
+
const q = v.current.get(r);
|
|
636
|
+
q && q(s), o.publish(`values.${r}`, s, { shouldDirty: S, shouldOnChange: k }), k && o.publish("onChange", r, s, u.current);
|
|
631
637
|
},
|
|
632
638
|
[w]
|
|
633
|
-
), A =
|
|
639
|
+
), A = b((r, s) => (v.current.set(r, s), f.current[r] = { ...fe }, () => {
|
|
634
640
|
i && v.current.delete(r);
|
|
635
|
-
}), []), I =
|
|
636
|
-
(r, { keepError: s, keepDirty:
|
|
637
|
-
const
|
|
638
|
-
if (!
|
|
641
|
+
}), []), I = b(
|
|
642
|
+
(r, { keepError: s, keepDirty: S, keepTouched: k, keepCustomState: U, defaultValue: O }) => {
|
|
643
|
+
const q = v.current.get(r);
|
|
644
|
+
if (!q)
|
|
639
645
|
throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);
|
|
640
|
-
c.current[r] = O, u.current[r] = O,
|
|
646
|
+
c.current[r] = O, u.current[r] = O, q && q(O), s || a(r), S || w(r, "isDirty", !1), k || w(r, "isTouched", !1);
|
|
641
647
|
},
|
|
642
648
|
[a, w]
|
|
643
|
-
), L =
|
|
649
|
+
), L = b((r, s = N.getValues(r)) => {
|
|
644
650
|
o.publish("onBlur", r, s, N.getValues());
|
|
645
|
-
}, []), _ =
|
|
651
|
+
}, []), _ = b((r) => o.subscribe("onChange", r), []), D = b((r) => o.subscribe("onBlur", r), []), N = le(
|
|
646
652
|
() => ({
|
|
647
|
-
subscribe:
|
|
653
|
+
subscribe: Z,
|
|
648
654
|
reset: C,
|
|
649
655
|
resetField: I,
|
|
650
656
|
setValue: j,
|
|
651
|
-
getValues:
|
|
657
|
+
getValues: H,
|
|
652
658
|
getErrors: $,
|
|
653
659
|
getFieldStates: W,
|
|
654
660
|
getFormState: M,
|
|
@@ -656,25 +662,25 @@ const Ve = () => {
|
|
|
656
662
|
clearError: a,
|
|
657
663
|
clearErrors: R,
|
|
658
664
|
checkValidity: T,
|
|
659
|
-
getNumberFields:
|
|
660
|
-
getFieldValidity:
|
|
661
|
-
getDefaultValues:
|
|
665
|
+
getNumberFields: oe,
|
|
666
|
+
getFieldValidity: se,
|
|
667
|
+
getDefaultValues: ne,
|
|
662
668
|
setFieldState: w,
|
|
663
669
|
triggerFieldBlur: L,
|
|
664
|
-
resetFieldState:
|
|
665
|
-
getControlledFields:
|
|
670
|
+
resetFieldState: K,
|
|
671
|
+
getControlledFields: ue,
|
|
666
672
|
subscribeChange: _,
|
|
667
673
|
subscribeBlur: D,
|
|
668
|
-
setFormState:
|
|
674
|
+
setFormState: Q,
|
|
669
675
|
getEvents: o.getEvents,
|
|
670
676
|
getWatchEvents: o.getWatchEvents
|
|
671
677
|
}),
|
|
672
678
|
[
|
|
673
|
-
|
|
679
|
+
Z,
|
|
674
680
|
C,
|
|
675
681
|
I,
|
|
676
682
|
j,
|
|
677
|
-
|
|
683
|
+
H,
|
|
678
684
|
$,
|
|
679
685
|
W,
|
|
680
686
|
M,
|
|
@@ -682,18 +688,18 @@ const Ve = () => {
|
|
|
682
688
|
a,
|
|
683
689
|
R,
|
|
684
690
|
T,
|
|
685
|
-
|
|
686
|
-
te,
|
|
691
|
+
oe,
|
|
687
692
|
se,
|
|
693
|
+
ne,
|
|
688
694
|
w,
|
|
689
|
-
|
|
695
|
+
K,
|
|
690
696
|
L,
|
|
691
|
-
|
|
697
|
+
ue,
|
|
692
698
|
_,
|
|
693
699
|
D,
|
|
694
|
-
|
|
700
|
+
Q
|
|
695
701
|
]
|
|
696
|
-
),
|
|
702
|
+
), ce = le(
|
|
697
703
|
() => ({
|
|
698
704
|
ref: g,
|
|
699
705
|
watch: Y,
|
|
@@ -702,7 +708,7 @@ const Ve = () => {
|
|
|
702
708
|
registerHookWatcher: B,
|
|
703
709
|
lastReloadedAt: h,
|
|
704
710
|
loadFormValues: x,
|
|
705
|
-
getWatchValue:
|
|
711
|
+
getWatchValue: X,
|
|
706
712
|
channels: o
|
|
707
713
|
}),
|
|
708
714
|
[
|
|
@@ -713,10 +719,10 @@ const Ve = () => {
|
|
|
713
719
|
B,
|
|
714
720
|
h,
|
|
715
721
|
x,
|
|
716
|
-
|
|
722
|
+
X,
|
|
717
723
|
o
|
|
718
724
|
]
|
|
719
|
-
), Fe = le(() => ({ control:
|
|
725
|
+
), Fe = le(() => ({ control: ce, actions: N, watch: Y }), [h, ce, N, Y]);
|
|
720
726
|
return be(() => {
|
|
721
727
|
if ([...g.current.querySelectorAll("[name]")].forEach((s) => {
|
|
722
728
|
!s.defaultValue && !v.current.has(s.name) && c.current[s.name] && (s.defaultValue = c.current[s.name]), s.type === "number" && !m.current.includes(s.name) && m.current.push(s.name);
|
|
@@ -725,7 +731,7 @@ const Ve = () => {
|
|
|
725
731
|
u.current = { ...s }, c.current = { ...s };
|
|
726
732
|
}
|
|
727
733
|
}, [h]), be(() => {
|
|
728
|
-
|
|
734
|
+
F();
|
|
729
735
|
}, []), Fe;
|
|
730
736
|
};
|
|
731
737
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(O,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(O=typeof globalThis<"u"?globalThis:O||self,r(O.Name={},O.React))})(this,function(O,r){"use strict";var
|
|
1
|
+
(function(O,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(O=typeof globalThis<"u"?globalThis:O||self,r(O.Name={},O.React))})(this,function(O,r){"use strict";var se={exports:{}},H={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var fe;function Se(){if(fe)return
|
|
9
|
+
*/var fe;function Se(){if(fe)return H;fe=1;var s=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function i(f,h,E){var m=null;if(E!==void 0&&(m=""+E),h.key!==void 0&&(m=""+h.key),"key"in h){E={};for(var g in h)g!=="key"&&(E[g]=h[g])}else E=h;return h=E.ref,{$$typeof:s,type:f,key:m,ref:h!==void 0?h:null,props:E}}return H.Fragment=a,H.jsx=i,H.jsxs=i,H}var X={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var de;function Ce(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Y?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case
|
|
17
|
+
*/var de;function Ce(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){function s(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Y?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case V:return"Profiler";case P:return"StrictMode";case ae:return"Suspense";case oe:return"SuspenseList";case q:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case o:return"Portal";case K:return(e.displayName||"Context")+".Provider";case Q:return(e._context.displayName||"Context")+".Consumer";case ne:var l=e.render;return e=e.displayName,e||(e=l.displayName||l.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ce:return l=e.displayName||null,l!==null?l:s(e.type)||"Memo";case j:l=e._payload,e=e._init;try{return s(e(l))}catch{}}return null}function a(e){return""+e}function i(e){try{a(e);var l=!1}catch{l=!0}if(l){l=console;var k=l.error,F=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return k.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",F),a(e)}}function f(e){if(e===y)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===j)return"<...>";try{var l=s(e);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function h(){var e=D.A;return e===null?null:e.getOwner()}function E(){return Error("react-stack-top-frame")}function m(e){if(B.call(e,"key")){var l=Object.getOwnPropertyDescriptor(e,"key").get;if(l&&l.isReactWarning)return!1}return e.key!==void 0}function g(e,l){function k(){$||($=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}k.isReactWarning=!0,Object.defineProperty(e,"key",{get:k,configurable:!0})}function R(){var e=s(this.type);return ee[e]||(ee[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function C(e,l,k,F,N,_,U,J){return k=_.ref,e={$$typeof:u,type:e,key:l,props:_,_owner:N},(k!==void 0?k:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,l,k,F,N,_,U,J){var T=l.children;if(T!==void 0)if(F)if(I(T)){for(F=0;F<T.length;F++)b(T[F]);Object.freeze&&Object.freeze(T)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else b(T);if(B.call(l,"key")){T=s(e);var W=Object.keys(l).filter(function(ue){return ue!=="key"});F=0<W.length?"{key: someKey, "+W.join(": ..., ")+": ...}":"{key: someKey}",re[T+F]||(W=0<W.length?"{"+W.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,F,T,W,T),te[T+F]=!0)}if(T=null,k!==void 0&&(i(k),T=""+k),m(l)&&(i(l.key),T=""+l.key),"key"in l){k={};for(var x in l)x!=="key"&&(k[x]=l[x])}else k=l;return T&&g(k,typeof e=="function"?e.displayName||e.name||"Unknown":e),S(e,T,_,N,h(),k,U,J)}function b(e){typeof e=="object"&&e!==null&&e.$$typeof===u&&e._store&&(e._store.validated=1)}var c=r,u=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),Z=Symbol.for("react.consumer"),Q=Symbol.for("react.context"),se=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),ae=Symbol.for("react.suspense_list"),oe=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),K=Symbol.for("react.activity"),Y=Symbol.for("react.client.reference"),D=c.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=Object.prototype.hasOwnProperty,I=Array.isArray,L=console.createTask?console.createTask:function(){return null};c={"react-stack-bottom-frame":function(e){return e()}};var q,$={},ee=c["react-stack-bottom-frame"].bind(c,E)(),p=L(f(E)),te={};H.Fragment=C,H.jsx=function(e,l,k,F,N){var _=1e4>D.recentlyCreatedOwnerStacks++;return d(e,l,k,!1,F,N,_?Error("react-stack-top-frame"):ee,_?L(f(e)):p)},H.jsxs=function(e,l,k,F,N){var _=1e4>D.recentlyCreatedOwnerStacks++;return d(e,l,k,!0,F,N,_?Error("react-stack-top-frame"):ee,_?L(f(e)):p)}}()),H}var be;function ye(){return be||(be=1,process.env.NODE_ENV==="production"?re.exports=Se():re.exports=Ce()),re.exports}var he=ye();const v=()=>{},Ee=r.createContext({ref:null,watch:v,actions:{reset:v,resetField:v,setValue:v,getValues:v,getErrors:v,getFieldStates:v,getFormStates:v,setError:v,clearError:v,clearErrors:v,checkValidity:v,getNumberFields:v,getFieldValidity:v,getDefaultValues:v,setFieldState:v,resetFieldState:v,getControlledFields:v},registerController:v,registerHookWatcher:v,lastReloadedAt:v,loadFormValues:v,getWatchValue:v,channels:{}}),le=()=>r.useContext(Ee),pe=({id:s,control:a,method:i,action:f,children:h,onSubmit:E=()=>{},onInput:m=()=>{},onChange:g=()=>{},onBlur:R=()=>{},onReset:S=()=>{},numberFields:d=[],className:b,...c})=>(r.useEffect(()=>{const u=a.channels.subscribe("onChange",g),o=a.channels.subscribe("onBlur",R);return()=>{u(),o()}},[a.lastReloadedAt]),he.jsx(Ee.Provider,{value:a,children:he.jsx("form",{id:s,ref:a.ref,action:f,method:i,className:b,onInput:m,onSubmit:u=>{i||u.preventDefault();const o=a.loadFormValues();E(o)},onChange:u=>{const o=u.target.name;!o||a.actions.getControlledFields().has(o)||a.actions.setValue(o,u.target.value)},onBlur:u=>{const o=u.target.name;if(!o||a.actions.getControlledFields().has(o))return;const C=u.target.value;a.channels.publish("onBlur",o,C,a.actions.getValues())},onReset:u=>{a.actions.reset(),S(u)},...c,children:h},a.lastReloadedAt)})),me=({control:s,name:a,compute:i})=>{const{getWatchValue:f,registerHookWatcher:h}=s||le(),E=f({name:a,compute:i}),[m,g]=r.useState(E);return r.useEffect(()=>{const R=h({name:a,compute:i,value:m,setValue:g});return()=>R.forEach(S=>S())},[]),m},ge=({name:s,defaultValue:a})=>{const{actions:i,registerController:f,channels:h}=le(),E=r.useRef(),m=i.getDefaultValues()[s]||a||"",[g,R]=r.useState(m),S=me({name:`fieldStates.${s}`}),d=r.useCallback((c,{shouldDirty:u=!0,shouldOnChange:o=!0}={})=>{var P,V;let C=c;(P=c==null?void 0:c.target)!=null&&P.value&&(C=c.target.value),(V=c==null?void 0:c.target)!=null&&V.checked&&(C=c.target.checked+""),R(C),i.setValue(s,C,{shouldDirty:u,shouldOnChange:o})},[i.setValue]),b=r.useCallback(c=>{const u=i.getValues(),o=c??u[s];h.publish("onBlur",s,o,u)},[]);return r.useEffect(()=>f(s,R),[]),{ref:E,name:s,defaultValue:m,value:g,onChange:d,onBlur:b,fieldState:S}},Fe=({name:s,defaultValue:a,render:i=({ref:f,name:h,defaultValue:E,value:m,onChange:g,onBlur:R,fieldState:S})=>null})=>{const f=ge({name:s,defaultValue:a});return i(f)},Te=["errors","fieldStates","formState"],X=(s={},a="")=>a.split(".").reduce((i,f)=>i&&i[f]!==void 0?i[f]:void 0,s),Re=(s={},a="",i)=>{let f=s;const h=a.split(".");return h.forEach((E,m)=>{m<h.length-1&&(f[E]||(f[E]={}),m===h.length-2&&(f[E]={...f[E]}),f=f[E]),f[E]=i}),s},M=s=>Te.some(a=>s.startsWith(a))?s:"values."+s,we=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],ke=s=>{typeof s.setCustomValidity=="function"&&s.setCustomValidity("");let a=s.validity,i=we.find(f=>a[f]);if(i)return{type:i,message:s.validationMessage}};class _e{constructor(){this.events=new Map,this.watchEvents=new Map}getWatchEvents(){return this.watchEvents}getEvents(){return this.events}subscribe(a,i){return this.events.has(a)||this.events.set(a,new Set),this.events.get(a).add(i),()=>{var f;return(f=this.events.get(a))==null?void 0:f.delete(i)}}subscribeWatch(a,i){this.watchEvents.has(a)||(this.watchEvents.set(a,new Set),this.watchEvents.get(a).add(i))}publish(a,...i){this.events.forEach((f,h)=>{a.includes(h)&&f.forEach(E=>E(...i))}),this.watchEvents.forEach((f,h)=>{a.includes(h)&&f.forEach(E=>E(...i))})}reset(){this.events.clear(),this.watchEvents.clear()}}const Ae=()=>{const s=r.useRef(new _e),a=r.useCallback((g,...R)=>{s.current.publish(g,...R)},[]),i=r.useCallback((g,R)=>s.current.subscribe(g,R),[]),f=r.useCallback((g,R)=>{s.current.subscribeWatch(g,R)},[]),h=r.useCallback(()=>s.current.getEvents(),[]),E=r.useCallback(()=>s.current.getWatchEvents(),[]),m=r.useCallback(()=>{s.current.reset()},[]);return{publish:a,subscribe:i,reset:m,getEvents:h,subscribeWatch:f,getWatchEvents:E}},Oe=()=>{const[s,a]=r.useState(),i=r.useCallback(()=>a(new Date().toString()),[]);return[s,i]},Pe=()=>{const[,s]=r.useState({});return r.useCallback(()=>s({}),[])},je=({channels:s,getValues:a,getErrors:i,getFieldStates:f,getFormState:h})=>{const E=Pe(),m=r.useCallback(({name:d,compute:b})=>{if(typeof b=="function")return b(a());if(Array.isArray(d)){const c={};return d.forEach(u=>{c[u]=m({name:u})}),c}return X({...a(),errors:{...i()},formState:{...h()},fieldStates:{...f()}},d)},[]),g=r.useCallback(d=>{if(!d)return s.subscribeWatch("values",()=>E()),a();if(typeof d=="string"){const b=M(d);return s.subscribeWatch(b,()=>E()),m({name:d})}if(Array.isArray(d)){const b={};return d.forEach(c=>{const u=M(c);s.subscribeWatch(u,()=>E()),b[c]=m({name:c})}),{...b}}throw new Error("Parameters of watch must be string or array of string")},[]),R=r.useCallback(({name:d,compute:b,setValue:c})=>{if(typeof b=="function")return[s.subscribe("values",()=>{const o=m({compute:b});c(o)})];if(!d)return[s.subscribe("values",()=>{c(a())})];if(typeof d=="string"){const u=M(d);return[s.subscribe(u,()=>{const C=m({name:d});c(C)})]}if(Array.isArray(d)){const u=m({name:d}),o=[];return d.forEach(C=>{const P=M(C),V=s.subscribe(P,()=>{const Z=m({name:C});u[C]=Z,c({...u})});o.push(V)}),o}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),S=r.useCallback((d,b)=>{if(!d)return s.subscribe("values",b);if(typeof d=="string"){const c=M(d);return s.subscribe(c,b)}if(Array.isArray(d)){const c={},u=[];return d.forEach(o=>{const C=M(o),P=s.subscribe(C,()=>{c[o]=m({name:o}),b({...c})});u.push(P)}),u}throw new Error("Parameters of name must be string or array of string")},[s]);return{watch:g,registerHookWatcher:R,getWatchValue:m,subscribe:S}},ve={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},ie={isDirty:!1,isTouched:!1,error:null},Ne=[],Ve={},xe=({numberFields:s=Ne,defaultValues:a=Ve,shouldUnRegister:i=!1,shouldConvertNumber:f=!1}={})=>{const[h,E]=Oe(),m=r.useRef(),g=r.useRef(s),R=r.useRef(new Map),S=r.useRef({}),d=r.useRef({}),b=r.useRef({...ve}),c=r.useRef({...a}),u=r.useRef({...a}),o=Ae(),C=r.useCallback(()=>{d.current=Object.keys(u.current).reduce((t,n)=>({...t,[n]:{...ie}}),{})},[]),P=r.useCallback((t={})=>{u.current={...u.current,...t},c.current={...u.current},R.current.forEach((n,y)=>{n(u.current[y])}),S.current={},b.current={...ve},g.current=s,R.current=new Map,o.reset(),C(),s.length>0&&(f=!0),E()},[]),V=r.useCallback(()=>{const t=Object.fromEntries(new FormData(m.current));return R.current.forEach((y,w)=>{t[w]=c.current[w]}),f&&g.current.forEach(y=>t.hasOwnProperty(y)&&(t[y]=Number(t[y])||0)),{...c.current,...t}},[]),Z=r.useCallback(()=>!!Object.values(D()).find(t=>t.isDirty),[]),Q=r.useCallback(()=>!!Object.values(Y()).find(t=>!!t),[]),se=r.useCallback(t=>ke(t.target),[]),ne=r.useCallback(()=>u.current,[]),ae=r.useCallback(()=>g.current,[]),oe=r.useCallback(()=>R.current,[]),j=r.useCallback((t,n)=>n?Array.isArray(n)?n.reduce((y,w)=>({...y,[w]:X(t,w)}),{}):X(t,n):{...t},[]),K=r.useCallback(t=>j(c.current,t),[j]),Y=r.useCallback(t=>j(S.current,t),[j]),D=r.useCallback(t=>j(d.current,t),[j]),B=r.useCallback(t=>j({...b.current,lastReset:h},t),[j,h]),{watch:I,registerHookWatcher:L,getWatchValue:q,subscribe:$}=je({channels:o,getValues:K,getErrors:Y,getFieldStates:D,getFormState:B}),ee=r.useCallback((t,n)=>{const y=b.current;X(y,t)!==n&&(Re(b.current,t,n),o.publish(`formState.${t}`,n))},[]),p=r.useCallback((t,n,y)=>{const w=d.current[t]||{...ie};X(w,n)!==y&&(Re(d.current,`${t}.${n}`,y),o.publish(`fieldStates.${t}.${n}`,y),n==="error"&&(b.current.errorFields=Object.keys(S.current).filter(A=>!!S.current[A]),o.publish("formState.errorFields",b.current.errorFields)),n==="isDirty"&&(b.current.dirtyFields=Object.keys(d.current).filter(A=>d.current[A].isDirty),o.publish("formState.dirtyFields",b.current.dirtyFields)),n==="isTouched"&&(b.current.touchedFields=Object.keys(d.current).filter(A=>d.current[A].isTouched),o.publish("formState.touchedFields",b.current.touchedFields)))},[]),te=r.useCallback(t=>{p(t,"isDirty",!1),p(t,"isTouched",!1),p(t,"error",null)},[p]),e=r.useCallback((t,n)=>{if(S.current[t]===n)return;S.current[t]=n,p(t,"error",n),o.publish(`errors.${t}`,n);const w=Q();b.current.isError!==w&&(b.current.isError=w,o.publish("formState.isError",w))},[p]),l=r.useCallback(t=>{if(!S.current[t])return;S.current[t]=null,p(t,"error",null),o.publish(`errors.${t}`,null);const n=Q();b.current.isError!==n&&(b.current.isError=n,o.publish("formState.isError",n))},[p]),k=r.useCallback(()=>{if(Object.keys(S.current)===0)return;Object.keys(S.current).forEach(n=>l(n)),S.current={};const t=Q();b.current.isError!==t&&(b.current.isError=t,o.publish("formState.isError",t))},[]),F=r.useCallback(t=>{const n=ke(t.target);n?e(t.target.name,n):l(t.target.name)},[e,l]),N=r.useCallback((t,n,{shouldDirty:y=!0,shouldOnChange:w=!0}={})=>{if(n===c.current[t])return;f&&g.current.includes(t)&&(n=Number(n)||void 0),p(t,"isTouched",!0);const ue=n!==u.current[t];y&&d.current[t].isDirty!==ue&&p(t,"isDirty",ue);const A=Z();b.current.isDirty!==A&&(b.current.isDirty=A,o.publish("formState.isDirty",A)),c.current[t]=n;const z=R.current.get(t);z&&z(n),o.publish(`values.${t}`,n,{shouldDirty:y,shouldOnChange:w}),w&&o.publish("onChange",t,n,c.current)},[p]),_=r.useCallback((t,n)=>(R.current.set(t,n),d.current[t]={...ie},()=>{i&&R.current.delete(t)}),[]),U=r.useCallback((t,{keepError:n,keepDirty:y,keepTouched:w,keepCustomState:ue,defaultValue:A})=>{const z=R.current.get(t);if(!z)throw new Error(`Cannot reset "${t}" because it's uncontrolled field`);u.current[t]=A,c.current[t]=A,z&&z(A),n||l(t),y||p(t,"isDirty",!1),w||p(t,"isTouched",!1)},[l,p]),J=r.useCallback((t,n=x.getValues(t))=>{o.publish("onBlur",t,n,x.getValues())},[]),T=r.useCallback(t=>o.subscribe("onChange",t),[]),W=r.useCallback(t=>o.subscribe("onBlur",t),[]),x=r.useMemo(()=>({subscribe:$,reset:P,resetField:U,setValue:N,getValues:K,getErrors:Y,getFieldStates:D,getFormState:B,setError:e,clearError:l,clearErrors:k,checkValidity:F,getNumberFields:ae,getFieldValidity:se,getDefaultValues:ne,setFieldState:p,triggerFieldBlur:J,resetFieldState:te,getControlledFields:oe,subscribeChange:T,subscribeBlur:W,setFormState:ee,getEvents:o.getEvents,getWatchEvents:o.getWatchEvents}),[$,P,U,N,K,Y,D,B,e,l,k,F,ae,se,ne,p,te,J,oe,T,W,ee]),ce=r.useMemo(()=>({ref:m,watch:I,actions:x,registerController:_,registerHookWatcher:L,lastReloadedAt:h,loadFormValues:V,getWatchValue:q,channels:o}),[m,I,x,_,L,h,V,q,o]),We=r.useMemo(()=>({control:ce,actions:x,watch:I}),[h,ce,x,I]);return r.useLayoutEffect(()=>{if([...m.current.querySelectorAll("[name]")].forEach(n=>{!n.defaultValue&&!R.current.has(n.name)&&u.current[n.name]&&(n.defaultValue=u.current[n.name]),n.type==="number"&&!g.current.includes(n.name)&&g.current.push(n.name)}),m.current){const n=V();c.current={...n},u.current={...n}}},[h]),r.useLayoutEffect(()=>{C()},[]),We};O.Controller=Fe,O.Form=pe,O.useController=ge,O.useForm=xe,O.useFormContext=le,O.useWatch=me,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,F,T,W,T),re[T+F]=!0)}if(T=null,k!==void 0&&(i(k),T=""+k),m(l)&&(i(l.key),T=""+l.key),"key"in l){k={};for(var x in l)x!=="key"&&(k[x]=l[x])}else k=l;return T&&g(k,typeof e=="function"?e.displayName||e.name||"Unknown":e),C(e,T,_,N,h(),k,U,J)}function b(e){typeof e=="object"&&e!==null&&e.$$typeof===u&&e._store&&(e._store.validated=1)}var c=r,u=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ne=Symbol.for("react.forward_ref"),ae=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ce=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),Y=Symbol.for("react.client.reference"),D=c.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=Object.prototype.hasOwnProperty,I=Array.isArray,L=console.createTask?console.createTask:function(){return null};c={"react-stack-bottom-frame":function(e){return e()}};var $,ee={},te=c["react-stack-bottom-frame"].bind(c,E)(),p=L(f(E)),re={};X.Fragment=y,X.jsx=function(e,l,k,F,N){var _=1e4>D.recentlyCreatedOwnerStacks++;return d(e,l,k,!1,F,N,_?Error("react-stack-top-frame"):te,_?L(f(e)):p)},X.jsxs=function(e,l,k,F,N){var _=1e4>D.recentlyCreatedOwnerStacks++;return d(e,l,k,!0,F,N,_?Error("react-stack-top-frame"):te,_?L(f(e)):p)}}()),X}var be;function ye(){return be||(be=1,process.env.NODE_ENV==="production"?se.exports=Se():se.exports=Ce()),se.exports}var he=ye();const v=()=>{},Ee=r.createContext({ref:null,watch:v,actions:{reset:v,resetField:v,setValue:v,getValues:v,getErrors:v,getFieldStates:v,getFormStates:v,setError:v,clearError:v,clearErrors:v,checkValidity:v,getNumberFields:v,getFieldValidity:v,getDefaultValues:v,setFieldState:v,resetFieldState:v,getControlledFields:v},registerController:v,registerHookWatcher:v,lastReloadedAt:v,loadFormValues:v,getWatchValue:v,channels:{}}),le=()=>r.useContext(Ee),pe=({id:s,control:a,method:i,action:f,children:h,onSubmit:E=()=>{},onInput:m=()=>{},onChange:g=()=>{},onBlur:R=()=>{},onReset:C=()=>{},numberFields:d=[],className:b,...c})=>(r.useEffect(()=>{const u=a.channels.subscribe("onChange",g),o=a.channels.subscribe("onBlur",R);return()=>{u(),o()}},[a.lastReloadedAt]),he.jsx(Ee.Provider,{value:a,children:he.jsx("form",{id:s,ref:a.ref,action:f,method:i,className:b,onInput:m,onSubmit:u=>{i||u.preventDefault();const o=a.loadFormValues();E(o)},onChange:u=>{const o=u.target.name;!o||a.actions.getControlledFields().has(o)||a.actions.setValue(o,u.target.value)},onBlur:u=>{const o=u.target.name;if(!o||a.actions.getControlledFields().has(o))return;const y=u.target.value;a.channels.publish("onBlur",o,y,a.actions.getValues())},onReset:u=>{a.actions.reset(),C(u)},...c,children:h},a.lastReloadedAt)})),me=({control:s,name:a,compute:i})=>{const{getWatchValue:f,registerHookWatcher:h}=s||le(),E=f({name:a,compute:i}),[m,g]=r.useState(E);return r.useEffect(()=>{const R=h({name:a,compute:i,value:m,setValue:g});return()=>R.forEach(C=>C())},[]),m},ge=({name:s,defaultValue:a})=>{const{actions:i,registerController:f,channels:h}=le(),E=r.useRef(),m=i.getDefaultValues()[s]||a||"",[g,R]=r.useState(m),C=me({name:`fieldStates.${s}`}),d=r.useCallback((c,{shouldDirty:u=!0,shouldOnChange:o=!0}={})=>{var P,V;let y=c;(P=c==null?void 0:c.target)!=null&&P.value&&(y=c.target.value),(V=c==null?void 0:c.target)!=null&&V.checked&&(y=c.target.checked+""),R(y),i.setValue(s,y,{shouldDirty:u,shouldOnChange:o})},[i.setValue]),b=r.useCallback(c=>{const u=i.getValues(),o=c??u[s];h.publish("onBlur",s,o,u)},[]);return r.useEffect(()=>f(s,R),[]),{ref:E,name:s,defaultValue:m,value:g,onChange:d,onBlur:b,fieldState:C}},Fe=({name:s,defaultValue:a,render:i=({ref:f,name:h,defaultValue:E,value:m,onChange:g,onBlur:R,fieldState:C})=>null})=>{const f=ge({name:s,defaultValue:a});return i(f)},Te=["errors","fieldStates","formState"],Z=(s={},a="")=>a.split(".").reduce((i,f)=>i&&i[f]!==void 0?i[f]:void 0,s),Re=(s={},a="",i)=>{let f=s;const h=a.split(".");return h.forEach((E,m)=>{m<h.length-1&&(f[E]||(f[E]={}),m===h.length-2&&(f[E]={...f[E]}),f=f[E]),f[E]=i}),s},M=s=>Te.some(a=>s.startsWith(a))?s:"values."+s,we=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],ke=s=>{typeof s.setCustomValidity=="function"&&s.setCustomValidity("");let a=s.validity,i=we.find(f=>a[f]);if(i)return{type:i,message:s.validationMessage}};class _e{constructor(){this.events=new Map,this.watchEvents=new Map}getWatchEvents(){return this.watchEvents}getEvents(){return this.events}subscribe(a,i){return this.events.has(a)||this.events.set(a,new Set),this.events.get(a).add(i),()=>{var f;return(f=this.events.get(a))==null?void 0:f.delete(i)}}subscribeWatch(a,i){this.watchEvents.has(a)||(this.watchEvents.set(a,new Set),this.watchEvents.get(a).add(i))}publish(a,...i){this.events.forEach((f,h)=>{a.includes(h)&&f.forEach(E=>E(...i))}),this.watchEvents.forEach((f,h)=>{a.includes(h)&&f.forEach(E=>E(...i))})}reset(){this.events.clear(),this.watchEvents.clear()}}const Ae=()=>{const s=r.useRef(new _e),a=r.useCallback((g,...R)=>{s.current.publish(g,...R)},[]),i=r.useCallback((g,R)=>s.current.subscribe(g,R),[]),f=r.useCallback((g,R)=>{s.current.subscribeWatch(g,R)},[]),h=r.useCallback(()=>s.current.getEvents(),[]),E=r.useCallback(()=>s.current.getWatchEvents(),[]),m=r.useCallback(()=>{s.current.reset()},[]);return{publish:a,subscribe:i,reset:m,getEvents:h,subscribeWatch:f,getWatchEvents:E}},Oe=()=>{const[s,a]=r.useState(),i=r.useCallback(()=>a(new Date().toString()),[]);return[s,i]},Pe=()=>{const[,s]=r.useState({});return r.useCallback(()=>s({}),[])},je=({channels:s,getValues:a,getErrors:i,getFieldStates:f,getFormState:h})=>{const E=Pe(),m=r.useCallback(({name:d,compute:b})=>{if(typeof b=="function")return b(a());if(Array.isArray(d)){const c={};return d.forEach(u=>{c[u]=m({name:u})}),c}return Z({...a(),errors:{...i()},formState:{...h()},fieldStates:{...f()}},d)},[]),g=r.useCallback(d=>{if(!d)return s.subscribeWatch("values",()=>E()),a();if(typeof d=="string"){const b=M(d);return s.subscribeWatch(b,()=>E()),m({name:d})}if(Array.isArray(d)){const b={};return d.forEach(c=>{const u=M(c);s.subscribeWatch(u,()=>E()),b[c]=m({name:c})}),{...b}}throw new Error("Parameters of watch must be string or array of string")},[]),R=r.useCallback(({name:d,compute:b,setValue:c})=>{if(typeof b=="function")return[s.subscribe("values",()=>{const o=m({compute:b});c(o)})];if(!d)return[s.subscribe("values",()=>{c(a())})];if(typeof d=="string"){const u=M(d);return[s.subscribe(u,()=>{const y=m({name:d});c(y)})]}if(Array.isArray(d)){const u=m({name:d}),o=[];return d.forEach(y=>{const P=M(y),V=s.subscribe(P,()=>{const Q=m({name:y});u[y]=Q,c({...u})});o.push(V)}),o}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),C=r.useCallback((d,b)=>{if(!d)return s.subscribe("values",b);if(typeof d=="string"){const c=M(d);return s.subscribe(c,b)}if(Array.isArray(d)){const c={},u=[];return d.forEach(o=>{const y=M(o),P=s.subscribe(y,()=>{c[o]=m({name:o}),b({...c})});u.push(P)}),u}throw new Error("Parameters of name must be string or array of string")},[s]);return{watch:g,registerHookWatcher:R,getWatchValue:m,subscribe:C}},ve={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},ie={isDirty:!1,isTouched:!1,error:null},Ne=[],Ve={},xe=({numberFields:s=Ne,defaultValues:a=Ve,shouldUnRegister:i=!1,shouldConvertNumber:f=!1}={})=>{const[h,E]=Oe(),m=r.useRef(),g=r.useRef(s),R=r.useRef(new Map),C=r.useRef({}),d=r.useRef({}),b=r.useRef({...ve}),c=r.useRef({...a}),u=r.useRef({...a}),o=Ae(),y=r.useCallback(t=>{d.current=Object.keys(u.current).reduce((n,S)=>({...n,[S]:{...t?{}:d.current[S]||{},...ie}}),{})},[]),P=r.useCallback((t={},{clearCustomFormStates:n=!1,clearCustomFieldStates:S=!1}={})=>{u.current={...u.current,...t},c.current={...u.current},R.current.forEach((w,z)=>{w(u.current[z])}),C.current={},b.current={...n?{}:b.current,...ve},g.current=s,R.current=new Map,o.reset(),y(S),s.length>0&&(f=!0),E()},[]),V=r.useCallback(()=>{const t=Object.fromEntries(new FormData(m.current));return R.current.forEach((S,w)=>{t[w]=c.current[w]}),f&&g.current.forEach(S=>t.hasOwnProperty(S)&&(t[S]=Number(t[S])||0)),{...c.current,...t}},[]),Q=r.useCallback(()=>!!Object.values(D()).find(t=>t.isDirty),[]),K=r.useCallback(()=>!!Object.values(Y()).find(t=>!!t),[]),ne=r.useCallback(t=>ke(t.target),[]),ae=r.useCallback(()=>u.current,[]),oe=r.useCallback(()=>g.current,[]),ce=r.useCallback(()=>R.current,[]),j=r.useCallback((t,n)=>n?Array.isArray(n)?n.reduce((S,w)=>({...S,[w]:Z(t,w)}),{}):Z(t,n):{...t},[]),q=r.useCallback(t=>j(c.current,t),[j]),Y=r.useCallback(t=>j(C.current,t),[j]),D=r.useCallback(t=>j(d.current,t),[j]),B=r.useCallback(t=>j({...b.current,lastReset:h},t),[j,h]),{watch:I,registerHookWatcher:L,getWatchValue:$,subscribe:ee}=je({channels:o,getValues:q,getErrors:Y,getFieldStates:D,getFormState:B}),te=r.useCallback((t,n)=>{const S=b.current;Z(S,t)!==n&&(Re(b.current,t,n),o.publish(`formState.${t}`,n))},[]),p=r.useCallback((t,n,S)=>{const w=d.current[t]||{...ie};Z(w,n)!==S&&(Re(d.current,`${t}.${n}`,S),o.publish(`fieldStates.${t}.${n}`,S),n==="error"&&(b.current.errorFields=Object.keys(C.current).filter(A=>!!C.current[A]),o.publish("formState.errorFields",b.current.errorFields)),n==="isDirty"&&(b.current.dirtyFields=Object.keys(d.current).filter(A=>d.current[A].isDirty),o.publish("formState.dirtyFields",b.current.dirtyFields)),n==="isTouched"&&(b.current.touchedFields=Object.keys(d.current).filter(A=>d.current[A].isTouched),o.publish("formState.touchedFields",b.current.touchedFields)))},[]),re=r.useCallback(t=>{p(t,"isDirty",!1),p(t,"isTouched",!1),p(t,"error",null)},[p]),e=r.useCallback((t,n)=>{if(C.current[t]===n)return;C.current[t]=n,p(t,"error",n),o.publish(`errors.${t}`,n);const w=K();b.current.isError!==w&&(b.current.isError=w,o.publish("formState.isError",w))},[p]),l=r.useCallback(t=>{if(!C.current[t])return;C.current[t]=null,p(t,"error",null),o.publish(`errors.${t}`,null);const n=K();b.current.isError!==n&&(b.current.isError=n,o.publish("formState.isError",n))},[p]),k=r.useCallback(()=>{if(Object.keys(C.current)===0)return;Object.keys(C.current).forEach(n=>l(n)),C.current={};const t=K();b.current.isError!==t&&(b.current.isError=t,o.publish("formState.isError",t))},[]),F=r.useCallback(t=>{const n=ke(t.target);n?e(t.target.name,n):l(t.target.name)},[e,l]),N=r.useCallback((t,n,{shouldDirty:S=!0,shouldOnChange:w=!0}={})=>{if(n===c.current[t])return;f&&g.current.includes(t)&&(n=Number(n)||void 0),p(t,"isTouched",!0);const z=n!==u.current[t];S&&d.current[t].isDirty!==z&&p(t,"isDirty",z);const A=Q();b.current.isDirty!==A&&(b.current.isDirty=A,o.publish("formState.isDirty",A)),c.current[t]=n;const G=R.current.get(t);G&&G(n),o.publish(`values.${t}`,n,{shouldDirty:S,shouldOnChange:w}),w&&o.publish("onChange",t,n,c.current)},[p]),_=r.useCallback((t,n)=>(R.current.set(t,n),d.current[t]={...ie},()=>{i&&R.current.delete(t)}),[]),U=r.useCallback((t,{keepError:n,keepDirty:S,keepTouched:w,keepCustomState:z,defaultValue:A})=>{const G=R.current.get(t);if(!G)throw new Error(`Cannot reset "${t}" because it's uncontrolled field`);u.current[t]=A,c.current[t]=A,G&&G(A),n||l(t),S||p(t,"isDirty",!1),w||p(t,"isTouched",!1)},[l,p]),J=r.useCallback((t,n=x.getValues(t))=>{o.publish("onBlur",t,n,x.getValues())},[]),T=r.useCallback(t=>o.subscribe("onChange",t),[]),W=r.useCallback(t=>o.subscribe("onBlur",t),[]),x=r.useMemo(()=>({subscribe:ee,reset:P,resetField:U,setValue:N,getValues:q,getErrors:Y,getFieldStates:D,getFormState:B,setError:e,clearError:l,clearErrors:k,checkValidity:F,getNumberFields:oe,getFieldValidity:ne,getDefaultValues:ae,setFieldState:p,triggerFieldBlur:J,resetFieldState:re,getControlledFields:ce,subscribeChange:T,subscribeBlur:W,setFormState:te,getEvents:o.getEvents,getWatchEvents:o.getWatchEvents}),[ee,P,U,N,q,Y,D,B,e,l,k,F,oe,ne,ae,p,re,J,ce,T,W,te]),ue=r.useMemo(()=>({ref:m,watch:I,actions:x,registerController:_,registerHookWatcher:L,lastReloadedAt:h,loadFormValues:V,getWatchValue:$,channels:o}),[m,I,x,_,L,h,V,$,o]),We=r.useMemo(()=>({control:ue,actions:x,watch:I}),[h,ue,x,I]);return r.useLayoutEffect(()=>{if([...m.current.querySelectorAll("[name]")].forEach(n=>{!n.defaultValue&&!R.current.has(n.name)&&u.current[n.name]&&(n.defaultValue=u.current[n.name]),n.type==="number"&&!g.current.includes(n.name)&&g.current.push(n.name)}),m.current){const n=V();c.current={...n},u.current={...n}}},[h]),r.useLayoutEffect(()=>{y()},[]),We};O.Controller=Fe,O.Form=pe,O.useController=ge,O.useForm=xe,O.useFormContext=le,O.useWatch=me,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|