react-simple-formkit 2.2.3 → 2.2.5

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 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 states](#manage-states)
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
- ### `Uncontrolled`:
84
+ React Simple FormKit provides three flexible modes to help you balance performance and feature requirements.
82
85
 
83
- Basic HTML form elements whose value is natively managed by the browser. Such as
84
- `<input type="text">`, `<input type="checkbox">`, `<select>`, or `<textarea>`.
86
+ ### 1. `Uncontrolled`:
85
87
 
86
- > **Note:** Or also **UI library components** that are simple wrappers around these native elements that **still follow the browser’s standard behavior**
88
+ **Best for**: High Performance.
87
89
 
88
- ### `Controlled`:
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
- 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.
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:** Or whenever you want to **control the value of a field** (e.g. by calling `actions.setValue`), you **must** wrap that field with a `Controller`.
98
- > Without `Controller`, the field will not respond to external value changes.
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
- ## Get form states
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.customState")
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)
@@ -395,6 +403,7 @@ Return:
395
403
  - `actions.setValue()`: `(name: String, value: Any, options?: { shouldDirty?: Boolean, shouldTouched?: Boolean }) => void` [Example](#set-value)
396
404
  - `actions.setError()`: `(name: String, error: Any) => void` [Example](#set-field-error)
397
405
  - `actions.setFieldState()`: `(name: String, property: String, value: Any) => void` [Example](#set-field-states)
406
+ - `actions.setFormState()`: `(name: String, value: Any) => void`
398
407
  - `actions.triggerFieldBlur()`: `(name: String, value?: Any) => void`
399
408
  - `actions.resetFieldState()`: `(name: String) => void`
400
409
  - `actions.resetField()`: `(name: String) => void`
@@ -420,7 +429,7 @@ Generic props:
420
429
 
421
430
  - `name`
422
431
  - `defaultValue`
423
- - `render({name, value, onChange, onBlur, customState, setCustomState})`
432
+ - `render({name, value, onChange, onBlur, fieldState})`
424
433
 
425
434
  ## useController
426
435
 
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react");var ue={exports:{}},Q={};/**
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 ke(){if(ie)return Q;ie=1;var s=Symbol.for("react.transitional.element"),u=Symbol.for("react.fragment");function l(i,E,h){var g=null;if(h!==void 0&&(g=""+h),E.key!==void 0&&(g=""+E.key),"key"in E){h={};for(var k in E)k!=="key"&&(h[k]=E[k])}else h=E;return E=h.ref,{$$typeof:s,type:i,key:g,ref:E!==void 0?E:null,props:h}}return Q.Fragment=u,Q.jsx=l,Q.jsxs=l,Q}var K={};/**
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 ve(){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===z?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case b:return"Fragment";case x:return"Profiler";case A:return"StrictMode";case ee:return"Suspense";case re:return"SuspenseList";case P: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 d:return"Portal";case oe:return(e.displayName||"Context")+".Provider";case M:return(e._context.displayName||"Context")+".Consumer";case q:var o=e.render;return e=e.displayName,e||(e=o.displayName||o.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case te:return o=e.displayName||null,o!==null?o:s(e.type)||"Memo";case J:o=e._payload,e=e._init;try{return s(e(o))}catch{}}return null}function u(e){return""+e}function l(e){try{u(e);var o=!1}catch{o=!0}if(o){o=console;var R=o.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return R.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),u(e)}}function i(e){if(e===b)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===J)return"<...>";try{var o=s(e);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function E(){var e=V.A;return e===null?null:e.getOwner()}function h(){return Error("react-stack-top-frame")}function g(e){if($.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function k(e,o){function R(){G||(G=!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)",o))}R.isReactWarning=!0,Object.defineProperty(e,"key",{get:R,configurable:!0})}function v(){var e=s(this.type);return H[e]||(H[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 F(e,o,R,p,O,_,B,I){return R=_.ref,e={$$typeof:c,type:e,key:o,props:_,_owner:O},(R!==void 0?R:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:v}):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 f(e,o,R,p,O,_,B,I){var y=o.children;if(y!==void 0)if(p)if(W(y)){for(p=0;p<y.length;p++)m(y[p]);Object.freeze&&Object.freeze(y)}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 m(y);if($.call(o,"key")){y=s(e);var N=Object.keys(o).filter(function(se){return se!=="key"});p=0<N.length?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}",Z[y+p]||(N=0<N.length?"{"+N.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
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} />`,p,y,N,y),Z[y+p]=!0)}if(y=null,R!==void 0&&(l(R),y=""+R),g(o)&&(l(o.key),y=""+o.key),"key"in o){R={};for(var j in o)j!=="key"&&(R[j]=o[j])}else R=o;return y&&k(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),F(e,y,_,O,E(),R,B,I)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===c&&e._store&&(e._store.validated=1)}var a=t,c=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),oe=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),ee=Symbol.for("react.suspense"),re=Symbol.for("react.suspense_list"),te=Symbol.for("react.memo"),J=Symbol.for("react.lazy"),P=Symbol.for("react.activity"),z=Symbol.for("react.client.reference"),V=a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,$=Object.prototype.hasOwnProperty,W=Array.isArray,D=console.createTask?console.createTask:function(){return null};a={"react-stack-bottom-frame":function(e){return e()}};var G,H={},X=a["react-stack-bottom-frame"].bind(a,h)(),S=D(i(h)),Z={};K.Fragment=b,K.jsx=function(e,o,R,p,O){var _=1e4>V.recentlyCreatedOwnerStacks++;return f(e,o,R,!1,p,O,_?Error("react-stack-top-frame"):X,_?D(i(e)):S)},K.jsxs=function(e,o,R,p,O){var _=1e4>V.recentlyCreatedOwnerStacks++;return f(e,o,R,!0,p,O,_?Error("react-stack-top-frame"):X,_?D(i(e)):S)}}()),K}var be;function Ce(){return be||(be=1,process.env.NODE_ENV==="production"?ue.exports=ke():ue.exports=ve()),ue.exports}var de=Ce();const C=()=>{},Ee=t.createContext({ref:null,watch:C,actions:{reset:C,resetField:C,setValue:C,getValues:C,getErrors:C,getFieldStates:C,getFormStates:C,setError:C,clearError:C,clearErrors:C,checkValidity:C,getNumberFields:C,getFieldValidity:C,getDefaultValues:C,setFieldState:C,resetFieldState:C,getControlledFields:C},registerController:C,registerHookWatcher:C,lastReloadedAt:C,loadFormValues:C,getWatchValue:C,channels:{}}),le=()=>t.useContext(Ee),Se=({id:s,control:u,method:l,action:i,children:E,onSubmit:h=()=>{},onInput:g=()=>{},onChange:k=()=>{},onBlur:v=()=>{},onReset:F=()=>{},numberFields:f=[],className:m,...a})=>(t.useEffect(()=>{const c=u.channels.subscribe("onChange",k),d=u.channels.subscribe("onBlur",v);return()=>{c(),d()}},[u.lastReloadedAt]),de.jsx(Ee.Provider,{value:u,children:de.jsx("form",{id:s,ref:u.ref,action:i,method:l,className:m,onInput:g,onSubmit:c=>{l||c.preventDefault();const d=u.loadFormValues();h(d)},onChange:c=>{const d=c.target.name;!d||u.actions.getControlledFields().has(d)||u.actions.setValue(d,c.target.value)},onBlur:c=>{const d=c.target.name;if(!d||u.actions.getControlledFields().has(d))return;const b=c.target.value;u.channels.publish("onBlur",d,b,u.actions.getValues())},onReset:c=>{u.actions.reset(),F(c)},...a,children:E},u.lastReloadedAt)})),ge=({control:s,name:u,compute:l})=>{const{getWatchValue:i,registerHookWatcher:E}=s||le(),h=i({name:u,compute:l}),[g,k]=t.useState(h);return t.useEffect(()=>{const v=E({name:u,compute:l,value:g,setValue:k});return()=>v.forEach(F=>F())},[]),g},me=({name:s,defaultValue:u})=>{const{actions:l,registerController:i,channels:E}=le(),h=t.useRef(),g=l.getDefaultValues()[s]||u||"",[k,v]=t.useState(g),F=ge({name:`fieldStates.${s}`}),f=t.useCallback((a,{shouldDirty:c=!0,shouldOnChange:d=!0}={})=>{var A,x;let b=a;(A=a==null?void 0:a.target)!=null&&A.value&&(b=a.target.value),(x=a==null?void 0:a.target)!=null&&x.checked&&(b=a.target.checked+""),v(b),l.setValue(s,b,{shouldDirty:c,shouldOnChange:d})},[l.setValue]),m=t.useCallback(a=>{const c=l.getValues(),d=a??c[s];E.publish("onBlur",s,d,c)},[]);return t.useEffect(()=>i(s,v),[]),{ref:h,name:s,defaultValue:g,value:k,onChange:f,onBlur:m,fieldState:F}},pe=({name:s,defaultValue:u,render:l=({ref:i,name:E,defaultValue:h,value:g,onChange:k,onBlur:v,fieldState:F})=>null})=>{const i=me({name:s,defaultValue:u});return l(i)},ye=["errors","fieldStates","formState"],ae=(s={},u="")=>u.split(".").reduce((l,i)=>l&&l[i]!==void 0?l[i]:void 0,s),we=(s={},u="",l)=>{let i=s;const E=u.split(".");return E.forEach((h,g)=>{g<E.length-1&&(i[h]||(i[h]={}),g===E.length-2&&(i[h]={...i[h]}),i=i[h]),i[h]=l}),s},U=s=>ye.some(u=>s.startsWith(u))?s:"values."+s,Fe=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],he=s=>{typeof s.setCustomValidity=="function"&&s.setCustomValidity("");let u=s.validity,l=Fe.find(i=>u[i]);if(l)return{type:l,message:s.validationMessage}};class Te{constructor(){this.events=new Map,this.watchEvents=new Map}getWatchEvents(){return this.watchEvents}getEvents(){return this.events}subscribe(u,l){return this.events.has(u)||this.events.set(u,new Set),this.events.get(u).add(l),()=>{var i;return(i=this.events.get(u))==null?void 0:i.delete(l)}}subscribeWatch(u,l){this.watchEvents.has(u)||(this.watchEvents.set(u,new Set),this.watchEvents.get(u).add(l))}publish(u,...l){this.events.forEach((i,E)=>{u.includes(E)&&i.forEach(h=>h(...l))}),this.watchEvents.forEach((i,E)=>{u.includes(E)&&i.forEach(h=>h(...l))})}reset(){this.events.clear(),this.watchEvents.clear()}}const _e=()=>{const s=t.useRef(new Te),u=t.useCallback((k,...v)=>{s.current.publish(k,...v)},[]),l=t.useCallback((k,v)=>s.current.subscribe(k,v),[]),i=t.useCallback((k,v)=>{s.current.subscribeWatch(k,v)},[]),E=t.useCallback(()=>s.current.getEvents(),[]),h=t.useCallback(()=>s.current.getWatchEvents(),[]),g=t.useCallback(()=>{s.current.reset()},[]);return{publish:u,subscribe:l,reset:g,getEvents:E,subscribeWatch:i,getWatchEvents:h}},Ae=()=>{const[s,u]=t.useState(),l=t.useCallback(()=>u(new Date().toString()),[]);return[s,l]},Oe=()=>{const[,s]=t.useState({});return t.useCallback(()=>s({}),[])},Pe=({channels:s,getValues:u,getErrors:l,getFieldStates:i,getFormState:E})=>{const h=Oe(),g=t.useCallback(({name:f,compute:m})=>{if(typeof m=="function")return m(u());if(Array.isArray(f)){const a={};return f.forEach(c=>{a[c]=g({name:c})}),a}return ae({...u(),errors:{...l()},formState:{...E()},fieldStates:{...i()}},f)},[]),k=t.useCallback(f=>{if(!f)return s.subscribeWatch("values",()=>h()),u();if(typeof f=="string"){const m=U(f);return s.subscribeWatch(m,()=>h()),g({name:f})}if(Array.isArray(f)){const m={};return f.forEach(a=>{const c=U(a);s.subscribeWatch(c,()=>h()),m[a]=g({name:a})}),{...m}}throw new Error("Parameters of watch must be string or array of string")},[]),v=t.useCallback(({name:f,compute:m,setValue:a})=>{if(typeof m=="function")return[s.subscribe("values",()=>{const d=g({compute:m});a(d)})];if(!f)return[s.subscribe("values",()=>{a(u())})];if(typeof f=="string"){const c=U(f);return[s.subscribe(c,()=>{const b=g({name:f});a(b)})]}if(Array.isArray(f)){const c=g({name:f}),d=[];return f.forEach(b=>{const A=U(b),x=s.subscribe(A,()=>{const M=g({name:b});c[b]=M,a({...c})});d.push(x)}),d}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),F=t.useCallback((f,m)=>{if(!f)return s.subscribe("values",m);if(typeof f=="string"){const a=U(f);return s.subscribe(a,m)}if(Array.isArray(f)){const a={},c=[];return f.forEach(d=>{const b=U(d),A=s.subscribe(b,()=>{a[d]=g({name:d}),m({...a})});c.push(A)}),c}throw new Error("Parameters of name must be string or array of string")},[s]);return{watch:k,registerHookWatcher:v,getWatchValue:g,subscribe:F}},ce={isDirty:!1,isTouched:!1,error:null},je=[],xe={},Ne=({numberFields:s=je,defaultValues:u=xe,shouldUnRegister:l=!1,shouldConvertNumber:i=!1}={})=>{const[E,h]=Ae(),g=t.useRef(),k=t.useRef(!1),v=t.useRef(!1),F=t.useRef(s),f=t.useRef(new Map),m=t.useRef({}),a=t.useRef({}),c=t.useRef({...u}),d=t.useRef({...u}),b=_e(),A=t.useCallback(()=>{a.current=Object.keys(d.current).reduce((r,n)=>({...r,[n]:{...ce}}),{})},[]),x=t.useCallback((r={})=>{d.current={...d.current,...r},c.current={...d.current},f.current.forEach((n,w)=>{n(d.current[w])}),k.current=!1,m.current={},F.current=s,f.current=new Map,b.reset(),A(),s.length>0&&(i=!0),h()},[]),M=t.useCallback(()=>{const r=Object.fromEntries(new FormData(g.current));return f.current.forEach((w,T)=>{r[T]=c.current[T]}),i&&F.current.forEach(w=>r.hasOwnProperty(w)&&(r[w]=Number(r[w])||0)),{...c.current,...r}},[]),oe=t.useCallback(()=>!!Object.values($()).find(r=>r.isDirty),[]),q=t.useCallback(()=>!!Object.values(V()).find(r=>!!r),[]),ee=t.useCallback(r=>he(r.target),[]),re=t.useCallback(()=>d.current,[]),te=t.useCallback(()=>F.current,[]),J=t.useCallback(()=>f.current,[]),P=t.useCallback((r,n)=>n?Array.isArray(n)?n.reduce((w,T)=>({...w,[T]:ae(r,T)}),{}):ae(r,n):{...r},[]),z=t.useCallback(r=>P(c.current,r),[P]),V=t.useCallback(r=>P(m.current,r),[P]),$=t.useCallback(r=>P(a.current,r),[P]),W=t.useCallback(r=>P({isDirty:k.current,isError:v.current,errorFields:Object.keys(m.current).filter(n=>!!m.current[n]),dirtyFields:Object.keys(a.current).filter(n=>a.current[n].isDirty),touchedFields:Object.keys(a.current).filter(n=>a.current[n].isTouched)},r),[P]),{watch:D,registerHookWatcher:G,getWatchValue:H,subscribe:X}=Pe({channels:b,getValues:z,getErrors:V,getFieldStates:$,getFormState:W}),S=t.useCallback((r,n,w)=>{const T=a.current[r]||{...ce};ae(T,n)!==w&&(we(a.current,`${r}.${n}`,w),b.publish(`fieldStates.${r}.${n}`,w),n==="error"&&b.publish("formState.errorFields",W("errorFields")),n==="isDirty"&&b.publish("formState.dirtyFields",W("dirtyFields")),n==="isTouched"&&b.publish("formState.touchedFields",W("touchedFields")))},[]),Z=t.useCallback(r=>{S(r,"isDirty",!1),S(r,"isTouched",!1),S(r,"error",null)},[S]),e=t.useCallback((r,n)=>{if(m.current[r]===n)return;m.current[r]=n,S(r,"error",n),b.publish(`errors.${r}`,n);const T=q();v.current!==T&&(v.current=T,b.publish("formState.isError",T))},[S]),o=t.useCallback(r=>{if(!m.current[r])return;m.current[r]=null,S(r,"error",null),b.publish(`errors.${r}`,null);const n=q();v.current!==n&&(v.current=n,b.publish("formState.isError",n))},[S]),R=t.useCallback(()=>{if(Object.keys(m.current)===0)return;Object.keys(m.current).forEach(n=>o(n)),m.current={};const r=q();v.current!==r&&(v.current=r,b.publish("formState.isError",r))},[]),p=t.useCallback(r=>{const n=he(r.target);n?e(r.target.name,n):o(r.target.name)},[e,o]),O=t.useCallback((r,n,{shouldDirty:w=!0,shouldOnChange:T=!0}={})=>{if(n===c.current[r])return;i&&F.current.includes(r)&&(n=Number(n)||void 0),S(r,"isTouched",!0);const ne=n!==d.current[r];w&&a.current[r].isDirty!==ne&&S(r,"isDirty",ne);const Y=oe();k.current!==Y&&(k.current=Y,b.publish("formState.isDirty",Y)),c.current[r]=n;const L=f.current.get(r);L&&L(n),b.publish(`values.${r}`,n,{shouldDirty:w,shouldOnChange:T}),T&&b.publish("onChange",r,n,c.current)},[S]),_=t.useCallback((r,n)=>(f.current.set(r,n),a.current[r]={...ce},()=>{l&&f.current.delete(r)}),[]),B=t.useCallback((r,{keepError:n,keepDirty:w,keepTouched:T,keepCustomState:ne,defaultValue:Y})=>{const L=f.current.get(r);if(!L)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);d.current[r]=Y,c.current[r]=Y,L&&L(Y),n||o(r),w||S(r,"isDirty",!1),T||S(r,"isTouched",!1)},[o,S]),I=t.useCallback((r,n=j.getValues(r))=>{b.publish("onBlur",r,n,j.getValues())},[]),y=t.useCallback(r=>b.subscribe("onChange",r),[]),N=t.useCallback(r=>b.subscribe("onBlur",r),[]),j=t.useMemo(()=>({subscribe:X,reset:x,resetField:B,setValue:O,getValues:z,getErrors:V,getFieldStates:$,getFormState:W,setError:e,clearError:o,clearErrors:R,checkValidity:p,getNumberFields:te,getFieldValidity:ee,getDefaultValues:re,setFieldState:S,triggerFieldBlur:I,resetFieldState:Z,getControlledFields:J,subscribeChange:y,subscribeBlur:N,getEvents:b.getEvents,getWatchEvents:b.getWatchEvents}),[X,x,B,O,z,V,$,W,e,o,R,p,te,ee,re,S,Z,I,J,y,N]),se=t.useMemo(()=>({ref:g,watch:D,actions:j,registerController:_,registerHookWatcher:G,lastReloadedAt:E,loadFormValues:M,getWatchValue:H,channels:b}),[g,D,j,_,G,E,M,H,b]),Re=t.useMemo(()=>({control:se,actions:j,watch:D}),[E,se,j,D]);return t.useLayoutEffect(()=>{if([...g.current.querySelectorAll("[name]")].forEach(n=>{!n.defaultValue&&!f.current.has(n.name)&&d.current[n.name]&&(n.defaultValue=d.current[n.name]),n.type==="number"&&!F.current.includes(n.name)&&F.current.push(n.name)}),g.current){const n=M();c.current={...n},d.current={...n}}},[E]),t.useLayoutEffect(()=>{A()},[]),Re};exports.Controller=pe;exports.Form=Se;exports.useController=me;exports.useForm=Ne;exports.useFormContext=le;exports.useWatch=ge;
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;