react-simple-formkit 2.4.2 → 2.4.4
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 +17 -9
- package/dist/react-simple-formkit.js +4 -4
- package/dist/react-simple-formkit.mjs +330 -320
- package/dist/react-simple-formkit.umd.js +4 -4
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -97,6 +97,8 @@ return (
|
|
|
97
97
|
|
|
98
98
|
- **`onBlur` Behavior**: Works automatically by default.
|
|
99
99
|
|
|
100
|
+
> **Warning:** The library automatically captures changes in the `Form` component through bubbled events from input fields. However, if in some cases it cannot capture changes (e.g., due to a custom input or `e.stopPropagation()`), please use **`Controller`** so the form can work correctly.
|
|
101
|
+
|
|
100
102
|
### 2. `Controlled`:
|
|
101
103
|
|
|
102
104
|
**Best for**: Absolute control over input or complex UIs.
|
|
@@ -110,9 +112,9 @@ By using `Controller`, you can transform the value in both directions:
|
|
|
110
112
|
- On `change`: join the selected array back into a string before updating the form state.
|
|
111
113
|
|
|
112
114
|
> **Note:**
|
|
115
|
+
> You should explicitly pass the **`onBlur`** prop during rendering to use blur tracking features.
|
|
113
116
|
> whenever you want to **control the value of a field** (e.g. by calling **`actions.setValue`**), you **must** wrap that field with a **`Controller`**.
|
|
114
117
|
> Without **`Controller`**, the field will not respond to external value changes.
|
|
115
|
-
> You should explicitly pass the **`onBlur`** prop during rendering for the library to track the field's state.
|
|
116
118
|
|
|
117
119
|
Example:
|
|
118
120
|
|
|
@@ -190,6 +192,7 @@ State updates only when observed via `watch()`, `useWatch()`, `subscribe()`, or
|
|
|
190
192
|
- [actions.trigger(name)](#actions.trigger) trigger watchers (e.g. `watch`, `useWatch`, `subscribe`) re-update values if needed.
|
|
191
193
|
|
|
192
194
|
> **Rule\*:** By default, onBlur works automatically for uncontrolled fields. However, for controlled fields, you must explicitly pass the onBlur prop when rendering the field.
|
|
195
|
+
> actions.setValue() makes onChange by default, if you call it in onChange callback so it will make infinite loop.
|
|
193
196
|
|
|
194
197
|
### The Power of watch (Unified Observation)
|
|
195
198
|
|
|
@@ -382,7 +385,7 @@ return (
|
|
|
382
385
|
|
|
383
386
|
- **Use cases**: When you need to group multiple fields into an object. By registering these fields with dot notation, you can manage these fieldStates, errors, values as a nested object.
|
|
384
387
|
|
|
385
|
-
- **Example**: Suppose an address has two fields, line1 and line2. You want to track their individual states (fieldStates, errors, values) separately, but you also need to group them under a single address object for easier management and form submission.
|
|
388
|
+
- **Example**: Suppose an address group has two fields, line1 and line2. You want to track their individual states (fieldStates, errors, values) separately, but you also need to group them under a single address object for easier management and form submission.
|
|
386
389
|
|
|
387
390
|
## Registering
|
|
388
391
|
|
|
@@ -411,7 +414,7 @@ const { control, actions } = useForm({ groups: ["address"] })
|
|
|
411
414
|
actions.addGroups(["address"])
|
|
412
415
|
```
|
|
413
416
|
|
|
414
|
-
> **Rule\***:
|
|
417
|
+
> **Rule\***: If a group isn't registered, the field will be treated as a regular field with an object type value.
|
|
415
418
|
|
|
416
419
|
## Watching
|
|
417
420
|
|
|
@@ -433,7 +436,7 @@ actions.setFieldState("address.line1", "disabled", true)
|
|
|
433
436
|
actions.setFieldState("address.line1", "custom", { hello: "world" })
|
|
434
437
|
```
|
|
435
438
|
|
|
436
|
-
> **Rule\***: If
|
|
439
|
+
> **Rule\***: If a `group` is registered, all the fieldState, error, and value will be stored in the bottom level fields (leaf nodes). You cannot set fieldState, error, and value for a `group` (e.g. "address").
|
|
437
440
|
|
|
438
441
|
# Utilities
|
|
439
442
|
|
|
@@ -506,18 +509,22 @@ Generic props:
|
|
|
506
509
|
|
|
507
510
|
Generic props:
|
|
508
511
|
|
|
509
|
-
- `name`
|
|
510
|
-
- `defaultValue`
|
|
512
|
+
- `name`: `String`
|
|
513
|
+
- `defaultValue`: `Any`
|
|
514
|
+
- `shouldUnRegister`: `Boolean` Default is **false**
|
|
515
|
+
- `control`: received from useForm(). Pass it if use Controller outside `<Form>`
|
|
511
516
|
- `render({name, value, onChange, onBlur, fieldState})`
|
|
512
517
|
|
|
513
518
|
## useController
|
|
514
519
|
|
|
515
520
|
Generic props:
|
|
516
521
|
|
|
517
|
-
- `name`
|
|
518
|
-
- `defaultValue`
|
|
522
|
+
- `name`: `String`
|
|
523
|
+
- `defaultValue`: `Any`
|
|
524
|
+
- `shouldUnRegister`: `Boolean` Default is **false**
|
|
525
|
+
- `control`: received from useForm(). Pass it if use Controller outside `<Form>`
|
|
519
526
|
|
|
520
|
-
Return:
|
|
527
|
+
Return: `render` arguments in `<Controller>`
|
|
521
528
|
|
|
522
529
|
## useWatch
|
|
523
530
|
|
|
@@ -527,6 +534,7 @@ Generic props:
|
|
|
527
534
|
|
|
528
535
|
- `name`: `String | Array | undefined`. If undefined, it will return all input values
|
|
529
536
|
- `compute`: `Function` that will calculate from form values and return a value. It will make re-render when the result changes
|
|
537
|
+
- `control`: received from useForm(). Pass it if use Controller outside `<Form>`
|
|
530
538
|
|
|
531
539
|
Return:
|
|
532
540
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var ce={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 be;function Te(){if(be)return
|
|
9
|
+
*/var be;function Te(){if(be)return K;be=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function c(i,a,f){var u=null;if(f!==void 0&&(u=""+f),a.key!==void 0&&(u=""+a.key),"key"in a){f={};for(var h in a)h!=="key"&&(f[h]=a[h])}else f=a;return a=f.ref,{$$typeof:n,type:i,key:u,ref:a!==void 0?a:null,props:f}}return K.Fragment=t,K.jsx=c,K.jsxs=c,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 Ee;function Ae(){return Ee||(Ee=1,process.env.NODE_ENV!=="production"&&function(){function n(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===
|
|
17
|
+
*/var Ee;function Ae(){return Ee||(Ee=1,process.env.NODE_ENV!=="production"&&function(){function n(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===te?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case C:return"Fragment";case A:return"Profiler";case M:return"StrictMode";case J:return"Suspense";case ae:return"SuspenseList";case k:return"Activity"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case S:return"Portal";case P:return(r.displayName||"Context")+".Provider";case D:return(r._context.displayName||"Context")+".Consumer";case I:var b=r.render;return r=r.displayName,r||(r=b.displayName||b.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case re:return b=r.displayName||null,b!==null?b:n(r.type)||"Memo";case L:b=r._payload,r=r._init;try{return n(r(b))}catch{}}return null}function t(r){return""+r}function c(r){try{t(r);var b=!1}catch{b=!0}if(b){b=console;var p=b.error,O=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return p.call(b,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",O),t(r)}}function i(r){if(r===C)return"<>";if(typeof r=="object"&&r!==null&&r.$$typeof===L)return"<...>";try{var b=n(r);return b?"<"+b+">":"<...>"}catch{return"<...>"}}function a(){var r=X.A;return r===null?null:r.getOwner()}function f(){return Error("react-stack-top-frame")}function u(r){if(se.call(r,"key")){var b=Object.getOwnPropertyDescriptor(r,"key").get;if(b&&b.isReactWarning)return!1}return r.key!==void 0}function h(r,b){function p(){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)",b))}p.isReactWarning=!0,Object.defineProperty(r,"key",{get:p,configurable:!0})}function R(){var r=n(this.type);return ne[r]||(ne[r]=!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.")),r=this.props.ref,r!==void 0?r:null}function d(r,b,p,O,Y,x,Z,B){return p=x.ref,r={$$typeof:T,type:r,key:b,props:x,_owner:Y},(p!==void 0?p:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:R}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(r,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.defineProperty(r,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function l(r,b,p,O,Y,x,Z,B){var _=b.children;if(_!==void 0)if(O)if(le(_)){for(O=0;O<_.length;O++)g(_[O]);Object.freeze&&Object.freeze(_)}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 g(_);if(se.call(b,"key")){_=n(r);var U=Object.keys(b).filter(function(e){return e!=="key"});O=0<U.length?"{key: someKey, "+U.join(": ..., ")+": ...}":"{key: someKey}",ue[_+O]||(U=0<U.length?"{"+U.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} />`,O,_,U,_),oe[_+O]=!0)}if(_=null,p!==void 0&&(c(p),_=""+p),u(d)&&(c(d.key),_=""+d.key),"key"in d){p={};for(var Z in d)Z!=="key"&&(p[Z]=d[Z])}else p=d;return _&&m(p,typeof r=="function"?r.displayName||r.name||"Unknown":r),b(r,_,x,W,a(),p,X,B)}function g(r){typeof r=="object"&&r!==null&&r.$$typeof===A&&r._store&&(r._store.validated=1)}var v=s,A=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),k=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),D=Symbol.for("react.context"),Y=Symbol.for("react.forward_ref"),ce=Symbol.for("react.suspense"),ae=Symbol.for("react.suspense_list"),ee=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),F=Symbol.for("react.activity"),re=Symbol.for("react.client.reference"),H=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te=Object.prototype.hasOwnProperty,le=Array.isArray,J=console.createTask?console.createTask:function(){return null};v={"react-stack-bottom-frame":function(r){return r()}};var G,se={},N=v["react-stack-bottom-frame"].bind(v,f)(),ne=J(l(f)),oe={};K.Fragment=C,K.jsx=function(r,d,p,O,W){var x=1e4>H.recentlyCreatedOwnerStacks++;return i(r,d,p,!1,O,W,x?Error("react-stack-top-frame"):N,x?J(l(r)):ne)},K.jsxs=function(r,d,p,O,W){var x=1e4>H.recentlyCreatedOwnerStacks++;return i(r,d,p,!0,O,W,x?Error("react-stack-top-frame"):N,x?J(l(r)):ne)}}()),K}var ge;function _e(){return ge||(ge=1,process.env.NODE_ENV==="production"?ue.exports=Te():ue.exports=Ae()),ue.exports}var he=_e();const y=()=>{},ve=s.createContext({ref:null,watch:y,actions:{reset:y,resetField:y,setValue:y,getValues:y,getErrors:y,getFieldStates:y,getFormStates:y,setError:y,clearError:y,clearErrors:y,checkValidity:y,getNumberFields:y,getFieldValidity:y,getDefaultValues:y,setFieldState:y,resetFieldState:y,getControlledFields:y},registerController:y,registerHookWatcher:y,lastReloadedAt:y,loadFormValues:y,getWatchValue:y,channels:{}}),fe=()=>s.useContext(ve),Oe=({id:n,control:t,method:c,action:l,children:a,onChange:f,onBlur:u,onSubmit:m=()=>{},onInput:E=()=>{},onReset:b=()=>{},numberFields:i=[],className:g,...v})=>{const A=s.useCallback(S=>{t.ref&&(t.ref.current=S,t.ref.current&&t.initForm())},[t]);return s.useEffect(()=>{let S=()=>{},C=()=>{};return f&&(S=t.channels.subscribe("onChange",f)),u&&(C=t.channels.subscribe("onBlur",u)),()=>{S(),C()}},[t.lastReloadedAt]),he.jsx(ve.Provider,{value:t,children:he.jsx("form",{id:n,ref:A,action:l,method:c,className:g,onInput:E,onSubmit:S=>{c||S.preventDefault();const C=t.loadFormValues();m(C)},onChange:S=>{const C=S.target.name;!C||t.actions.getControlledFields().has(C)||t.actions.setValue(C,S.target.value)},onBlur:S=>{const C=S.target.name;if(!C||t.actions.getControlledFields().has(C))return;const k=S.target.value;t.channels.publish("onBlur",C,k,t.actions.getValues())},onReset:S=>{t.actions.reset(),b(S)},...v,children:a},t.lastReloadedAt)})},ie={isDirty:!1,isTouched:!1,error:null},me={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},we={},je=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],P=(n={},t="")=>t.split(".").reduce((c,l)=>c&&c[l]!==void 0?c[l]:void 0,n),M=(n={},t="",c)=>{const l=Array.isArray(n)?[...n]:{...n};let a=l;const f=t.split(".");return f.forEach((u,m)=>{m<f.length-1?(a[u]||(a[u]=/^\d+$/.test(f[m+1])?[]:{}),Array.isArray(a[u])?a[u]=[...a[u]]:a[u]={...a[u]},a=a[u]):a[u]=c}),l},Ce=n=>{let t=Array.isArray(n)?[...n]:{...n};return Object.keys(t).forEach(c=>{if(c.includes(".")){const l=P(t,c);t=M(t,c,l||""),delete t[c]}}),t},Pe=["errors","fieldStates","formState"],q=n=>Pe.some(t=>n.startsWith(t))?n:"values."+n,Re=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let t=n.validity,c=je.find(l=>t[l]);if(c)return{type:c,message:n.validationMessage}},Se=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((l,a)=>{const f=(t||{})[a];return n.has(c+a)?[...l,...Se(n,f,c+a+".")]:f!=null&&f.isDirty?[...l,c+a]:l},[]),pe=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((l,a)=>{const f=(t||{})[a];return n.has(c+a)?[...l,...pe(n,f,c+a+".")]:f!=null&&f.isTouched?[...l,c+a]:l},[]),ye=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((l,a)=>{const f=(t||{})[a];return n.has(c+a)?[...l,...ye(n,f,c+a+".")]:f?[...l,c+a]:l},[]),Ne=({control:n,name:t,compute:c})=>{const{getWatchValue:l,registerHookWatcher:a}=n||fe(),f=l({name:t,compute:c}),[u,m]=s.useState(f);return s.useEffect(()=>a({name:t,compute:c,value:u,setValue:m}),[]),u},ke=({control:n,name:t,defaultValue:c})=>{const{actions:l,registerController:a,channels:f,getWatchValue:u}=n||fe(),m=s.useRef(),E=s.useRef(),b=P(l.getDefaultValues(),t)||c||"",[i,g]=s.useState(b),[v,A]=s.useState({}),S=s.useCallback((k,{shouldDirty:w=!0,shouldOnChange:I=!0}={})=>{var Y;let D=k;((Y=k==null?void 0:k.target)==null?void 0:Y.value)!==void 0&&(D=k.target.value),g(D),l.setValue(t,D,{shouldDirty:w,shouldOnChange:I})},[l.setValue]),C=s.useCallback(k=>{const w=l.getValues(),I=k??P(w,t);f.publish("onBlur",t,I,w)},[]);return s.useEffect(()=>{const k=a(t,g);return()=>{k(),E.current&&E.current()}},[]),new Proxy({ref:m,name:t,defaultValue:b,value:i,onChange:S,onBlur:C,fieldState:v},{get(k,w,I){return typeof w=="string"&&w==="fieldState"&&(E.current&&E.current(),E.current=l.subscribe(`fieldStates.${t}`,()=>{A(u({name:`fieldStates.${t}`}))})),Reflect.get(k,w,I)}})},De=({name:n,control:t,defaultValue:c,render:l=({ref:a,name:f,defaultValue:u,value:m,onChange:E,onBlur:b,fieldState:i})=>null})=>{const a=ke({name:n,defaultValue:c,control:t});return l(a)},xe=()=>{const[n,t]=s.useState(),c=s.useCallback(()=>t(new Date().toString()),[]);return[n,c]},$e=()=>{const[,n]=s.useState({});return s.useCallback(()=>n({}),[])},Me=({channels:n,getWatchValue:t})=>{const c=$e(),l=s.useCallback(u=>{if(!u)return n.subscribeWatch("values",()=>c()),t();if(typeof u=="string"){const m=q(u);n.subscribeWatch(m,(E,b)=>{E!==b&&c()})}return Array.isArray(u)&&u.forEach(m=>{const E=q(m);n.subscribeWatch(E,(b,i)=>{b!==i&&c()})}),t({name:u})},[]),a=s.useCallback(({name:u,compute:m,setValue:E})=>{if(typeof m=="function")return n.subscribe("values",()=>{const i=t({compute:m});E(i)});if(!u)return n.subscribe("values",()=>{E(t())});if(typeof u=="string"){const b=q(u);return n.subscribe(b,()=>{const g=t({name:u});E(g)})}if(Array.isArray(u)){const b=[];return u.forEach(i=>{const g=q(i),v=n.subscribe(g,()=>{const A=t({name:u});E(A)});b.push(v)}),()=>b.forEach(i=>i())}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),f=s.useCallback((u,m)=>{if(!u)return n.subscribe("values",()=>m(t()));if(["onChange","onBlur"].includes(u))return n.subscribe(u,m);if(typeof u=="string"){const E=q(u);return n.subscribe(E,()=>m(t({name:u})))}if(Array.isArray(u)){const E=[];return u.forEach(b=>{const i=q(b),g=n.subscribe(i,()=>{m(t({name:u}))});E.push(g)}),()=>E.forEach(b=>b())}throw new Error("Parameters of name must be string or array of string")},[]);return{watch:l,registerHookWatcher:a,getWatchValue:t,subscribe:f}},We=({getWatchValue:n})=>{const t=s.useRef(new Map),c=s.useRef(new Map),l=s.useCallback(()=>c.current,[]),a=s.useCallback(()=>t.current,[]),f=s.useCallback(()=>{t.current.clear(),c.current.clear()},[]),u=s.useCallback((i,...g)=>{const v=t.current.get(i),A=c.current.get(i);v&&v.forEach(S=>S(...g)),A&&A.forEach(S=>S(...g)),t.current.forEach((S,C)=>{if(C!==i&&i.startsWith(C)){const k=n({name:C.replace("values.","").replace("values","")});S.forEach(w=>w(M(k,i.replace(`${C}.`,""),g[0])))}}),c.current.forEach((S,C)=>{if(C!==i&&i.startsWith(C)){const k=n({name:C.replace("values.","").replace("values","")});S.forEach(w=>w(M(k,i.replace(`${C}.`,""),g[0])))}})},[]),m=s.useCallback(i=>{t.current.forEach((g,v)=>{v.startsWith(i)&&g.forEach(A=>A(n({name:v.replace("values.","").replace("values","")})))}),c.current.forEach((g,v)=>{v.startsWith(i)&&g.forEach(A=>A(n({name:v.replace("values.","").replace("values","")})))})},[]),E=s.useCallback((i,g)=>(t.current.has(i)||t.current.set(i,new Set),t.current.get(i).add(g),()=>{var v;return(v=t.current.get(i))==null?void 0:v.delete(g)}),[]),b=s.useCallback((i,g)=>{c.current.has(i)||(c.current.set(i,new Set),c.current.get(i).add(g))},[]);return{reset:f,publish:u,subscribe:E,subscribeWatch:b,getEvents:a,getWatchEvents:l,trigger:m}},Ie=({defaultValues:n=we,shouldUnRegister:t=!1,groups:c=[]}={})=>{const[l,a]=xe(),f=s.useRef(),u=s.useRef(new Map),m=s.useRef({}),E=s.useRef({}),b=s.useRef({...me}),i=s.useRef({...n}),g=s.useRef({...n}),v=s.useRef(new Set(c)),A=s.useCallback((e,o=g.current)=>Object.keys(o).reduce((h,R)=>{if(typeof o[R]=="object")return{...h,[R]:A(e,o[R])};const j={...e?{}:E.current[R]||{},...ie};return{...h,[R]:j}},{}),[]),S=s.useCallback((e={},{clearCustomFormStates:o=!1,clearCustomFieldStates:h=!1,groups:R=v.current}={})=>{g.current={...g.current,...e},i.current={...g.current},u.current.forEach((j,T)=>{j(P(g.current,T)??"")}),m.current={},v.current=new Set(R),u.current=new Map,b.current={...o?{}:b.current,...me},E.current=A(h),F.reset(),a()},[]),C=s.useCallback(()=>{let e=Object.fromEntries(new FormData(f.current));u.current.forEach((h,R)=>{e=M(e,R,P(i.current,R))});let o={...i.current,...e};return Ce(o)},[]),k=s.useCallback(e=>Re(e.target),[]),w=s.useCallback(()=>g.current,[]),I=s.useCallback(()=>u.current,[]),D=s.useCallback((e,o)=>o?Array.isArray(o)?o.reduce((h,R)=>({...h,[R]:P(e,R)}),{}):P(e,o):{...e},[]),Y=s.useCallback(e=>D(i.current,e),[D]),ce=s.useCallback(e=>D(m.current,e),[D]),ae=s.useCallback(e=>D(E.current,e),[D]),ee=s.useCallback(e=>D({...b.current,lastReset:l},e),[l]),L=s.useCallback(({name:e,compute:o}={})=>!e&&!o||e==="values"?Y():typeof o=="function"?o(Y()):Array.isArray(e)?e.reduce((h,R)=>({...h,[R]:L({name:R})}),{}):P({...i.current,errors:m.current,fieldStates:E.current,formState:ee()},e),[]),F=We({getWatchValue:L}),{watch:re,registerHookWatcher:H,subscribe:te}=Me({getWatchValue:L,channels:F}),le=s.useCallback((e,o)=>{const h=b.current,R=P(h,e);R!==o&&(b.current=M(b.current,e,o),F.publish(`formState.${e}`,o,R))},[]),J=s.useCallback((e,o)=>{N(e,"error",o)},[]),G=s.useCallback(e=>{N(e,"error",null)},[]),se=s.useCallback(()=>{b.current.isError&&Object.keys(m.current).forEach(e=>G(e))},[]),N=s.useCallback((e,o,h)=>{try{if(typeof h=="function"&&(h=h(L({name:e}))),v.current.has(e))if(typeof h=="object"&&h!==null){Object.keys(h).forEach(T=>{N(`${e}.${T}`,o,h[T])});return}else return console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);const R=P(E.current,e)||{...ie},j=P(R,o);if(j!==h){if(E.current=M(E.current,`${e}.${o}`,h),F.publish(`fieldStates.${e}.${o}`,h,j),o==="error"){const T=P(m.current,e),V=h||null;T!==V&&(m.current=M(m.current,e,V),F.publish(`errors.${e}`,V,T));const $=ye(v.current,m.current);b.current.errorFields=$,F.publish("formState.errorFields",$);const z=$.length>0;if(b.current.isError!==z){const de=b.current.isError;b.current.isError=z,F.publish("formState.isError",z,de)}}if(o==="isDirty"){const T=Se(v.current,E.current);b.current.dirtyFields=T,F.publish("formState.dirtyFields",T);const V=T.length>0;if(b.current.isDirty!==V){const $=b.current.isDirty;b.current.isDirty=V,F.publish("formState.isDirty",V,$)}}if(o==="isTouched"){const T=pe(v.current,E.current);b.current.touchedFields=T,F.publish("formState.touchedFields",T)}}}catch(R){console.log(R)}},[]),ne=s.useCallback(e=>{N(e,"isDirty",!1),N(e,"isTouched",!1),N(e,"error",!1)},[]),oe=s.useCallback(e=>{const o=Re(e.target);o?J(e.target.name,o):G(e.target.name)},[]),r=s.useCallback((e,o,{shouldDirty:h=!0,shouldOnChange:R=!0}={})=>{if(typeof o=="function"&&(o=o(Y(e))),v.current.has(e)){typeof o=="object"&&o!==null?Object.keys(o).forEach($=>{r(`${e}.${$}`,o[$],{shouldDirty:h,shouldOnChange:R})}):console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);return}const j=P(i.current,e);if(o===j)return;i.current=M(i.current,e,o),F.publish(`values.${e}`,o,j);const T=u.current.get(e);if(T&&T(o),e.includes(".")){const $=e.split("."),z=$.findIndex((de,Fe)=>!v.current.has($.slice(0,Fe+1).join(".")));z!==-1&&(e=$.slice(0,z+1).join("."))}o&&N(e,"isTouched",!0);const V=o!==(P(g.current,e)||"");h&&N(e,"isDirty",V),R&&F.publish("onChange",e,o,j)},[]),d=s.useCallback(e=>{const o=e.split(".");let h="";o.forEach((R,j)=>{j<o.length-1&&(h=h?`${h}.${R}`:R,v.current.add(h))})},[]),p=s.useCallback(e=>{Array.isArray(e)?e.forEach(o=>d(o+".")):d(e+".")},[]),O=s.useCallback((e="",o)=>(u.current.set(e,o),E.current=M(E.current,e,{...ie}),e.includes(".")&&d(e),()=>{t&&u.current.delete(e)}),[]),W=s.useCallback((e,{keepError:o,keepDirty:h,keepTouched:R,defaultValue:j})=>{const T=u.current.get(e);if(!T)throw new Error(`Cannot reset "${e}" because it's uncontrolled field`);g.current=M(g.current,e,j),i.current=M(i.current,e,j),T&&T(j),o||G(e),h||N(e,"isDirty",!1),R||N(e,"isTouched",!1)},[]),x=s.useCallback(e=>{if(!e)return F.trigger("values");if(!Array.isArray(e)){const o=q(e);F.trigger(o);return}e.forEach(o=>{const h=q(o);F.trigger(h)})},[]),X=s.useCallback((e,o=B.getValues(e))=>{F.publish("onBlur",e,o,B.getValues())},[]),B=s.useMemo(()=>({subscribe:te,reset:S,trigger:x,reload:a,resetField:W,setValue:r,getValues:Y,getErrors:ce,getFieldStates:ae,getFormState:ee,setError:J,clearError:G,clearErrors:se,checkValidity:oe,getFieldValidity:k,getDefaultValues:w,setFieldState:N,triggerFieldBlur:X,resetFieldState:ne,getControlledFields:I,setFormState:le,getEvents:F.getEvents,getWatchEvents:F.getWatchEvents,addGroups:p}),[l]),_=s.useCallback(()=>{[...f.current.querySelectorAll("[name]")].forEach(h=>{const R=h.name||"";R.includes(".")&&d(R),!h.defaultValue&&!u.current.has(R)&&P(g.current,R)&&(h.defaultValue=P(g.current,R))});const o=C();i.current={...o},g.current={...o}},[]),U=s.useMemo(()=>({ref:f,watch:re,actions:B,initForm:_,registerController:O,registerHookWatcher:H,lastReloadedAt:l,loadFormValues:C,getWatchValue:L,channels:F}),[l]),Z=s.useMemo(()=>({control:U,actions:B,watch:re}),[l]);return s.useLayoutEffect(()=>{f.current&&_()},[l]),s.useLayoutEffect(()=>{E.current=A(!1)},[]),Z};exports.Controller=De;exports.Form=Oe;exports.restoreFromDotNotation=Ce;exports.useController=ke;exports.useForm=Ie;exports.useFormContext=fe;exports.useWatch=Ne;
|
|
22
|
+
<%s key={someKey} {...props} />`,O,_,U,_),ue[_+O]=!0)}if(_=null,p!==void 0&&(c(p),_=""+p),u(b)&&(c(b.key),_=""+b.key),"key"in b){p={};for(var Q in b)Q!=="key"&&(p[Q]=b[Q])}else p=b;return _&&h(p,typeof r=="function"?r.displayName||r.name||"Unknown":r),d(r,_,x,Y,a(),p,Z,B)}function g(r){typeof r=="object"&&r!==null&&r.$$typeof===T&&r._store&&(r._store.validated=1)}var v=s,T=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),M=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),P=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),ae=Symbol.for("react.suspense_list"),re=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),te=Symbol.for("react.client.reference"),X=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,se=Object.prototype.hasOwnProperty,le=Array.isArray,z=console.createTask?console.createTask:function(){return null};v={"react-stack-bottom-frame":function(r){return r()}};var G,ne={},N=v["react-stack-bottom-frame"].bind(v,f)(),oe=z(i(f)),ue={};ee.Fragment=C,ee.jsx=function(r,b,p,O,Y){var x=1e4>X.recentlyCreatedOwnerStacks++;return l(r,b,p,!1,O,Y,x?Error("react-stack-top-frame"):N,x?z(i(r)):oe)},ee.jsxs=function(r,b,p,O,Y){var x=1e4>X.recentlyCreatedOwnerStacks++;return l(r,b,p,!0,O,Y,x?Error("react-stack-top-frame"):N,x?z(i(r)):oe)}}()),ee}var ge;function _e(){return ge||(ge=1,process.env.NODE_ENV==="production"?ce.exports=Te():ce.exports=Ae()),ce.exports}var he=_e();const y=()=>{},ve=s.createContext({ref:null,watch:y,actions:{reset:y,resetField:y,setValue:y,getValues:y,getErrors:y,getFieldStates:y,getFormStates:y,setError:y,clearError:y,clearErrors:y,checkValidity:y,getNumberFields:y,getFieldValidity:y,getDefaultValues:y,setFieldState:y,resetFieldState:y,getControlledFields:y},registerController:y,registerHookWatcher:y,lastReloadedAt:y,loadFormValues:y,getWatchValue:y,channels:{}}),fe=()=>s.useContext(ve),Oe=({id:n,control:t,method:c,action:i,children:a,onChange:f,onBlur:u,onSubmit:h=()=>{},onInput:R=()=>{},onReset:d=()=>{},numberFields:l=[],className:g,...v})=>{const T=s.useCallback(S=>{t.ref&&(t.ref.current=S,t.ref.current&&t.initForm())},[t]);return s.useEffect(()=>{let S=()=>{},C=()=>{};return f&&(S=t.channels.subscribe("onChange",f)),u&&(C=t.channels.subscribe("onBlur",u)),()=>{S(),C()}},[t.lastReloadedAt]),he.jsx(ve.Provider,{value:t,children:he.jsx("form",{id:n,ref:T,action:i,method:c,className:g,onInput:R,onSubmit:S=>{c||S.preventDefault();const C=t.loadFormValues();h(C)},onChange:S=>{const C=S.target.name;!C||t.actions.getControlledFields().has(C)||t.actions.setValue(C,S.target.value)},onBlur:S=>{const C=S.target.name;if(!C||t.actions.getControlledFields().has(C))return;const M=S.target.value;t.channels.publish("onBlur",C,M,t.actions.getValues())},onReset:S=>{t.actions.reset(),d(S)},...v,children:a},t.lastReloadedAt)})},ie={isDirty:!1,isTouched:!1,error:null},me={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},we={},je=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],j=(n={},t="")=>t.split(".").reduce((c,i)=>c&&c[i]!==void 0?c[i]:void 0,n),W=(n={},t="",c)=>{const i=Array.isArray(n)?[...n]:{...n};let a=i;const f=t.split(".");return f.forEach((u,h)=>{h<f.length-1?(a[u]||(a[u]=/^\d+$/.test(f[h+1])?[]:{}),Array.isArray(a[u])?a[u]=[...a[u]]:a[u]={...a[u]},a=a[u]):a[u]=c}),i},Ce=n=>{let t=Array.isArray(n)?[...n]:{...n};return Object.keys(t).forEach(c=>{if(c.includes(".")){const i=j(t,c);t=W(t,c,i||""),delete t[c]}}),t},Pe=["errors","fieldStates","formState"],q=n=>Pe.some(t=>n.startsWith(t))?n:"values."+n,Re=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let t=n.validity,c=je.find(i=>t[i]);if(c)return{type:c,message:n.validationMessage}},Se=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((i,a)=>{const f=(t||{})[a];return n.has(c+a)?[...i,...Se(n,f,c+a+".")]:f!=null&&f.isDirty?[...i,c+a]:i},[]),pe=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((i,a)=>{const f=(t||{})[a];return n.has(c+a)?[...i,...pe(n,f,c+a+".")]:f!=null&&f.isTouched?[...i,c+a]:i},[]),ye=(n=new Set,t={},c="")=>Object.keys(t||{}).reduce((i,a)=>{const f=(t||{})[a];return n.has(c+a)?[...i,...ye(n,f,c+a+".")]:f?[...i,c+a]:i},[]),ke=({control:n,name:t,defaultValue:c,shouldUnRegister:i})=>{const{actions:a,registerController:f,channels:u,getWatchValue:h}=n||fe(),R=s.useRef(),d=s.useRef(),l=j(a.getDefaultValues(),t)||c||"",[g,v]=s.useState(l),[T,S]=s.useState({}),C=s.useCallback((A,{shouldDirty:D=!0,shouldOnChange:P=!0}={})=>{var J;let I=A;((J=A==null?void 0:A.target)==null?void 0:J.value)!==void 0&&(I=A.target.value),v(I),a.setValue(t,I,{shouldDirty:D,shouldOnChange:P})},[a.setValue]),M=s.useCallback(A=>{const D=a.getValues(),P=A??j(D,t);u.publish("onBlur",t,P,D)},[]);return s.useEffect(()=>{const A=f(t,v,{shouldUnRegister:i});return()=>{A(),d.current&&d.current()}},[i]),new Proxy({ref:R,name:t,defaultValue:l,value:g,onChange:C,onBlur:M,fieldState:T},{get(A,D,P){return typeof D=="string"&&D==="fieldState"&&(d.current&&d.current(),d.current=a.subscribe(`fieldStates.${t}`,()=>{S(h({name:`fieldStates.${t}`}))})),Reflect.get(A,D,P)}})},Ne=({name:n,control:t,shouldUnRegister:c,defaultValue:i,render:a=({ref:f,name:u,defaultValue:h,value:R,onChange:d,onBlur:l,fieldState:g})=>null})=>{const f=ke({name:n,defaultValue:i,shouldUnRegister:c,control:t});return a(f)},De=()=>{const[n,t]=s.useState(),c=s.useCallback(()=>t(new Date().toString()),[]);return[n,c]},xe=()=>{const[,n]=s.useState({});return s.useCallback(()=>n({}),[])},$e=({channels:n,getWatchValue:t})=>{const c=xe(),i=s.useCallback(u=>{if(!u)return n.subscribeWatch("values",()=>c()),t();if(typeof u=="string"){const h=q(u);n.subscribeWatch(h,(R,d)=>{R!==d&&c()})}return Array.isArray(u)&&u.forEach(h=>{const R=q(h);n.subscribeWatch(R,(d,l)=>{d!==l&&c()})}),t({name:u})},[]),a=s.useCallback(({name:u,compute:h,setValue:R})=>{if(typeof h=="function")return n.subscribe("values",()=>{const l=t({compute:h});R(l)});if(!u)return n.subscribe("values",()=>{R(t())});if(typeof u=="string"){const d=q(u);return n.subscribe(d,()=>{const g=t({name:u});R(g)})}if(Array.isArray(u)){const d=[];return u.forEach(l=>{const g=q(l),v=n.subscribe(g,()=>{const T=t({name:u});R(T)});d.push(v)}),()=>d.forEach(l=>l())}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),f=s.useCallback((u,h)=>{if(!u)return n.subscribe("values",()=>h(t()));if(["onChange","onBlur"].includes(u))return n.subscribe(u,h);if(typeof u=="string"){const R=q(u);return n.subscribe(R,()=>h(t({name:u})))}if(Array.isArray(u)){const R=[];return u.forEach(d=>{const l=q(d),g=n.subscribe(l,()=>{h(t({name:u}))});R.push(g)}),()=>R.forEach(d=>d())}throw new Error("Parameters of name must be string or array of string")},[]);return{watch:i,registerHookWatcher:a,getWatchValue:t,subscribe:f}},Me=({getWatchValue:n})=>{const t=s.useRef(new Map),c=s.useRef(new Map),i=s.useCallback(()=>c.current,[]),a=s.useCallback(()=>t.current,[]),f=s.useCallback(()=>{t.current.clear(),c.current.clear()},[]),u=s.useCallback((l,...g)=>{const v=t.current.get(l),T=c.current.get(l);v&&v.forEach(S=>S(...g)),T&&T.forEach(S=>S(...g)),t.current.forEach((S,C)=>{if(C!==l&&l.startsWith(C)){const M=n({name:C.replace("values.","").replace("values","")});S.forEach(A=>A(W(M,l.replace(`${C}.`,""),g[0])))}}),c.current.forEach((S,C)=>{if(C!==l&&l.startsWith(C)){const M=n({name:C.replace("values.","").replace("values","")});S.forEach(A=>A(W(M,l.replace(`${C}.`,""),g[0])))}})},[]),h=s.useCallback(l=>{t.current.forEach((g,v)=>{v.startsWith(l)&&g.forEach(T=>T(n({name:v.replace("values.","").replace("values","")})))}),c.current.forEach((g,v)=>{v.startsWith(l)&&g.forEach(T=>T(n({name:v.replace("values.","").replace("values","")})))})},[]),R=s.useCallback((l,g)=>(t.current.has(l)||t.current.set(l,new Set),t.current.get(l).add(g),()=>{var v;return(v=t.current.get(l))==null?void 0:v.delete(g)}),[]),d=s.useCallback((l,g)=>{c.current.has(l)||(c.current.set(l,new Set),c.current.get(l).add(g))},[]);return{reset:f,publish:u,subscribe:R,subscribeWatch:d,getEvents:a,getWatchEvents:i,trigger:h}},We=({defaultValues:n=we,shouldUnRegister:t=!1,groups:c=[]}={})=>{const[i,a]=De(),f=s.useRef(),u=s.useRef(new Map),h=s.useRef({}),R=s.useRef({}),d=s.useRef({...me}),l=s.useRef({...n}),g=s.useRef({...n}),v=s.useRef(new Set(c)),T=s.useCallback((e,o=g.current)=>Object.keys(o).reduce((E,m)=>{if(typeof o[m]=="object")return{...E,[m]:T(e,o[m])};const w={...e?{}:R.current[m]||{},...ie};return{...E,[m]:w}},{}),[]),S=s.useCallback((e={},{clearCustomFormStates:o=!1,clearCustomFieldStates:E=!1,groups:m=v.current}={})=>{g.current={...g.current,...e},l.current={...g.current},u.current.forEach((w,F)=>{w(j(g.current,F)??"")}),h.current={},v.current=new Set(m),u.current=new Map,d.current={...o?{}:d.current,...me},R.current=T(E),k.reset(),a()},[]),C=s.useCallback(()=>{let e=Object.fromEntries(new FormData(f.current));u.current.forEach((E,m)=>{e=W(e,m,j(l.current,m))});let o={...l.current,...e};return Ce(o)},[]),M=s.useCallback(e=>Re(e.target),[]),A=s.useCallback(()=>g.current,[]),D=s.useCallback(()=>u.current,[]),P=s.useCallback((e,o)=>o?Array.isArray(o)?o.reduce((E,m)=>({...E,[m]:j(e,m)}),{}):j(e,o):{...e},[]),I=s.useCallback(e=>P(l.current,e),[P]),J=s.useCallback(e=>P(h.current,e),[P]),ae=s.useCallback(e=>P(R.current,e),[P]),re=s.useCallback(e=>P({...d.current,lastReset:i},e),[i]),L=s.useCallback(({name:e,compute:o}={})=>!e&&!o||e==="values"?I():typeof o=="function"?o(I()):Array.isArray(e)?e.reduce((E,m)=>({...E,[m]:L({name:m})}),{}):j({...l.current,errors:h.current,fieldStates:R.current,formState:re()},e),[]),k=Me({getWatchValue:L}),{watch:te,registerHookWatcher:X,subscribe:se}=$e({getWatchValue:L,channels:k}),le=s.useCallback((e,o)=>{const E=d.current,m=j(E,e);m!==o&&(d.current=W(d.current,e,o),k.publish(`formState.${e}`,o,m))},[]),z=s.useCallback((e,o)=>{N(e,"error",o)},[]),G=s.useCallback(e=>{N(e,"error",null)},[]),ne=s.useCallback(()=>{d.current.isError&&Object.keys(h.current).forEach(e=>G(e))},[]),N=s.useCallback((e,o,E)=>{try{if(typeof E=="function"&&(E=E(L({name:e}))),v.current.has(e))if(typeof E=="object"&&E!==null){Object.keys(E).forEach(F=>{N(`${e}.${F}`,o,E[F])});return}else return console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);const m=j(R.current,e)||{...ie},w=j(m,o);if(w!==E){if(R.current=W(R.current,`${e}.${o}`,E),k.publish(`fieldStates.${e}.${o}`,E,w),o==="error"){const F=j(h.current,e),V=E||null;F!==V&&(h.current=W(h.current,e,V),k.publish(`errors.${e}`,V,F));const $=ye(v.current,h.current);d.current.errorFields=$,k.publish("formState.errorFields",$);const H=$.length>0;if(d.current.isError!==H){const de=d.current.isError;d.current.isError=H,k.publish("formState.isError",H,de)}}if(o==="isDirty"){const F=Se(v.current,R.current);d.current.dirtyFields=F,k.publish("formState.dirtyFields",F);const V=F.length>0;if(d.current.isDirty!==V){const $=d.current.isDirty;d.current.isDirty=V,k.publish("formState.isDirty",V,$)}}if(o==="isTouched"){const F=pe(v.current,R.current);d.current.touchedFields=F,k.publish("formState.touchedFields",F)}}}catch(m){console.log(m)}},[]),oe=s.useCallback(e=>{N(e,"isDirty",!1),N(e,"isTouched",!1),N(e,"error",!1)},[]),ue=s.useCallback(e=>{const o=Re(e.target);o?z(e.target.name,o):G(e.target.name)},[]),r=s.useCallback((e,o,{shouldDirty:E=!0,shouldOnChange:m=!0}={})=>{if(typeof o=="function"&&(o=o(I(e))),v.current.has(e)){typeof o=="object"&&o!==null?Object.keys(o).forEach($=>{r(`${e}.${$}`,o[$],{shouldDirty:E,shouldOnChange:m})}):console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);return}const w=j(l.current,e);if(o===w)return;l.current=W(l.current,e,o),k.publish(`values.${e}`,o,w);const F=u.current.get(e);if(F&&F(o),e.includes(".")){const $=e.split("."),H=$.findIndex((de,Fe)=>!v.current.has($.slice(0,Fe+1).join(".")));H!==-1&&(e=$.slice(0,H+1).join("."))}o&&N(e,"isTouched",!0);const V=o!==(j(g.current,e)||"");E&&N(e,"isDirty",V),m&&k.publish("onChange",e,o,w)},[]),b=s.useCallback(e=>{const o=e.split(".");let E="";o.forEach((m,w)=>{w<o.length-1&&(E=E?`${E}.${m}`:m,v.current.add(E))})},[]),p=s.useCallback(e=>{Array.isArray(e)?e.forEach(o=>b(o+".")):b(e+".")},[]),O=s.useCallback((e="",o,{shouldUnRegister:E=t}={})=>{if(!e){console.error("Controller must have a name");return}return u.current.set(e,o),R.current=W(R.current,e,{...ie}),e.includes(".")&&b(e),()=>{E&&u.current.delete(e)}},[]),Y=s.useCallback((e,{keepError:o,keepDirty:E,keepTouched:m,defaultValue:w})=>{const F=u.current.get(e);if(!F)throw new Error(`Cannot reset "${e}" because it's uncontrolled field`);g.current=W(g.current,e,w),l.current=W(l.current,e,w),F&&F(w),o||G(e),E||N(e,"isDirty",!1),m||N(e,"isTouched",!1)},[]),x=s.useCallback(e=>{if(!e)return k.trigger("values");if(!Array.isArray(e)){const o=q(e);k.trigger(o);return}e.forEach(o=>{const E=q(o);k.trigger(E)})},[]),Z=s.useCallback((e,o=B.getValues(e))=>{k.publish("onBlur",e,o,B.getValues())},[]),B=s.useMemo(()=>({subscribe:se,reset:S,trigger:x,reload:a,resetField:Y,setValue:r,getValues:I,getErrors:J,getFieldStates:ae,getFormState:re,setError:z,clearError:G,clearErrors:ne,checkValidity:ue,getFieldValidity:M,getDefaultValues:A,setFieldState:N,triggerFieldBlur:Z,resetFieldState:oe,getControlledFields:D,setFormState:le,getEvents:k.getEvents,getWatchEvents:k.getWatchEvents,addGroups:p}),[i]),_=s.useCallback(()=>{[...f.current.querySelectorAll("[name]")].forEach(E=>{const m=E.name||"";m.includes(".")&&b(m),!E.defaultValue&&!u.current.has(m)&&j(g.current,m)&&(E.defaultValue=j(g.current,m))});const o=C();l.current={...o},g.current={...o}},[]),U=s.useMemo(()=>({ref:f,watch:te,actions:B,initForm:_,registerController:O,registerHookWatcher:X,lastReloadedAt:i,loadFormValues:C,getWatchValue:L,channels:k}),[i]),Q=s.useMemo(()=>({control:U,actions:B,watch:te}),[i]);return s.useLayoutEffect(()=>{f.current&&_()},[i]),s.useLayoutEffect(()=>{R.current=T(!1)},[]),Q},Ie=({control:n,name:t,compute:c})=>{const{getWatchValue:i,registerHookWatcher:a}=n||fe(),f=i({name:t,compute:c}),[u,h]=s.useState(f);return s.useEffect(()=>a({name:t,compute:c,value:u,setValue:h}),[]),u};exports.Controller=Ne;exports.Form=Oe;exports.restoreFromDotNotation=Ce;exports.useController=ke;exports.useForm=We;exports.useFormContext=fe;exports.useWatch=Ie;
|