react-simple-formkit 2.1.9 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -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
|
|
9
|
+
*/var ce;function ge(){if(ce)return ee;ce=1;var n=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function l(g,b,h){var E=null;if(h!==void 0&&(E=""+h),b.key!==void 0&&(E=""+b.key),"key"in b){h={};for(var y in b)y!=="key"&&(h[y]=b[y])}else h=b;return b=h.ref,{$$typeof:n,type:g,key:E,ref:b!==void 0?b:null,props:h}}return ee.Fragment=o,ee.jsx=l,ee.jsxs=l,ee}var re={};/**
|
|
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
|
|
17
|
+
*/var le;function he(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){function n(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 m:return"Fragment";case $:return"Profiler";case A:return"StrictMode";case te:return"Suspense";case se:return"SuspenseList";case j: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 f:return"Portal";case U:return(e.displayName||"Context")+".Provider";case D:return(e._context.displayName||"Context")+".Consumer";case q:var u=e.render;return e=e.displayName,e||(e=u.displayName||u.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ne:return u=e.displayName||null,u!==null?u:n(e.type)||"Memo";case J:u=e._payload,e=e._init;try{return n(e(u))}catch{}}return null}function o(e){return""+e}function l(e){try{o(e);var u=!1}catch{u=!0}if(u){u=console;var R=u.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return R.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),o(e)}}function g(e){if(e===m)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===J)return"<...>";try{var u=n(e);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function b(){var e=x.A;return e===null?null:e.getOwner()}function h(){return Error("react-stack-top-frame")}function E(e){if(W.call(e,"key")){var u=Object.getOwnPropertyDescriptor(e,"key").get;if(u&&u.isReactWarning)return!1}return e.key!==void 0}function y(e,u){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)",u))}R.isReactWarning=!0,Object.defineProperty(e,"key",{get:R,configurable:!0})}function v(){var e=n(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 T(e,u,R,p,O,w,Y,I){return R=w.ref,e={$$typeof:a,type:e,key:u,props:w,_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:Y}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function c(e,u,R,p,O,w,Y,I){var k=u.children;if(k!==void 0)if(p)if(N(k)){for(p=0;p<k.length;p++)d(k[p]);Object.freeze&&Object.freeze(k)}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(k);if(W.call(u,"key")){k=n(e);var P=Object.keys(u).filter(function(r){return r!=="key"});p=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",Z[k+p]||(P=0<P.length?"{"+P.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,k,P,k),Z[k+p]=!0)}if(k=null,R!==void 0&&(l(R),k=""+R),E(u)&&(l(u.key),k=""+u.key),"key"in u){R={};for(var Q in u)Q!=="key"&&(R[Q]=u[Q])}else R=u;return k&&y(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,k,w,O,b(),R,Y,I)}function d(e){typeof e=="object"&&e!==null&&e.$$typeof===a&&e._store&&(e._store.validated=1)}var f=s,a=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),U=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),J=Symbol.for("react.lazy"),j=Symbol.for("react.activity"),z=Symbol.for("react.client.reference"),x=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,N=Array.isArray,V=console.createTask?console.createTask:function(){return null};f={"react-stack-bottom-frame":function(e){return e()}};var G,H={},X=f["react-stack-bottom-frame"].bind(f,h)(),C=V(g(h)),Z={};re.Fragment=m,re.jsx=function(e,u,R,p,O){var w=1e4>x.recentlyCreatedOwnerStacks++;return c(e,u,R,!1,p,O,w?Error("react-stack-top-frame"):X,w?V(g(e)):C)},re.jsxs=function(e,u,R,p,O){var w=1e4>x.recentlyCreatedOwnerStacks++;return c(e,u,R,!0,p,O,w?Error("react-stack-top-frame"):X,w?V(g(e)):C)}}()),re}var le;function he(){return le||(le=1,process.env.NODE_ENV==="production"?oe.exports=Ee():oe.exports=ge()),oe.exports}var ie=he();const S=()=>{},be=s.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:{}}),ue=()=>s.useContext(be),Re=({id:n,control:o,method:l,action:g,children:b,onSubmit:h=()=>{},onInput:E=()=>{},onChange:y=()=>{},onBlur:v=()=>{},onReset:T=()=>{},numberFields:c=[],className:d,...f})=>(s.useEffect(()=>{const a=o.channels.subscribe("onChange",y),i=o.channels.subscribe("onBlur",v);return()=>{a(),i()}},[]),ie.jsx(be.Provider,{value:o,children:ie.jsx("form",{id:n,ref:o.ref,action:g,method:l,className:d,onInput:E,onSubmit:a=>{l||a.preventDefault();const i=o.loadFormValues();h(i)},onChange:a=>{const i=a.target.name;o.actions.getControlledFields().has(i)||o.actions.setValue(i,a.target.value)},onBlur:a=>{const i=a.target.name;if(o.actions.getControlledFields().has(i))return;const m=a.target.value;o.channels.publish("onBlur",i,m,o.actions.getValues())},onReset:a=>{o.actions.reset(),T(a)},...f,children:b},o.lastReloadedAt)})),de=({control:n,name:o,compute:l})=>{const{getWatchValue:g,registerHookWatcher:b}=n||ue(),h=g({name:o,compute:l}),[E,y]=s.useState(h);return s.useEffect(()=>{const v=b({name:o,compute:l,value:E,setValue:y});return()=>v.forEach(T=>T())},[]),E},me=({name:n,defaultValue:o})=>{const{actions:l,registerController:g,channels:b}=ue(),h=s.useRef(),E=l.getDefaultValues()[n]||o,[y,v]=s.useState(E),T=de({name:`fieldStates.${n}.customState`}),c=s.useCallback(a=>{l.setFieldState(n,"customState",a)},[]),d=s.useCallback((a,{shouldDirty:i=!0,shouldOnChange:m=!0}={})=>{v(a),l.setValue(n,a,{shouldDirty:i,shouldOnChange:m})},[l.setValue]),f=s.useCallback(()=>{b.publish("onBlur",n,y,l.getValues())},[]);return s.useEffect(()=>g(n,v),[]),{ref:h,name:n,defaultValue:E,value:y,onChange:d,onBlur:f,customState:T,setCustomState:c}},ke=({name:n,defaultValue:o,render:l=({ref:g,name:b,defaultValue:h,value:E,onChange:y,onBlur:v,customState:T,setCustomState:c})=>null})=>{const g=me({name:n,defaultValue:o});return l(g)},Se=["errors","fieldStates","formState"],L=n=>Se.some(o=>n.startsWith(o))?n:"values."+n,Ce=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],fe=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let o=n.validity,l=Ce.find(g=>o[g]);if(l)return{type:l,message:n.validationMessage}};class ye{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,l){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(l),()=>{var g;return(g=this.events.get(o))==null?void 0:g.delete(l)}}publish(o,...l){const g=this.events.get(o);g&&g.forEach(b=>b(...l)),this.events.forEach((b,h)=>{o.includes(h)&&b.forEach(E=>E(...l))})}reset(){this.events.clear()}}const ve=()=>{const n=s.useRef(new ye),o=s.useCallback((b,...h)=>{n.current.publish(b,...h)},[]),l=s.useCallback((b,h)=>n.current.subscribe(b,h),[]),g=s.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:l,reset:g}},pe=()=>{const[n,o]=s.useState(),l=s.useCallback(()=>o(new Date().toString()),[]);return[n,l]},Fe=()=>{const[,n]=s.useState({});return s.useCallback(()=>n({}),[])},Te=({channels:n,getValues:o,getErrors:l,getFieldStates:g,getFormState:b})=>{const h=Fe(),E=s.useCallback(({name:c,compute:d})=>{if(typeof d=="function")return d(o());if(Array.isArray(c)){const f={};return c.forEach(a=>{f[a]=E({name:a})}),f}return c.split(".").reduce((f,a)=>f&&f[a]!==void 0?f[a]:void 0,{...o(),errors:{...l()},formState:{...b()},fieldStates:{...g()}})},[]),y=s.useCallback(c=>{if(!c)return n.subscribe("values",()=>h()),o();if(typeof c=="string"){const d=L(c);return n.subscribe(d,()=>h()),E({name:c})}if(Array.isArray(c)){const d={};return c.forEach(f=>{const a=L(f);n.subscribe(a,()=>h()),d[f]=E({name:f})}),{...d}}throw new Error("Parameters of watch must be string or array of string")},[]),v=s.useCallback(({name:c,compute:d,value:f,setValue:a})=>{if(typeof d=="function")return[n.subscribe("values",()=>{const m=E({compute:d});a(m)})];if(!c)return[n.subscribe("values",()=>{a(o())})];if(typeof c=="string"){const i=L(c);return[n.subscribe(i,()=>{const A=E({name:c});a(A)})]}if(Array.isArray(c)){const i=E({name:c}),m=[];return c.forEach(A=>{const $=L(A),D=n.subscribe($,()=>{const U=E({name:A});i[A]=U,a({...i})});m.push(D)}),m}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),T=s.useCallback((c,d)=>{if(!c)return n.subscribe("values",d);if(typeof c=="string"){const f=L(c);return n.subscribe(f,d)}if(Array.isArray(c)){const f={},a=[];return c.forEach(i=>{const m=L(i),A=n.subscribe(m,()=>{f[i]=E({name:i}),d({...f})});a.push(A)}),a}throw new Error("Parameters of name must be string or array of string")},[n]);return{watch:y,registerHookWatcher:v,getWatchValue:E,subscribe:T}},_e=[],we={},Ae=({numberFields:n=_e,defaultValues:o=we,shouldUnRegister:l=!1,shouldConvertNumber:g=!1}={})=>{const[b,h]=pe(),E=s.useRef(),y=s.useRef(!1),v=s.useRef(!1),T=s.useRef(n),c=s.useRef(new Map),d=s.useRef({}),f=s.useRef({}),a=s.useRef(o),i=s.useRef(o),m=ve(),A=s.useCallback(()=>{f.current=Object.keys(i.current).reduce((r,t)=>({...r,[t]:{isError:!1,isDirty:!1,isTouched:!1,customState:null}}),{})},[]),$=s.useCallback((r={})=>{i.current={...i.current,...r},a.current={...i.current},c.current.forEach((t,F)=>{t(i.current[F])}),y.current=!1,d.current={},T.current=n,c.current=new Map,m.reset(),A(),n.length>0&&(g=!0),h()},[]),D=s.useCallback(()=>{const r=Object.fromEntries(new FormData(E.current));return c.current.forEach((F,_)=>{r[_]=a.current[_]}),g&&T.current.forEach(F=>r.hasOwnProperty(F)&&(r[F]=Number(r[F])||0)),r},[]),U=s.useCallback(()=>!!Object.values(W()).find(r=>r.isDirty),[]),q=s.useCallback(()=>!!Object.values(x()).find(r=>!!r),[]),te=s.useCallback(r=>fe(r.target),[]),se=s.useCallback(()=>i.current,[]),ne=s.useCallback(()=>T.current,[]),J=s.useCallback(()=>c.current,[]),j=s.useCallback((r,t)=>t?Array.isArray(t)?t.map(F=>r[F]):r[t]:{...r},[]),z=s.useCallback(r=>j(a.current,r),[j]),x=s.useCallback(r=>j(d.current,r),[j]),W=s.useCallback(r=>j(f.current,r),[j]),N=s.useCallback(r=>j({isDirty:y.current,isError:v.current,errorFields:Object.keys(d.current).filter(t=>!!d.current[t]),dirtyFields:Object.keys(f.current).filter(t=>f.current[t].isDirty),touchedFields:Object.keys(f.current).filter(t=>f.current[t].isTouched)},r),[j]),{watch:V,registerHookWatcher:G,getWatchValue:H,subscribe:X}=Te({channels:m,getValues:z,getErrors:x,getFieldStates:W,getFormState:N}),C=s.useCallback((r,t,F)=>{const _=f.current[r];_[t]!==F&&(f.current[r]={..._,[t]:F},m.publish(`fieldStates.${r}.${t}`,F),t==="isError"&&m.publish("formState.errorFields",N("errorFields")),t==="isDirty"&&m.publish("formState.dirtyFields",N("dirtyFields")),t==="isTouched"&&m.publish("formState.touchedFields",N("touchedFields")))},[]),Z=s.useCallback(r=>{C(r,"isError",!1),C(r,"isDirty",!1),C(r,"isTouched",!1),C(r,"customState",null)},[C]),e=s.useCallback((r,t)=>{if(d.current[r]===t)return;d.current[r]=t,C(r,"isError",!!t),m.publish(`errors.${r}`,t);const _=q();v.current!==_&&(v.current=_,m.publish("formState.isError",_))},[C]),u=s.useCallback(r=>{if(!d.current[r])return;d.current[r]=null,C(r,"isError",!1),m.publish(`errors.${r}`,null);const t=q();v.current!==t&&(v.current=t,m.publish("formState.isError",t))},[C]),R=s.useCallback(()=>{if(Object.keys(d.current)===0)return;Object.keys(d.current).forEach(t=>u(t)),d.current={};const r=q();v.current!==r&&(v.current=r,m.publish("formState.isError",r))},[]),p=s.useCallback(r=>{const t=fe(r.target);t?e(r.target.name,t):u(r.target.name)},[e,u]),O=s.useCallback((r,t,{shouldDirty:F=!0,shouldOnChange:_=!0}={})=>{if(t===a.current[r])return;g&&T.current.includes(r)&&(t=Number(t)||void 0),C(r,"isTouched",!0);const K=t!==i.current[r];F&&f.current[r].isDirty!==K&&C(r,"isDirty",K);const M=U();y.current!==M&&(y.current=M,m.publish("formState.isDirty",M)),a.current[r]=t;const B=c.current.get(r);B&&B(t),m.publish(`values.${r}`,t,{shouldDirty:F,shouldOnChange:_}),_&&m.publish("onChange",r,t,a.current)},[C]),w=s.useCallback((r,t)=>(c.current.set(r,t),()=>{l&&c.current.delete(r)}),[]),Y=s.useCallback((r,{keepError:t,keepDirty:F,keepTouched:_,keepCustomState:K,defaultValue:M})=>{const B=c.current.get(r);if(!B)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);i.current[r]=M,a.current[r]=M,B&&B(M),t||u(r),F||C(r,"isDirty",!1),_||C(r,"isTouched",!1),K||C(r,"customState",null)},[u,C]),I=s.useCallback((r,t=k.getValues(r))=>{m.publish("onBlur",r,t,k.getValues())},[]),k=s.useMemo(()=>({subscribe:X,reset:$,resetField:Y,setValue:O,getValues:z,getErrors:x,getFieldStates:W,getFormState:N,setError:e,clearError:u,clearErrors:R,checkValidity:p,getNumberFields:ne,getFieldValidity:te,getDefaultValues:se,setFieldState:C,triggerFieldBlur:I,resetFieldState:Z,getControlledFields:J}),[X,$,Y,O,z,x,W,N,e,u,R,p,ne,te,se,C,Z,I,J]),P=s.useMemo(()=>({ref:E,watch:V,actions:k,registerController:w,registerHookWatcher:G,lastReloadedAt:b,loadFormValues:D,getWatchValue:H,channels:m}),[E,V,k,w,G,b,D,H,m]),Q=s.useMemo(()=>({control:P,actions:k,watch:V}),[b,P,k,V]);return s.useLayoutEffect(()=>{if([...E.current.querySelectorAll("[name]")].forEach(t=>{!t.defaultValue&&i.current[t.name]&&(t.defaultValue=i.current[t.name]),t.type==="number"&&!T.current.includes(t.name)&&T.current.push(t.name)}),E.current){const t=D();a.current={...t},i.current={...t}}},[b]),s.useLayoutEffect(()=>{A()},[]),Q};exports.Controller=ke;exports.Form=Re;exports.useController=me;exports.useForm=Ae;exports.useFormContext=ue;exports.useWatch=de;
|
|
22
|
+
<%s key={someKey} {...props} />`,p,k,P,k),Z[k+p]=!0)}if(k=null,R!==void 0&&(l(R),k=""+R),E(u)&&(l(u.key),k=""+u.key),"key"in u){R={};for(var Q in u)Q!=="key"&&(R[Q]=u[Q])}else R=u;return k&&y(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,k,w,O,b(),R,Y,I)}function d(e){typeof e=="object"&&e!==null&&e.$$typeof===a&&e._store&&(e._store.validated=1)}var i=s,a=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),U=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),te=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),J=Symbol.for("react.lazy"),j=Symbol.for("react.activity"),z=Symbol.for("react.client.reference"),x=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,N=Array.isArray,V=console.createTask?console.createTask:function(){return null};i={"react-stack-bottom-frame":function(e){return e()}};var G,H={},X=i["react-stack-bottom-frame"].bind(i,h)(),C=V(g(h)),Z={};re.Fragment=m,re.jsx=function(e,u,R,p,O){var w=1e4>x.recentlyCreatedOwnerStacks++;return c(e,u,R,!1,p,O,w?Error("react-stack-top-frame"):X,w?V(g(e)):C)},re.jsxs=function(e,u,R,p,O){var w=1e4>x.recentlyCreatedOwnerStacks++;return c(e,u,R,!0,p,O,w?Error("react-stack-top-frame"):X,w?V(g(e)):C)}}()),re}var ie;function Re(){return ie||(ie=1,process.env.NODE_ENV==="production"?oe.exports=ge():oe.exports=he()),oe.exports}var fe=Re();const S=()=>{},de=s.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:{}}),ae=()=>s.useContext(de),ke=({id:n,control:o,method:l,action:g,children:b,onSubmit:h=()=>{},onInput:E=()=>{},onChange:y=()=>{},onBlur:v=()=>{},onReset:T=()=>{},numberFields:c=[],className:d,...i})=>(s.useEffect(()=>{const a=o.channels.subscribe("onChange",y),f=o.channels.subscribe("onBlur",v);return()=>{a(),f()}},[]),fe.jsx(de.Provider,{value:o,children:fe.jsx("form",{id:n,ref:o.ref,action:g,method:l,className:d,onInput:E,onSubmit:a=>{l||a.preventDefault();const f=o.loadFormValues();h(f)},onChange:a=>{const f=a.target.name;o.actions.getControlledFields().has(f)||o.actions.setValue(f,a.target.value)},onBlur:a=>{const f=a.target.name;if(o.actions.getControlledFields().has(f))return;const m=a.target.value;o.channels.publish("onBlur",f,m,o.actions.getValues())},onReset:a=>{o.actions.reset(),T(a)},...i,children:b},o.lastReloadedAt)})),me=({control:n,name:o,compute:l})=>{const{getWatchValue:g,registerHookWatcher:b}=n||ae(),h=g({name:o,compute:l}),[E,y]=s.useState(h);return s.useEffect(()=>{const v=b({name:o,compute:l,value:E,setValue:y});return()=>v.forEach(T=>T())},[]),E},Ee=({name:n,defaultValue:o})=>{const{actions:l,registerController:g,channels:b}=ae(),h=s.useRef(),E=l.getDefaultValues()[n]||o||"",[y,v]=s.useState(E),T=me({name:`fieldStates.${n}.customState`}),c=s.useCallback(a=>{l.setFieldState(n,"customState",a)},[]),d=s.useCallback((a,{shouldDirty:f=!0,shouldOnChange:m=!0}={})=>{v(a),l.setValue(n,a,{shouldDirty:f,shouldOnChange:m})},[l.setValue]),i=s.useCallback(()=>{b.publish("onBlur",n,y,l.getValues())},[]);return s.useEffect(()=>g(n,v),[]),{ref:h,name:n,defaultValue:E,value:y,onChange:d,onBlur:i,customState:T,setCustomState:c}},Se=({name:n,defaultValue:o,render:l=({ref:g,name:b,defaultValue:h,value:E,onChange:y,onBlur:v,customState:T,setCustomState:c})=>null})=>{const g=Ee({name:n,defaultValue:o});return l(g)},Ce=["errors","fieldStates","formState"],L=n=>Ce.some(o=>n.startsWith(o))?n:"values."+n,ye=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],be=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let o=n.validity,l=ye.find(g=>o[g]);if(l)return{type:l,message:n.validationMessage}};class ve{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,l){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(l),()=>{var g;return(g=this.events.get(o))==null?void 0:g.delete(l)}}publish(o,...l){const g=this.events.get(o);g&&g.forEach(b=>b(...l)),this.events.forEach((b,h)=>{o.includes(h)&&b.forEach(E=>E(...l))})}reset(){this.events.clear()}}const pe=()=>{const n=s.useRef(new ve),o=s.useCallback((b,...h)=>{n.current.publish(b,...h)},[]),l=s.useCallback((b,h)=>n.current.subscribe(b,h),[]),g=s.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:l,reset:g}},Fe=()=>{const[n,o]=s.useState(),l=s.useCallback(()=>o(new Date().toString()),[]);return[n,l]},Te=()=>{const[,n]=s.useState({});return s.useCallback(()=>n({}),[])},_e=({channels:n,getValues:o,getErrors:l,getFieldStates:g,getFormState:b})=>{const h=Te(),E=s.useCallback(({name:c,compute:d})=>{if(typeof d=="function")return d(o());if(Array.isArray(c)){const i={};return c.forEach(a=>{i[a]=E({name:a})}),i}return c.split(".").reduce((i,a)=>i&&i[a]!==void 0?i[a]:void 0,{...o(),errors:{...l()},formState:{...b()},fieldStates:{...g()}})},[]),y=s.useCallback(c=>{if(!c)return n.subscribe("values",()=>h()),o();if(typeof c=="string"){const d=L(c);return n.subscribe(d,()=>h()),E({name:c})}if(Array.isArray(c)){const d={};return c.forEach(i=>{const a=L(i);n.subscribe(a,()=>h()),d[i]=E({name:i})}),{...d}}throw new Error("Parameters of watch must be string or array of string")},[]),v=s.useCallback(({name:c,compute:d,value:i,setValue:a})=>{if(typeof d=="function")return[n.subscribe("values",()=>{const m=E({compute:d});a(m)})];if(!c)return[n.subscribe("values",()=>{a(o())})];if(typeof c=="string"){const f=L(c);return[n.subscribe(f,()=>{const A=E({name:c});a(A)})]}if(Array.isArray(c)){const f=E({name:c}),m=[];return c.forEach(A=>{const $=L(A),D=n.subscribe($,()=>{const U=E({name:A});f[A]=U,a({...f})});m.push(D)}),m}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),T=s.useCallback((c,d)=>{if(!c)return n.subscribe("values",d);if(typeof c=="string"){const i=L(c);return n.subscribe(i,d)}if(Array.isArray(c)){const i={},a=[];return c.forEach(f=>{const m=L(f),A=n.subscribe(m,()=>{i[f]=E({name:f}),d({...i})});a.push(A)}),a}throw new Error("Parameters of name must be string or array of string")},[n]);return{watch:y,registerHookWatcher:v,getWatchValue:E,subscribe:T}},ue={isError:!1,isDirty:!1,isTouched:!1,customState:null},we=[],Ae={},Oe=({numberFields:n=we,defaultValues:o=Ae,shouldUnRegister:l=!1,shouldConvertNumber:g=!1}={})=>{const[b,h]=Fe(),E=s.useRef(),y=s.useRef(!1),v=s.useRef(!1),T=s.useRef(n),c=s.useRef(new Map),d=s.useRef({}),i=s.useRef({}),a=s.useRef(o),f=s.useRef(o),m=pe(),A=s.useCallback(()=>{i.current=Object.keys(f.current).reduce((r,t)=>({...r,[t]:{...ue}}),{})},[]),$=s.useCallback((r={})=>{f.current={...f.current,...r},a.current={...f.current},c.current.forEach((t,F)=>{t(f.current[F])}),y.current=!1,d.current={},T.current=n,c.current=new Map,m.reset(),A(),n.length>0&&(g=!0),h()},[]),D=s.useCallback(()=>{const r=Object.fromEntries(new FormData(E.current));return c.current.forEach((F,_)=>{r[_]=a.current[_]}),g&&T.current.forEach(F=>r.hasOwnProperty(F)&&(r[F]=Number(r[F])||0)),r},[]),U=s.useCallback(()=>!!Object.values(W()).find(r=>r.isDirty),[]),q=s.useCallback(()=>!!Object.values(x()).find(r=>!!r),[]),te=s.useCallback(r=>be(r.target),[]),se=s.useCallback(()=>f.current,[]),ne=s.useCallback(()=>T.current,[]),J=s.useCallback(()=>c.current,[]),j=s.useCallback((r,t)=>t?Array.isArray(t)?t.map(F=>r[F]):r[t]:{...r},[]),z=s.useCallback(r=>j(a.current,r),[j]),x=s.useCallback(r=>j(d.current,r),[j]),W=s.useCallback(r=>j(i.current,r),[j]),N=s.useCallback(r=>j({isDirty:y.current,isError:v.current,errorFields:Object.keys(d.current).filter(t=>!!d.current[t]),dirtyFields:Object.keys(i.current).filter(t=>i.current[t].isDirty),touchedFields:Object.keys(i.current).filter(t=>i.current[t].isTouched)},r),[j]),{watch:V,registerHookWatcher:G,getWatchValue:H,subscribe:X}=_e({channels:m,getValues:z,getErrors:x,getFieldStates:W,getFormState:N}),C=s.useCallback((r,t,F)=>{const _=i.current[r]||{...ue};_[t]!==F&&(i.current[r]={..._,[t]:F},m.publish(`fieldStates.${r}.${t}`,F),t==="isError"&&m.publish("formState.errorFields",N("errorFields")),t==="isDirty"&&m.publish("formState.dirtyFields",N("dirtyFields")),t==="isTouched"&&m.publish("formState.touchedFields",N("touchedFields")))},[]),Z=s.useCallback(r=>{C(r,"isError",!1),C(r,"isDirty",!1),C(r,"isTouched",!1),C(r,"customState",null)},[C]),e=s.useCallback((r,t)=>{if(d.current[r]===t)return;d.current[r]=t,C(r,"isError",!!t),m.publish(`errors.${r}`,t);const _=q();v.current!==_&&(v.current=_,m.publish("formState.isError",_))},[C]),u=s.useCallback(r=>{if(!d.current[r])return;d.current[r]=null,C(r,"isError",!1),m.publish(`errors.${r}`,null);const t=q();v.current!==t&&(v.current=t,m.publish("formState.isError",t))},[C]),R=s.useCallback(()=>{if(Object.keys(d.current)===0)return;Object.keys(d.current).forEach(t=>u(t)),d.current={};const r=q();v.current!==r&&(v.current=r,m.publish("formState.isError",r))},[]),p=s.useCallback(r=>{const t=be(r.target);t?e(r.target.name,t):u(r.target.name)},[e,u]),O=s.useCallback((r,t,{shouldDirty:F=!0,shouldOnChange:_=!0}={})=>{if(t===a.current[r])return;g&&T.current.includes(r)&&(t=Number(t)||void 0),C(r,"isTouched",!0);const K=t!==f.current[r];F&&i.current[r].isDirty!==K&&C(r,"isDirty",K);const M=U();y.current!==M&&(y.current=M,m.publish("formState.isDirty",M)),a.current[r]=t;const B=c.current.get(r);B&&B(t),m.publish(`values.${r}`,t,{shouldDirty:F,shouldOnChange:_}),_&&m.publish("onChange",r,t,a.current)},[C]),w=s.useCallback((r,t)=>(c.current.set(r,t),i.current[r]={...ue},()=>{l&&c.current.delete(r)}),[]),Y=s.useCallback((r,{keepError:t,keepDirty:F,keepTouched:_,keepCustomState:K,defaultValue:M})=>{const B=c.current.get(r);if(!B)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);f.current[r]=M,a.current[r]=M,B&&B(M),t||u(r),F||C(r,"isDirty",!1),_||C(r,"isTouched",!1),K||C(r,"customState",null)},[u,C]),I=s.useCallback((r,t=k.getValues(r))=>{m.publish("onBlur",r,t,k.getValues())},[]),k=s.useMemo(()=>({subscribe:X,reset:$,resetField:Y,setValue:O,getValues:z,getErrors:x,getFieldStates:W,getFormState:N,setError:e,clearError:u,clearErrors:R,checkValidity:p,getNumberFields:ne,getFieldValidity:te,getDefaultValues:se,setFieldState:C,triggerFieldBlur:I,resetFieldState:Z,getControlledFields:J}),[X,$,Y,O,z,x,W,N,e,u,R,p,ne,te,se,C,Z,I,J]),P=s.useMemo(()=>({ref:E,watch:V,actions:k,registerController:w,registerHookWatcher:G,lastReloadedAt:b,loadFormValues:D,getWatchValue:H,channels:m}),[E,V,k,w,G,b,D,H,m]),Q=s.useMemo(()=>({control:P,actions:k,watch:V}),[b,P,k,V]);return s.useLayoutEffect(()=>{if([...E.current.querySelectorAll("[name]")].forEach(t=>{!t.defaultValue&&!c.current.has(t.name)&&f.current[t.name]&&(t.defaultValue=f.current[t.name]),t.type==="number"&&!T.current.includes(t.name)&&T.current.push(t.name)}),E.current){const t=D();a.current={...t},f.current={...t}}},[b]),s.useLayoutEffect(()=>{A()},[]),Q};exports.Controller=Se;exports.Form=ke;exports.useController=Ee;exports.useForm=Oe;exports.useFormContext=ae;exports.useWatch=me;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Re, { createContext as
|
|
1
|
+
import Re, { createContext as pe, useContext as ve, useEffect as le, useState as ce, useRef as C, useCallback as f, useMemo as ae, useLayoutEffect as fe } from "react";
|
|
2
2
|
var ue = { exports: {} }, re = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
@@ -9,10 +9,10 @@ var ue = { exports: {} }, re = {};
|
|
|
9
9
|
* This source code is licensed under the MIT license found in the
|
|
10
10
|
* LICENSE file in the root directory of this source tree.
|
|
11
11
|
*/
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
if (
|
|
15
|
-
|
|
12
|
+
var de;
|
|
13
|
+
function ye() {
|
|
14
|
+
if (de) return re;
|
|
15
|
+
de = 1;
|
|
16
16
|
var s = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
17
17
|
function a(g, d, h) {
|
|
18
18
|
var E = null;
|
|
@@ -41,9 +41,9 @@ var te = {};
|
|
|
41
41
|
* This source code is licensed under the MIT license found in the
|
|
42
42
|
* LICENSE file in the root directory of this source tree.
|
|
43
43
|
*/
|
|
44
|
-
var
|
|
45
|
-
function
|
|
46
|
-
return
|
|
44
|
+
var be;
|
|
45
|
+
function Fe() {
|
|
46
|
+
return be || (be = 1, process.env.NODE_ENV !== "production" && function() {
|
|
47
47
|
function s(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
@@ -67,7 +67,7 @@ function ye() {
|
|
|
67
67
|
switch (typeof e.tag == "number" && console.error(
|
|
68
68
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
69
69
|
), e.$$typeof) {
|
|
70
|
-
case
|
|
70
|
+
case l:
|
|
71
71
|
return "Portal";
|
|
72
72
|
case q:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
@@ -99,8 +99,8 @@ function ye() {
|
|
|
99
99
|
}
|
|
100
100
|
if (o) {
|
|
101
101
|
o = console;
|
|
102
|
-
var
|
|
103
|
-
return
|
|
102
|
+
var S = o.error, T = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
+
return S.call(
|
|
104
104
|
o,
|
|
105
105
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
106
|
T
|
|
@@ -133,14 +133,14 @@ function ye() {
|
|
|
133
133
|
return e.key !== void 0;
|
|
134
134
|
}
|
|
135
135
|
function y(e, o) {
|
|
136
|
-
function
|
|
136
|
+
function S() {
|
|
137
137
|
H || (H = !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
|
o
|
|
140
140
|
));
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
get:
|
|
142
|
+
S.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
+
get: S,
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
@@ -150,14 +150,14 @@ function ye() {
|
|
|
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 k(e, o,
|
|
154
|
-
return
|
|
153
|
+
function k(e, o, S, T, j, A, I, B) {
|
|
154
|
+
return S = A.ref, e = {
|
|
155
155
|
$$typeof: u,
|
|
156
156
|
type: e,
|
|
157
157
|
key: o,
|
|
158
158
|
props: A,
|
|
159
159
|
_owner: j
|
|
160
|
-
}, (
|
|
160
|
+
}, (S !== void 0 ? S : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
162
|
get: F
|
|
163
163
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
@@ -182,25 +182,25 @@ function ye() {
|
|
|
182
182
|
value: B
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function c(e, o,
|
|
186
|
-
var
|
|
187
|
-
if (
|
|
185
|
+
function c(e, o, S, T, j, A, I, B) {
|
|
186
|
+
var R = o.children;
|
|
187
|
+
if (R !== void 0)
|
|
188
188
|
if (T)
|
|
189
|
-
if (V(
|
|
190
|
-
for (T = 0; T <
|
|
191
|
-
b(
|
|
192
|
-
Object.freeze && Object.freeze(
|
|
189
|
+
if (V(R)) {
|
|
190
|
+
for (T = 0; T < R.length; T++)
|
|
191
|
+
b(R[T]);
|
|
192
|
+
Object.freeze && Object.freeze(R);
|
|
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 b(
|
|
197
|
+
else b(R);
|
|
198
198
|
if ($.call(o, "key")) {
|
|
199
|
-
|
|
199
|
+
R = s(e);
|
|
200
200
|
var x = Object.keys(o).filter(function(r) {
|
|
201
201
|
return r !== "key";
|
|
202
202
|
});
|
|
203
|
-
T = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", Q[
|
|
203
|
+
T = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", Q[R + T] || (x = 0 < x.length ? "{" + x.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} />
|
|
@@ -208,26 +208,26 @@ React keys must be passed directly to JSX without using spread:
|
|
|
208
208
|
let props = %s;
|
|
209
209
|
<%s key={someKey} {...props} />`,
|
|
210
210
|
T,
|
|
211
|
-
|
|
211
|
+
R,
|
|
212
212
|
x,
|
|
213
|
-
|
|
214
|
-
), Q[
|
|
213
|
+
R
|
|
214
|
+
), Q[R + T] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
216
|
+
if (R = null, S !== void 0 && (a(S), R = "" + S), E(o) && (a(o.key), R = "" + o.key), "key" in o) {
|
|
217
|
+
S = {};
|
|
218
218
|
for (var K in o)
|
|
219
|
-
K !== "key" && (
|
|
220
|
-
} else
|
|
221
|
-
return
|
|
222
|
-
|
|
219
|
+
K !== "key" && (S[K] = o[K]);
|
|
220
|
+
} else S = o;
|
|
221
|
+
return R && y(
|
|
222
|
+
S,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
224
|
), k(
|
|
225
225
|
e,
|
|
226
|
-
|
|
226
|
+
R,
|
|
227
227
|
A,
|
|
228
228
|
j,
|
|
229
229
|
d(),
|
|
230
|
-
|
|
230
|
+
S,
|
|
231
231
|
I,
|
|
232
232
|
B
|
|
233
233
|
);
|
|
@@ -235,36 +235,36 @@ React keys must be passed directly to JSX without using spread:
|
|
|
235
235
|
function b(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === u && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var i = Re, u = Symbol.for("react.transitional.element"), l = Symbol.for("react.portal"), m = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), q = Symbol.for("react.context"), J = Symbol.for("react.forward_ref"), se = Symbol.for("react.suspense"), ne = Symbol.for("react.suspense_list"), oe = Symbol.for("react.memo"), z = Symbol.for("react.lazy"), P = Symbol.for("react.activity"), G = Symbol.for("react.client.reference"), N = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, V = Array.isArray, D = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
|
-
|
|
241
|
+
i = {
|
|
242
242
|
"react-stack-bottom-frame": function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var H, X = {}, Z =
|
|
247
|
-
|
|
246
|
+
var H, X = {}, Z = i["react-stack-bottom-frame"].bind(
|
|
247
|
+
i,
|
|
248
248
|
h
|
|
249
249
|
)(), v = D(g(h)), Q = {};
|
|
250
|
-
te.Fragment = m, te.jsx = function(e, o,
|
|
250
|
+
te.Fragment = m, te.jsx = function(e, o, S, T, j) {
|
|
251
251
|
var A = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return c(
|
|
253
253
|
e,
|
|
254
254
|
o,
|
|
255
|
-
|
|
255
|
+
S,
|
|
256
256
|
!1,
|
|
257
257
|
T,
|
|
258
258
|
j,
|
|
259
259
|
A ? Error("react-stack-top-frame") : Z,
|
|
260
260
|
A ? D(g(e)) : v
|
|
261
261
|
);
|
|
262
|
-
}, te.jsxs = function(e, o,
|
|
262
|
+
}, te.jsxs = function(e, o, S, T, j) {
|
|
263
263
|
var A = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return c(
|
|
265
265
|
e,
|
|
266
266
|
o,
|
|
267
|
-
|
|
267
|
+
S,
|
|
268
268
|
!0,
|
|
269
269
|
T,
|
|
270
270
|
j,
|
|
@@ -274,13 +274,13 @@ React keys must be passed directly to JSX without using spread:
|
|
|
274
274
|
};
|
|
275
275
|
}()), te;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
278
|
-
function
|
|
279
|
-
return
|
|
277
|
+
var me;
|
|
278
|
+
function Te() {
|
|
279
|
+
return me || (me = 1, process.env.NODE_ENV === "production" ? ue.exports = ye() : ue.exports = Fe()), ue.exports;
|
|
280
280
|
}
|
|
281
|
-
var
|
|
281
|
+
var Ee = Te();
|
|
282
282
|
const p = () => {
|
|
283
|
-
},
|
|
283
|
+
}, he = pe({
|
|
284
284
|
ref: null,
|
|
285
285
|
watch: p,
|
|
286
286
|
actions: {
|
|
@@ -308,7 +308,7 @@ const p = () => {
|
|
|
308
308
|
loadFormValues: p,
|
|
309
309
|
getWatchValue: p,
|
|
310
310
|
channels: {}
|
|
311
|
-
}),
|
|
311
|
+
}), Se = () => ve(he), $e = ({
|
|
312
312
|
id: s,
|
|
313
313
|
control: n,
|
|
314
314
|
method: a,
|
|
@@ -326,13 +326,13 @@ const p = () => {
|
|
|
326
326
|
},
|
|
327
327
|
numberFields: c = [],
|
|
328
328
|
className: b,
|
|
329
|
-
...
|
|
330
|
-
}) => (
|
|
331
|
-
const u = n.channels.subscribe("onChange", y),
|
|
329
|
+
...i
|
|
330
|
+
}) => (le(() => {
|
|
331
|
+
const u = n.channels.subscribe("onChange", y), l = n.channels.subscribe("onBlur", F);
|
|
332
332
|
return () => {
|
|
333
|
-
u(),
|
|
333
|
+
u(), l();
|
|
334
334
|
};
|
|
335
|
-
}, []), /* @__PURE__ */
|
|
335
|
+
}, []), /* @__PURE__ */ Ee.jsx(he.Provider, { value: n, children: /* @__PURE__ */ Ee.jsx(
|
|
336
336
|
"form",
|
|
337
337
|
{
|
|
338
338
|
id: s,
|
|
@@ -343,52 +343,52 @@ const p = () => {
|
|
|
343
343
|
onInput: E,
|
|
344
344
|
onSubmit: (u) => {
|
|
345
345
|
a || u.preventDefault();
|
|
346
|
-
const
|
|
347
|
-
h(
|
|
346
|
+
const l = n.loadFormValues();
|
|
347
|
+
h(l);
|
|
348
348
|
},
|
|
349
349
|
onChange: (u) => {
|
|
350
|
-
const
|
|
351
|
-
n.actions.getControlledFields().has(
|
|
350
|
+
const l = u.target.name;
|
|
351
|
+
n.actions.getControlledFields().has(l) || n.actions.setValue(l, u.target.value);
|
|
352
352
|
},
|
|
353
353
|
onBlur: (u) => {
|
|
354
|
-
const
|
|
355
|
-
if (n.actions.getControlledFields().has(
|
|
354
|
+
const l = u.target.name;
|
|
355
|
+
if (n.actions.getControlledFields().has(l)) return;
|
|
356
356
|
const m = u.target.value;
|
|
357
|
-
n.channels.publish("onBlur",
|
|
357
|
+
n.channels.publish("onBlur", l, m, n.actions.getValues());
|
|
358
358
|
},
|
|
359
359
|
onReset: (u) => {
|
|
360
360
|
n.actions.reset(), k(u);
|
|
361
361
|
},
|
|
362
|
-
...
|
|
362
|
+
...i,
|
|
363
363
|
children: d
|
|
364
364
|
},
|
|
365
365
|
n.lastReloadedAt
|
|
366
|
-
) })),
|
|
367
|
-
const { getWatchValue: g, registerHookWatcher: d } = s ||
|
|
368
|
-
return
|
|
366
|
+
) })), _e = ({ control: s, name: n, compute: a }) => {
|
|
367
|
+
const { getWatchValue: g, registerHookWatcher: d } = s || Se(), h = g({ name: n, compute: a }), [E, y] = ce(h);
|
|
368
|
+
return le(() => {
|
|
369
369
|
const F = d({ name: n, compute: a, value: E, setValue: y });
|
|
370
370
|
return () => F.forEach((k) => k());
|
|
371
371
|
}, []), E;
|
|
372
|
-
},
|
|
373
|
-
const { actions: a, registerController: g, channels: d } =
|
|
372
|
+
}, ke = ({ name: s, defaultValue: n }) => {
|
|
373
|
+
const { actions: a, registerController: g, channels: d } = Se(), h = C(), E = a.getDefaultValues()[s] || n || "", [y, F] = ce(E), k = _e({ name: `fieldStates.${s}.customState` }), c = f((u) => {
|
|
374
374
|
a.setFieldState(s, "customState", u);
|
|
375
|
-
}, []), b =
|
|
376
|
-
(u, { shouldDirty:
|
|
377
|
-
F(u), a.setValue(s, u, { shouldDirty:
|
|
375
|
+
}, []), b = f(
|
|
376
|
+
(u, { shouldDirty: l = !0, shouldOnChange: m = !0 } = {}) => {
|
|
377
|
+
F(u), a.setValue(s, u, { shouldDirty: l, shouldOnChange: m });
|
|
378
378
|
},
|
|
379
379
|
[a.setValue]
|
|
380
|
-
),
|
|
380
|
+
), i = f(() => {
|
|
381
381
|
d.publish("onBlur", s, y, a.getValues());
|
|
382
382
|
}, []);
|
|
383
|
-
return
|
|
384
|
-
},
|
|
383
|
+
return le(() => g(s, F), []), { ref: h, name: s, defaultValue: E, value: y, onChange: b, onBlur: i, customState: k, setCustomState: c };
|
|
384
|
+
}, Me = ({
|
|
385
385
|
name: s,
|
|
386
386
|
defaultValue: n,
|
|
387
387
|
render: a = ({ ref: g, name: d, defaultValue: h, value: E, onChange: y, onBlur: F, customState: k, setCustomState: c }) => null
|
|
388
388
|
}) => {
|
|
389
|
-
const g =
|
|
389
|
+
const g = ke({ name: s, defaultValue: n });
|
|
390
390
|
return a(g);
|
|
391
|
-
},
|
|
391
|
+
}, we = ["errors", "fieldStates", "formState"], U = (s) => we.some((n) => s.startsWith(n)) ? s : "values." + s, Ae = [
|
|
392
392
|
"badInput",
|
|
393
393
|
"customError",
|
|
394
394
|
"patternMismatch",
|
|
@@ -399,12 +399,12 @@ const p = () => {
|
|
|
399
399
|
"tooShort",
|
|
400
400
|
"typeMismatch",
|
|
401
401
|
"valueMissing"
|
|
402
|
-
],
|
|
402
|
+
], ge = (s) => {
|
|
403
403
|
typeof s.setCustomValidity == "function" && s.setCustomValidity("");
|
|
404
|
-
let n = s.validity, a =
|
|
404
|
+
let n = s.validity, a = Ae.find((g) => n[g]);
|
|
405
405
|
if (a) return { type: a, message: s.validationMessage };
|
|
406
406
|
};
|
|
407
|
-
class
|
|
407
|
+
class Oe {
|
|
408
408
|
constructor() {
|
|
409
409
|
this.events = /* @__PURE__ */ new Map();
|
|
410
410
|
}
|
|
@@ -427,30 +427,30 @@ class Ae {
|
|
|
427
427
|
this.events.clear();
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
const
|
|
431
|
-
const s = C(new
|
|
430
|
+
const je = () => {
|
|
431
|
+
const s = C(new Oe()), n = f((d, ...h) => {
|
|
432
432
|
s.current.publish(d, ...h);
|
|
433
|
-
}, []), a =
|
|
433
|
+
}, []), a = f((d, h) => s.current.subscribe(d, h), []), g = f(() => {
|
|
434
434
|
s.current.reset();
|
|
435
435
|
}, []);
|
|
436
436
|
return { publish: n, subscribe: a, reset: g };
|
|
437
|
-
}, je = () => {
|
|
438
|
-
const [s, n] = ce(), a = l(() => n((/* @__PURE__ */ new Date()).toString()), []);
|
|
439
|
-
return [s, a];
|
|
440
437
|
}, Ce = () => {
|
|
438
|
+
const [s, n] = ce(), a = f(() => n((/* @__PURE__ */ new Date()).toString()), []);
|
|
439
|
+
return [s, a];
|
|
440
|
+
}, Pe = () => {
|
|
441
441
|
const [, s] = ce({});
|
|
442
|
-
return
|
|
443
|
-
},
|
|
444
|
-
const h =
|
|
442
|
+
return f(() => s({}), []);
|
|
443
|
+
}, xe = ({ channels: s, getValues: n, getErrors: a, getFieldStates: g, getFormState: d }) => {
|
|
444
|
+
const h = Pe(), E = f(({ name: c, compute: b }) => {
|
|
445
445
|
if (typeof b == "function") return b(n());
|
|
446
446
|
if (Array.isArray(c)) {
|
|
447
|
-
const
|
|
447
|
+
const i = {};
|
|
448
448
|
return c.forEach((u) => {
|
|
449
|
-
|
|
450
|
-
}),
|
|
449
|
+
i[u] = E({ name: u });
|
|
450
|
+
}), i;
|
|
451
451
|
}
|
|
452
452
|
return c.split(".").reduce(
|
|
453
|
-
(
|
|
453
|
+
(i, u) => i && i[u] !== void 0 ? i[u] : void 0,
|
|
454
454
|
{
|
|
455
455
|
...n(),
|
|
456
456
|
errors: { ...a() },
|
|
@@ -458,7 +458,7 @@ const Oe = () => {
|
|
|
458
458
|
fieldStates: { ...g() }
|
|
459
459
|
}
|
|
460
460
|
);
|
|
461
|
-
}, []), y =
|
|
461
|
+
}, []), y = f((c) => {
|
|
462
462
|
if (!c)
|
|
463
463
|
return s.subscribe("values", () => h()), n();
|
|
464
464
|
if (typeof c == "string") {
|
|
@@ -467,13 +467,13 @@ const Oe = () => {
|
|
|
467
467
|
}
|
|
468
468
|
if (Array.isArray(c)) {
|
|
469
469
|
const b = {};
|
|
470
|
-
return c.forEach((
|
|
471
|
-
const u = U(
|
|
472
|
-
s.subscribe(u, () => h()), b[
|
|
470
|
+
return c.forEach((i) => {
|
|
471
|
+
const u = U(i);
|
|
472
|
+
s.subscribe(u, () => h()), b[i] = E({ name: i });
|
|
473
473
|
}), { ...b };
|
|
474
474
|
}
|
|
475
475
|
throw new Error("Parameters of watch must be string or array of string");
|
|
476
|
-
}, []), F =
|
|
476
|
+
}, []), F = f(({ name: c, compute: b, value: i, setValue: u }) => {
|
|
477
477
|
if (typeof b == "function")
|
|
478
478
|
return [s.subscribe("values", () => {
|
|
479
479
|
const m = E({ compute: b });
|
|
@@ -484,36 +484,36 @@ const Oe = () => {
|
|
|
484
484
|
u(n());
|
|
485
485
|
})];
|
|
486
486
|
if (typeof c == "string") {
|
|
487
|
-
const
|
|
488
|
-
return [s.subscribe(
|
|
487
|
+
const l = U(c);
|
|
488
|
+
return [s.subscribe(l, () => {
|
|
489
489
|
const O = E({ name: c });
|
|
490
490
|
u(O);
|
|
491
491
|
})];
|
|
492
492
|
}
|
|
493
493
|
if (Array.isArray(c)) {
|
|
494
|
-
const
|
|
494
|
+
const l = E({ name: c }), m = [];
|
|
495
495
|
return c.forEach((O) => {
|
|
496
496
|
const Y = U(O), W = s.subscribe(Y, () => {
|
|
497
497
|
const q = E({ name: O });
|
|
498
|
-
|
|
498
|
+
l[O] = q, u({ ...l });
|
|
499
499
|
});
|
|
500
500
|
m.push(W);
|
|
501
501
|
}), m;
|
|
502
502
|
}
|
|
503
503
|
throw new Error("Parameters of name must be string or array of string or compute must be a function");
|
|
504
|
-
}, []), k =
|
|
504
|
+
}, []), k = f(
|
|
505
505
|
(c, b) => {
|
|
506
506
|
if (!c)
|
|
507
507
|
return s.subscribe("values", b);
|
|
508
508
|
if (typeof c == "string") {
|
|
509
|
-
const
|
|
510
|
-
return s.subscribe(
|
|
509
|
+
const i = U(c);
|
|
510
|
+
return s.subscribe(i, b);
|
|
511
511
|
}
|
|
512
512
|
if (Array.isArray(c)) {
|
|
513
|
-
const
|
|
514
|
-
return c.forEach((
|
|
515
|
-
const m = U(
|
|
516
|
-
|
|
513
|
+
const i = {}, u = [];
|
|
514
|
+
return c.forEach((l) => {
|
|
515
|
+
const m = U(l), O = s.subscribe(m, () => {
|
|
516
|
+
i[l] = E({ name: l }), b({ ...i });
|
|
517
517
|
});
|
|
518
518
|
u.push(O);
|
|
519
519
|
}), u;
|
|
@@ -523,55 +523,52 @@ const Oe = () => {
|
|
|
523
523
|
[s]
|
|
524
524
|
);
|
|
525
525
|
return { watch: y, registerHookWatcher: F, getWatchValue: E, subscribe: k };
|
|
526
|
-
},
|
|
527
|
-
numberFields: s =
|
|
528
|
-
defaultValues: n =
|
|
526
|
+
}, ie = { isError: !1, isDirty: !1, isTouched: !1, customState: null }, Ne = [], Ve = {}, Ye = ({
|
|
527
|
+
numberFields: s = Ne,
|
|
528
|
+
defaultValues: n = Ve,
|
|
529
529
|
shouldUnRegister: a = !1,
|
|
530
530
|
shouldConvertNumber: g = !1
|
|
531
531
|
} = {}) => {
|
|
532
|
-
const [d, h] =
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}, []), Y = l((r = {}) => {
|
|
538
|
-
i.current = { ...i.current, ...r }, u.current = { ...i.current }, c.current.forEach((t, _) => {
|
|
539
|
-
t(i.current[_]);
|
|
532
|
+
const [d, h] = Ce(), E = C(), y = C(!1), F = C(!1), k = C(s), c = C(/* @__PURE__ */ new Map()), b = C({}), i = C({}), u = C(n), l = C(n), m = je(), O = f(() => {
|
|
533
|
+
i.current = Object.keys(l.current).reduce((r, t) => ({ ...r, [t]: { ...ie } }), {});
|
|
534
|
+
}, []), Y = f((r = {}) => {
|
|
535
|
+
l.current = { ...l.current, ...r }, u.current = { ...l.current }, c.current.forEach((t, _) => {
|
|
536
|
+
t(l.current[_]);
|
|
540
537
|
}), y.current = !1, b.current = {}, k.current = s, c.current = /* @__PURE__ */ new Map(), m.reset(), O(), s.length > 0 && (g = !0), h();
|
|
541
|
-
}, []), W =
|
|
538
|
+
}, []), W = f(() => {
|
|
542
539
|
const r = Object.fromEntries(new FormData(E.current));
|
|
543
540
|
return c.current.forEach((_, w) => {
|
|
544
541
|
r[w] = u.current[w];
|
|
545
542
|
}), g && k.current.forEach(
|
|
546
543
|
(_) => r.hasOwnProperty(_) && (r[_] = Number(r[_]) || 0)
|
|
547
544
|
), r;
|
|
548
|
-
}, []), q =
|
|
545
|
+
}, []), q = f(() => !!Object.values($()).find((r) => r.isDirty), []), J = f(() => !!Object.values(N()).find((r) => !!r), []), se = f((r) => ge(r.target), []), ne = f(() => l.current, []), oe = f(() => k.current, []), z = f(() => c.current, []), P = f((r, t) => t ? Array.isArray(t) ? t.map((_) => r[_]) : r[t] : { ...r }, []), G = f((r) => P(u.current, r), [P]), N = f((r) => P(b.current, r), [P]), $ = f((r) => P(i.current, r), [P]), V = f(
|
|
549
546
|
(r) => P(
|
|
550
547
|
{
|
|
551
548
|
isDirty: y.current,
|
|
552
549
|
isError: F.current,
|
|
553
550
|
errorFields: Object.keys(b.current).filter((t) => !!b.current[t]),
|
|
554
|
-
dirtyFields: Object.keys(
|
|
555
|
-
touchedFields: Object.keys(
|
|
551
|
+
dirtyFields: Object.keys(i.current).filter((t) => i.current[t].isDirty),
|
|
552
|
+
touchedFields: Object.keys(i.current).filter((t) => i.current[t].isTouched)
|
|
556
553
|
},
|
|
557
554
|
r
|
|
558
555
|
),
|
|
559
556
|
[P]
|
|
560
|
-
), { watch: D, registerHookWatcher: H, getWatchValue: X, subscribe: Z } =
|
|
557
|
+
), { watch: D, registerHookWatcher: H, getWatchValue: X, subscribe: Z } = xe({
|
|
561
558
|
channels: m,
|
|
562
559
|
getValues: G,
|
|
563
560
|
getErrors: N,
|
|
564
561
|
getFieldStates: $,
|
|
565
562
|
getFormState: V
|
|
566
|
-
}), v =
|
|
567
|
-
const w =
|
|
568
|
-
w[t] !== _ && (
|
|
569
|
-
}, []), Q =
|
|
563
|
+
}), v = f((r, t, _) => {
|
|
564
|
+
const w = i.current[r] || { ...ie };
|
|
565
|
+
w[t] !== _ && (i.current[r] = { ...w, [t]: _ }, m.publish(`fieldStates.${r}.${t}`, _), t === "isError" && m.publish("formState.errorFields", V("errorFields")), t === "isDirty" && m.publish("formState.dirtyFields", V("dirtyFields")), t === "isTouched" && m.publish("formState.touchedFields", V("touchedFields")));
|
|
566
|
+
}, []), Q = f(
|
|
570
567
|
(r) => {
|
|
571
568
|
v(r, "isError", !1), v(r, "isDirty", !1), v(r, "isTouched", !1), v(r, "customState", null);
|
|
572
569
|
},
|
|
573
570
|
[v]
|
|
574
|
-
), e =
|
|
571
|
+
), e = f(
|
|
575
572
|
(r, t) => {
|
|
576
573
|
if (b.current[r] === t) return;
|
|
577
574
|
b.current[r] = t, v(r, "isError", !!t), m.publish(`errors.${r}`, t);
|
|
@@ -579,7 +576,7 @@ const Oe = () => {
|
|
|
579
576
|
F.current !== w && (F.current = w, m.publish("formState.isError", w));
|
|
580
577
|
},
|
|
581
578
|
[v]
|
|
582
|
-
), o =
|
|
579
|
+
), o = f(
|
|
583
580
|
(r) => {
|
|
584
581
|
if (!b.current[r]) return;
|
|
585
582
|
b.current[r] = null, v(r, "isError", !1), m.publish(`errors.${r}`, null);
|
|
@@ -587,42 +584,42 @@ const Oe = () => {
|
|
|
587
584
|
F.current !== t && (F.current = t, m.publish("formState.isError", t));
|
|
588
585
|
},
|
|
589
586
|
[v]
|
|
590
|
-
),
|
|
587
|
+
), S = f(() => {
|
|
591
588
|
if (Object.keys(b.current) === 0) return;
|
|
592
589
|
Object.keys(b.current).forEach((t) => o(t)), b.current = {};
|
|
593
590
|
const r = J();
|
|
594
591
|
F.current !== r && (F.current = r, m.publish("formState.isError", r));
|
|
595
|
-
}, []), T =
|
|
592
|
+
}, []), T = f(
|
|
596
593
|
(r) => {
|
|
597
|
-
const t =
|
|
594
|
+
const t = ge(r.target);
|
|
598
595
|
t ? e(r.target.name, t) : o(r.target.name);
|
|
599
596
|
},
|
|
600
597
|
[e, o]
|
|
601
|
-
), j =
|
|
598
|
+
), j = f(
|
|
602
599
|
(r, t, { shouldDirty: _ = !0, shouldOnChange: w = !0 } = {}) => {
|
|
603
600
|
if (t === u.current[r]) return;
|
|
604
601
|
g && k.current.includes(r) && (t = Number(t) || void 0), v(r, "isTouched", !0);
|
|
605
|
-
const ee = t !==
|
|
606
|
-
_ &&
|
|
602
|
+
const ee = t !== l.current[r];
|
|
603
|
+
_ && i.current[r].isDirty !== ee && v(r, "isDirty", ee);
|
|
607
604
|
const M = q();
|
|
608
605
|
y.current !== M && (y.current = M, m.publish("formState.isDirty", M)), u.current[r] = t;
|
|
609
606
|
const L = c.current.get(r);
|
|
610
607
|
L && L(t), m.publish(`values.${r}`, t, { shouldDirty: _, shouldOnChange: w }), w && m.publish("onChange", r, t, u.current);
|
|
611
608
|
},
|
|
612
609
|
[v]
|
|
613
|
-
), A =
|
|
610
|
+
), A = f((r, t) => (c.current.set(r, t), i.current[r] = { ...ie }, () => {
|
|
614
611
|
a && c.current.delete(r);
|
|
615
|
-
}), []), I =
|
|
612
|
+
}), []), I = f(
|
|
616
613
|
(r, { keepError: t, keepDirty: _, keepTouched: w, keepCustomState: ee, defaultValue: M }) => {
|
|
617
614
|
const L = c.current.get(r);
|
|
618
615
|
if (!L)
|
|
619
616
|
throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);
|
|
620
|
-
|
|
617
|
+
l.current[r] = M, u.current[r] = M, L && L(M), t || o(r), _ || v(r, "isDirty", !1), w || v(r, "isTouched", !1), ee || v(r, "customState", null);
|
|
621
618
|
},
|
|
622
619
|
[o, v]
|
|
623
|
-
), B =
|
|
624
|
-
m.publish("onBlur", r, t,
|
|
625
|
-
}, []),
|
|
620
|
+
), B = f((r, t = R.getValues(r)) => {
|
|
621
|
+
m.publish("onBlur", r, t, R.getValues());
|
|
622
|
+
}, []), R = ae(
|
|
626
623
|
() => ({
|
|
627
624
|
subscribe: Z,
|
|
628
625
|
reset: Y,
|
|
@@ -634,7 +631,7 @@ const Oe = () => {
|
|
|
634
631
|
getFormState: V,
|
|
635
632
|
setError: e,
|
|
636
633
|
clearError: o,
|
|
637
|
-
clearErrors:
|
|
634
|
+
clearErrors: S,
|
|
638
635
|
checkValidity: T,
|
|
639
636
|
getNumberFields: oe,
|
|
640
637
|
getFieldValidity: se,
|
|
@@ -655,7 +652,7 @@ const Oe = () => {
|
|
|
655
652
|
V,
|
|
656
653
|
e,
|
|
657
654
|
o,
|
|
658
|
-
|
|
655
|
+
S,
|
|
659
656
|
T,
|
|
660
657
|
oe,
|
|
661
658
|
se,
|
|
@@ -669,7 +666,7 @@ const Oe = () => {
|
|
|
669
666
|
() => ({
|
|
670
667
|
ref: E,
|
|
671
668
|
watch: D,
|
|
672
|
-
actions:
|
|
669
|
+
actions: R,
|
|
673
670
|
registerController: A,
|
|
674
671
|
registerHookWatcher: H,
|
|
675
672
|
lastReloadedAt: d,
|
|
@@ -680,7 +677,7 @@ const Oe = () => {
|
|
|
680
677
|
[
|
|
681
678
|
E,
|
|
682
679
|
D,
|
|
683
|
-
|
|
680
|
+
R,
|
|
684
681
|
A,
|
|
685
682
|
H,
|
|
686
683
|
d,
|
|
@@ -688,23 +685,23 @@ const Oe = () => {
|
|
|
688
685
|
X,
|
|
689
686
|
m
|
|
690
687
|
]
|
|
691
|
-
), K = ae(() => ({ control: x, actions:
|
|
692
|
-
return
|
|
688
|
+
), K = ae(() => ({ control: x, actions: R, watch: D }), [d, x, R, D]);
|
|
689
|
+
return fe(() => {
|
|
693
690
|
if ([...E.current.querySelectorAll("[name]")].forEach((t) => {
|
|
694
|
-
!t.defaultValue &&
|
|
691
|
+
!t.defaultValue && !c.current.has(t.name) && l.current[t.name] && (t.defaultValue = l.current[t.name]), t.type === "number" && !k.current.includes(t.name) && k.current.push(t.name);
|
|
695
692
|
}), E.current) {
|
|
696
693
|
const t = W();
|
|
697
|
-
u.current = { ...t },
|
|
694
|
+
u.current = { ...t }, l.current = { ...t };
|
|
698
695
|
}
|
|
699
|
-
}, [d]),
|
|
696
|
+
}, [d]), fe(() => {
|
|
700
697
|
O();
|
|
701
698
|
}, []), K;
|
|
702
699
|
};
|
|
703
700
|
export {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
701
|
+
Me as Controller,
|
|
702
|
+
$e as Form,
|
|
703
|
+
ke as useController,
|
|
704
|
+
Ye as useForm,
|
|
705
|
+
Se as useFormContext,
|
|
706
|
+
_e as useWatch
|
|
710
707
|
};
|
|
@@ -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
|
|
9
|
+
*/var le;function ge(){if(le)return z;le=1;var n=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function l(h,d,g){var E=null;if(g!==void 0&&(E=""+g),d.key!==void 0&&(E=""+d.key),"key"in d){g={};for(var C in d)C!=="key"&&(g[C]=d[C])}else g=d;return d=g.ref,{$$typeof:n,type:h,key:E,ref:d!==void 0?d:null,props:g}}return z.Fragment=o,z.jsx=l,z.jsxs=l,z}var G={};/**
|
|
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
|
|
17
|
+
*/var ie;function Re(){return ie||(ie=1,process.env.NODE_ENV!=="production"&&function(){function n(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case m:return"Fragment";case B:return"Profiler";case O:return"StrictMode";case ne:return"Suspense";case oe: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 f:return"Portal";case H:return(e.displayName||"Context")+".Provider";case W:return(e._context.displayName||"Context")+".Consumer";case X:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ae:return a=e.displayName||null,a!==null?a:n(e.type)||"Memo";case Z:a=e._payload,e=e._init;try{return n(e(a))}catch{}}return null}function o(e){return""+e}function l(e){try{o(e);var a=!1}catch{a=!0}if(a){a=console;var R=a.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return R.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),o(e)}}function h(e){if(e===m)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===Z)return"<...>";try{var a=n(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function d(){var e=x.A;return e===null?null:e.getOwner()}function g(){return Error("react-stack-top-frame")}function E(e){if(M.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function C(e,a){function R(){K||(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)",a))}R.isReactWarning=!0,Object.defineProperty(e,"key",{get:R,configurable:!0})}function v(){var e=n(this.type);return q[e]||(q[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 T(e,a,R,p,j,w,L,U){return R=w.ref,e={$$typeof:c,type:e,key:a,props:w,_owner:j},(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:L}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function u(e,a,R,p,j,w,L,U){var S=a.children;if(S!==void 0)if(p)if(V(S)){for(p=0;p<S.length;p++)b(S[p]);Object.freeze&&Object.freeze(S)}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(S);if(M.call(a,"key")){S=n(e);var N=Object.keys(a).filter(function(t){return t!=="key"});p=0<N.length?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}",ee[S+p]||(N=0<N.length?"{"+N.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,S,N,S),ee[S+p]=!0)}if(S=null,R!==void 0&&(l(R),S=""+R),E(a)&&(l(a.key),S=""+a.key),"key"in a){R={};for(var te in a)te!=="key"&&(R[te]=a[te])}else R=a;return S&&C(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,S,w,j,d(),R,L,U)}function b(e){typeof e=="object"&&e!==null&&e.$$typeof===c&&e._store&&(e._store.validated=1)}var f=r,c=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),W=Symbol.for("react.consumer"),H=Symbol.for("react.context"),X=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),Z=Symbol.for("react.lazy"),P=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),x=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,V=Array.isArray,D=console.createTask?console.createTask:function(){return null};f={"react-stack-bottom-frame":function(e){return e()}};var K,q={},$=f["react-stack-bottom-frame"].bind(f,g)(),y=D(h(g)),ee={};G.Fragment=m,G.jsx=function(e,a,R,p,j){var w=1e4>x.recentlyCreatedOwnerStacks++;return u(e,a,R,!1,p,j,w?Error("react-stack-top-frame"):$,w?D(h(e)):y)},G.jsxs=function(e,a,R,p,j){var w=1e4>x.recentlyCreatedOwnerStacks++;return u(e,a,R,!0,p,j,w?Error("react-stack-top-frame"):$,w?D(h(e)):y)}}()),G}var ie;function Re(){return ie||(ie=1,process.env.NODE_ENV==="production"?se.exports=he():se.exports=ge()),se.exports}var fe=Re();const k=()=>{},de=r.createContext({ref:null,watch:k,actions:{reset:k,resetField:k,setValue:k,getValues:k,getErrors:k,getFieldStates:k,getFormStates:k,setError:k,clearError:k,clearErrors:k,checkValidity:k,getNumberFields:k,getFieldValidity:k,getDefaultValues:k,setFieldState:k,resetFieldState:k,getControlledFields:k},registerController:k,registerHookWatcher:k,lastReloadedAt:k,loadFormValues:k,getWatchValue:k,channels:{}}),ce=()=>r.useContext(de),ke=({id:n,control:o,method:l,action:h,children:d,onSubmit:g=()=>{},onInput:E=()=>{},onChange:C=()=>{},onBlur:v=()=>{},onReset:T=()=>{},numberFields:u=[],className:b,...f})=>(r.useEffect(()=>{const c=o.channels.subscribe("onChange",C),i=o.channels.subscribe("onBlur",v);return()=>{c(),i()}},[]),fe.jsx(de.Provider,{value:o,children:fe.jsx("form",{id:n,ref:o.ref,action:h,method:l,className:b,onInput:E,onSubmit:c=>{l||c.preventDefault();const i=o.loadFormValues();g(i)},onChange:c=>{const i=c.target.name;o.actions.getControlledFields().has(i)||o.actions.setValue(i,c.target.value)},onBlur:c=>{const i=c.target.name;if(o.actions.getControlledFields().has(i))return;const m=c.target.value;o.channels.publish("onBlur",i,m,o.actions.getValues())},onReset:c=>{o.actions.reset(),T(c)},...f,children:d},o.lastReloadedAt)})),be=({control:n,name:o,compute:l})=>{const{getWatchValue:h,registerHookWatcher:d}=n||ce(),g=h({name:o,compute:l}),[E,C]=r.useState(g);return r.useEffect(()=>{const v=d({name:o,compute:l,value:E,setValue:C});return()=>v.forEach(T=>T())},[]),E},me=({name:n,defaultValue:o})=>{const{actions:l,registerController:h,channels:d}=ce(),g=r.useRef(),E=l.getDefaultValues()[n]||o,[C,v]=r.useState(E),T=be({name:`fieldStates.${n}.customState`}),u=r.useCallback(c=>{l.setFieldState(n,"customState",c)},[]),b=r.useCallback((c,{shouldDirty:i=!0,shouldOnChange:m=!0}={})=>{v(c),l.setValue(n,c,{shouldDirty:i,shouldOnChange:m})},[l.setValue]),f=r.useCallback(()=>{d.publish("onBlur",n,C,l.getValues())},[]);return r.useEffect(()=>h(n,v),[]),{ref:g,name:n,defaultValue:E,value:C,onChange:b,onBlur:f,customState:T,setCustomState:u}},Se=({name:n,defaultValue:o,render:l=({ref:h,name:d,defaultValue:g,value:E,onChange:C,onBlur:v,customState:T,setCustomState:u})=>null})=>{const h=me({name:n,defaultValue:o});return l(h)},ye=["errors","fieldStates","formState"],I=n=>ye.some(o=>n.startsWith(o))?n:"values."+n,Ce=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],Ee=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let o=n.validity,l=Ce.find(h=>o[h]);if(l)return{type:l,message:n.validationMessage}};class ve{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,l){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(l),()=>{var h;return(h=this.events.get(o))==null?void 0:h.delete(l)}}publish(o,...l){const h=this.events.get(o);h&&h.forEach(d=>d(...l)),this.events.forEach((d,g)=>{o.includes(g)&&d.forEach(E=>E(...l))})}reset(){this.events.clear()}}const pe=()=>{const n=r.useRef(new ve),o=r.useCallback((d,...g)=>{n.current.publish(d,...g)},[]),l=r.useCallback((d,g)=>n.current.subscribe(d,g),[]),h=r.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:l,reset:h}},Fe=()=>{const[n,o]=r.useState(),l=r.useCallback(()=>o(new Date().toString()),[]);return[n,l]},Te=()=>{const[,n]=r.useState({});return r.useCallback(()=>n({}),[])},_e=({channels:n,getValues:o,getErrors:l,getFieldStates:h,getFormState:d})=>{const g=Te(),E=r.useCallback(({name:u,compute:b})=>{if(typeof b=="function")return b(o());if(Array.isArray(u)){const f={};return u.forEach(c=>{f[c]=E({name:c})}),f}return u.split(".").reduce((f,c)=>f&&f[c]!==void 0?f[c]:void 0,{...o(),errors:{...l()},formState:{...d()},fieldStates:{...h()}})},[]),C=r.useCallback(u=>{if(!u)return n.subscribe("values",()=>g()),o();if(typeof u=="string"){const b=I(u);return n.subscribe(b,()=>g()),E({name:u})}if(Array.isArray(u)){const b={};return u.forEach(f=>{const c=I(f);n.subscribe(c,()=>g()),b[f]=E({name:f})}),{...b}}throw new Error("Parameters of watch must be string or array of string")},[]),v=r.useCallback(({name:u,compute:b,value:f,setValue:c})=>{if(typeof b=="function")return[n.subscribe("values",()=>{const m=E({compute:b});c(m)})];if(!u)return[n.subscribe("values",()=>{c(o())})];if(typeof u=="string"){const i=I(u);return[n.subscribe(i,()=>{const O=E({name:u});c(O)})]}if(Array.isArray(u)){const i=E({name:u}),m=[];return u.forEach(O=>{const B=I(O),W=n.subscribe(B,()=>{const H=E({name:O});i[O]=H,c({...i})});m.push(W)}),m}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),T=r.useCallback((u,b)=>{if(!u)return n.subscribe("values",b);if(typeof u=="string"){const f=I(u);return n.subscribe(f,b)}if(Array.isArray(u)){const f={},c=[];return u.forEach(i=>{const m=I(i),O=n.subscribe(m,()=>{f[i]=E({name:i}),b({...f})});c.push(O)}),c}throw new Error("Parameters of name must be string or array of string")},[n]);return{watch:C,registerHookWatcher:v,getWatchValue:E,subscribe:T}},we=[],Ae={},Oe=({numberFields:n=we,defaultValues:o=Ae,shouldUnRegister:l=!1,shouldConvertNumber:h=!1}={})=>{const[d,g]=Fe(),E=r.useRef(),C=r.useRef(!1),v=r.useRef(!1),T=r.useRef(n),u=r.useRef(new Map),b=r.useRef({}),f=r.useRef({}),c=r.useRef(o),i=r.useRef(o),m=pe(),O=r.useCallback(()=>{f.current=Object.keys(i.current).reduce((t,s)=>({...t,[s]:{isError:!1,isDirty:!1,isTouched:!1,customState:null}}),{})},[]),B=r.useCallback((t={})=>{i.current={...i.current,...t},c.current={...i.current},u.current.forEach((s,F)=>{s(i.current[F])}),C.current=!1,b.current={},T.current=n,u.current=new Map,m.reset(),O(),n.length>0&&(h=!0),g()},[]),W=r.useCallback(()=>{const t=Object.fromEntries(new FormData(E.current));return u.current.forEach((F,_)=>{t[_]=c.current[_]}),h&&T.current.forEach(F=>t.hasOwnProperty(F)&&(t[F]=Number(t[F])||0)),t},[]),H=r.useCallback(()=>!!Object.values(M()).find(t=>t.isDirty),[]),X=r.useCallback(()=>!!Object.values(x()).find(t=>!!t),[]),ne=r.useCallback(t=>Ee(t.target),[]),oe=r.useCallback(()=>i.current,[]),ae=r.useCallback(()=>T.current,[]),Z=r.useCallback(()=>u.current,[]),P=r.useCallback((t,s)=>s?Array.isArray(s)?s.map(F=>t[F]):t[s]:{...t},[]),Q=r.useCallback(t=>P(c.current,t),[P]),x=r.useCallback(t=>P(b.current,t),[P]),M=r.useCallback(t=>P(f.current,t),[P]),V=r.useCallback(t=>P({isDirty:C.current,isError:v.current,errorFields:Object.keys(b.current).filter(s=>!!b.current[s]),dirtyFields:Object.keys(f.current).filter(s=>f.current[s].isDirty),touchedFields:Object.keys(f.current).filter(s=>f.current[s].isTouched)},t),[P]),{watch:D,registerHookWatcher:K,getWatchValue:q,subscribe:$}=_e({channels:m,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V}),y=r.useCallback((t,s,F)=>{const _=f.current[t];_[s]!==F&&(f.current[t]={..._,[s]:F},m.publish(`fieldStates.${t}.${s}`,F),s==="isError"&&m.publish("formState.errorFields",V("errorFields")),s==="isDirty"&&m.publish("formState.dirtyFields",V("dirtyFields")),s==="isTouched"&&m.publish("formState.touchedFields",V("touchedFields")))},[]),ee=r.useCallback(t=>{y(t,"isError",!1),y(t,"isDirty",!1),y(t,"isTouched",!1),y(t,"customState",null)},[y]),e=r.useCallback((t,s)=>{if(b.current[t]===s)return;b.current[t]=s,y(t,"isError",!!s),m.publish(`errors.${t}`,s);const _=X();v.current!==_&&(v.current=_,m.publish("formState.isError",_))},[y]),a=r.useCallback(t=>{if(!b.current[t])return;b.current[t]=null,y(t,"isError",!1),m.publish(`errors.${t}`,null);const s=X();v.current!==s&&(v.current=s,m.publish("formState.isError",s))},[y]),R=r.useCallback(()=>{if(Object.keys(b.current)===0)return;Object.keys(b.current).forEach(s=>a(s)),b.current={};const t=X();v.current!==t&&(v.current=t,m.publish("formState.isError",t))},[]),p=r.useCallback(t=>{const s=Ee(t.target);s?e(t.target.name,s):a(t.target.name)},[e,a]),j=r.useCallback((t,s,{shouldDirty:F=!0,shouldOnChange:_=!0}={})=>{if(s===c.current[t])return;h&&T.current.includes(t)&&(s=Number(s)||void 0),y(t,"isTouched",!0);const re=s!==i.current[t];F&&f.current[t].isDirty!==re&&y(t,"isDirty",re);const Y=H();C.current!==Y&&(C.current=Y,m.publish("formState.isDirty",Y)),c.current[t]=s;const J=u.current.get(t);J&&J(s),m.publish(`values.${t}`,s,{shouldDirty:F,shouldOnChange:_}),_&&m.publish("onChange",t,s,c.current)},[y]),w=r.useCallback((t,s)=>(u.current.set(t,s),()=>{l&&u.current.delete(t)}),[]),L=r.useCallback((t,{keepError:s,keepDirty:F,keepTouched:_,keepCustomState:re,defaultValue:Y})=>{const J=u.current.get(t);if(!J)throw new Error(`Cannot reset "${t}" because it's uncontrolled field`);i.current[t]=Y,c.current[t]=Y,J&&J(Y),s||a(t),F||y(t,"isDirty",!1),_||y(t,"isTouched",!1),re||y(t,"customState",null)},[a,y]),U=r.useCallback((t,s=S.getValues(t))=>{m.publish("onBlur",t,s,S.getValues())},[]),S=r.useMemo(()=>({subscribe:$,reset:B,resetField:L,setValue:j,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V,setError:e,clearError:a,clearErrors:R,checkValidity:p,getNumberFields:ae,getFieldValidity:ne,getDefaultValues:oe,setFieldState:y,triggerFieldBlur:U,resetFieldState:ee,getControlledFields:Z}),[$,B,L,j,Q,x,M,V,e,a,R,p,ae,ne,oe,y,ee,U,Z]),N=r.useMemo(()=>({ref:E,watch:D,actions:S,registerController:w,registerHookWatcher:K,lastReloadedAt:d,loadFormValues:W,getWatchValue:q,channels:m}),[E,D,S,w,K,d,W,q,m]),te=r.useMemo(()=>({control:N,actions:S,watch:D}),[d,N,S,D]);return r.useLayoutEffect(()=>{if([...E.current.querySelectorAll("[name]")].forEach(s=>{!s.defaultValue&&i.current[s.name]&&(s.defaultValue=i.current[s.name]),s.type==="number"&&!T.current.includes(s.name)&&T.current.push(s.name)}),E.current){const s=W();c.current={...s},i.current={...s}}},[d]),r.useLayoutEffect(()=>{O()},[]),te};A.Controller=Se,A.Form=ke,A.useController=me,A.useForm=Oe,A.useFormContext=ce,A.useWatch=be,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,p,S,N,S),ee[S+p]=!0)}if(S=null,R!==void 0&&(l(R),S=""+R),E(a)&&(l(a.key),S=""+a.key),"key"in a){R={};for(var te in a)te!=="key"&&(R[te]=a[te])}else R=a;return S&&C(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,S,w,j,d(),R,L,U)}function b(e){typeof e=="object"&&e!==null&&e.$$typeof===c&&e._store&&(e._store.validated=1)}var i=r,c=Symbol.for("react.transitional.element"),f=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),W=Symbol.for("react.consumer"),H=Symbol.for("react.context"),X=Symbol.for("react.forward_ref"),ne=Symbol.for("react.suspense"),oe=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),Z=Symbol.for("react.lazy"),P=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),x=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,V=Array.isArray,D=console.createTask?console.createTask:function(){return null};i={"react-stack-bottom-frame":function(e){return e()}};var K,q={},$=i["react-stack-bottom-frame"].bind(i,g)(),y=D(h(g)),ee={};G.Fragment=m,G.jsx=function(e,a,R,p,j){var w=1e4>x.recentlyCreatedOwnerStacks++;return u(e,a,R,!1,p,j,w?Error("react-stack-top-frame"):$,w?D(h(e)):y)},G.jsxs=function(e,a,R,p,j){var w=1e4>x.recentlyCreatedOwnerStacks++;return u(e,a,R,!0,p,j,w?Error("react-stack-top-frame"):$,w?D(h(e)):y)}}()),G}var fe;function ke(){return fe||(fe=1,process.env.NODE_ENV==="production"?se.exports=ge():se.exports=Re()),se.exports}var de=ke();const k=()=>{},be=r.createContext({ref:null,watch:k,actions:{reset:k,resetField:k,setValue:k,getValues:k,getErrors:k,getFieldStates:k,getFormStates:k,setError:k,clearError:k,clearErrors:k,checkValidity:k,getNumberFields:k,getFieldValidity:k,getDefaultValues:k,setFieldState:k,resetFieldState:k,getControlledFields:k},registerController:k,registerHookWatcher:k,lastReloadedAt:k,loadFormValues:k,getWatchValue:k,channels:{}}),ce=()=>r.useContext(be),Se=({id:n,control:o,method:l,action:h,children:d,onSubmit:g=()=>{},onInput:E=()=>{},onChange:C=()=>{},onBlur:v=()=>{},onReset:T=()=>{},numberFields:u=[],className:b,...i})=>(r.useEffect(()=>{const c=o.channels.subscribe("onChange",C),f=o.channels.subscribe("onBlur",v);return()=>{c(),f()}},[]),de.jsx(be.Provider,{value:o,children:de.jsx("form",{id:n,ref:o.ref,action:h,method:l,className:b,onInput:E,onSubmit:c=>{l||c.preventDefault();const f=o.loadFormValues();g(f)},onChange:c=>{const f=c.target.name;o.actions.getControlledFields().has(f)||o.actions.setValue(f,c.target.value)},onBlur:c=>{const f=c.target.name;if(o.actions.getControlledFields().has(f))return;const m=c.target.value;o.channels.publish("onBlur",f,m,o.actions.getValues())},onReset:c=>{o.actions.reset(),T(c)},...i,children:d},o.lastReloadedAt)})),me=({control:n,name:o,compute:l})=>{const{getWatchValue:h,registerHookWatcher:d}=n||ce(),g=h({name:o,compute:l}),[E,C]=r.useState(g);return r.useEffect(()=>{const v=d({name:o,compute:l,value:E,setValue:C});return()=>v.forEach(T=>T())},[]),E},Ee=({name:n,defaultValue:o})=>{const{actions:l,registerController:h,channels:d}=ce(),g=r.useRef(),E=l.getDefaultValues()[n]||o||"",[C,v]=r.useState(E),T=me({name:`fieldStates.${n}.customState`}),u=r.useCallback(c=>{l.setFieldState(n,"customState",c)},[]),b=r.useCallback((c,{shouldDirty:f=!0,shouldOnChange:m=!0}={})=>{v(c),l.setValue(n,c,{shouldDirty:f,shouldOnChange:m})},[l.setValue]),i=r.useCallback(()=>{d.publish("onBlur",n,C,l.getValues())},[]);return r.useEffect(()=>h(n,v),[]),{ref:g,name:n,defaultValue:E,value:C,onChange:b,onBlur:i,customState:T,setCustomState:u}},ye=({name:n,defaultValue:o,render:l=({ref:h,name:d,defaultValue:g,value:E,onChange:C,onBlur:v,customState:T,setCustomState:u})=>null})=>{const h=Ee({name:n,defaultValue:o});return l(h)},Ce=["errors","fieldStates","formState"],I=n=>Ce.some(o=>n.startsWith(o))?n:"values."+n,ve=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],he=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let o=n.validity,l=ve.find(h=>o[h]);if(l)return{type:l,message:n.validationMessage}};class pe{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,l){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(l),()=>{var h;return(h=this.events.get(o))==null?void 0:h.delete(l)}}publish(o,...l){const h=this.events.get(o);h&&h.forEach(d=>d(...l)),this.events.forEach((d,g)=>{o.includes(g)&&d.forEach(E=>E(...l))})}reset(){this.events.clear()}}const Fe=()=>{const n=r.useRef(new pe),o=r.useCallback((d,...g)=>{n.current.publish(d,...g)},[]),l=r.useCallback((d,g)=>n.current.subscribe(d,g),[]),h=r.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:l,reset:h}},Te=()=>{const[n,o]=r.useState(),l=r.useCallback(()=>o(new Date().toString()),[]);return[n,l]},_e=()=>{const[,n]=r.useState({});return r.useCallback(()=>n({}),[])},we=({channels:n,getValues:o,getErrors:l,getFieldStates:h,getFormState:d})=>{const g=_e(),E=r.useCallback(({name:u,compute:b})=>{if(typeof b=="function")return b(o());if(Array.isArray(u)){const i={};return u.forEach(c=>{i[c]=E({name:c})}),i}return u.split(".").reduce((i,c)=>i&&i[c]!==void 0?i[c]:void 0,{...o(),errors:{...l()},formState:{...d()},fieldStates:{...h()}})},[]),C=r.useCallback(u=>{if(!u)return n.subscribe("values",()=>g()),o();if(typeof u=="string"){const b=I(u);return n.subscribe(b,()=>g()),E({name:u})}if(Array.isArray(u)){const b={};return u.forEach(i=>{const c=I(i);n.subscribe(c,()=>g()),b[i]=E({name:i})}),{...b}}throw new Error("Parameters of watch must be string or array of string")},[]),v=r.useCallback(({name:u,compute:b,value:i,setValue:c})=>{if(typeof b=="function")return[n.subscribe("values",()=>{const m=E({compute:b});c(m)})];if(!u)return[n.subscribe("values",()=>{c(o())})];if(typeof u=="string"){const f=I(u);return[n.subscribe(f,()=>{const O=E({name:u});c(O)})]}if(Array.isArray(u)){const f=E({name:u}),m=[];return u.forEach(O=>{const B=I(O),W=n.subscribe(B,()=>{const H=E({name:O});f[O]=H,c({...f})});m.push(W)}),m}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),T=r.useCallback((u,b)=>{if(!u)return n.subscribe("values",b);if(typeof u=="string"){const i=I(u);return n.subscribe(i,b)}if(Array.isArray(u)){const i={},c=[];return u.forEach(f=>{const m=I(f),O=n.subscribe(m,()=>{i[f]=E({name:f}),b({...i})});c.push(O)}),c}throw new Error("Parameters of name must be string or array of string")},[n]);return{watch:C,registerHookWatcher:v,getWatchValue:E,subscribe:T}},ue={isError:!1,isDirty:!1,isTouched:!1,customState:null},Ae=[],Oe={},je=({numberFields:n=Ae,defaultValues:o=Oe,shouldUnRegister:l=!1,shouldConvertNumber:h=!1}={})=>{const[d,g]=Te(),E=r.useRef(),C=r.useRef(!1),v=r.useRef(!1),T=r.useRef(n),u=r.useRef(new Map),b=r.useRef({}),i=r.useRef({}),c=r.useRef(o),f=r.useRef(o),m=Fe(),O=r.useCallback(()=>{i.current=Object.keys(f.current).reduce((t,s)=>({...t,[s]:{...ue}}),{})},[]),B=r.useCallback((t={})=>{f.current={...f.current,...t},c.current={...f.current},u.current.forEach((s,F)=>{s(f.current[F])}),C.current=!1,b.current={},T.current=n,u.current=new Map,m.reset(),O(),n.length>0&&(h=!0),g()},[]),W=r.useCallback(()=>{const t=Object.fromEntries(new FormData(E.current));return u.current.forEach((F,_)=>{t[_]=c.current[_]}),h&&T.current.forEach(F=>t.hasOwnProperty(F)&&(t[F]=Number(t[F])||0)),t},[]),H=r.useCallback(()=>!!Object.values(M()).find(t=>t.isDirty),[]),X=r.useCallback(()=>!!Object.values(x()).find(t=>!!t),[]),ne=r.useCallback(t=>he(t.target),[]),oe=r.useCallback(()=>f.current,[]),ae=r.useCallback(()=>T.current,[]),Z=r.useCallback(()=>u.current,[]),P=r.useCallback((t,s)=>s?Array.isArray(s)?s.map(F=>t[F]):t[s]:{...t},[]),Q=r.useCallback(t=>P(c.current,t),[P]),x=r.useCallback(t=>P(b.current,t),[P]),M=r.useCallback(t=>P(i.current,t),[P]),V=r.useCallback(t=>P({isDirty:C.current,isError:v.current,errorFields:Object.keys(b.current).filter(s=>!!b.current[s]),dirtyFields:Object.keys(i.current).filter(s=>i.current[s].isDirty),touchedFields:Object.keys(i.current).filter(s=>i.current[s].isTouched)},t),[P]),{watch:D,registerHookWatcher:K,getWatchValue:q,subscribe:$}=we({channels:m,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V}),y=r.useCallback((t,s,F)=>{const _=i.current[t]||{...ue};_[s]!==F&&(i.current[t]={..._,[s]:F},m.publish(`fieldStates.${t}.${s}`,F),s==="isError"&&m.publish("formState.errorFields",V("errorFields")),s==="isDirty"&&m.publish("formState.dirtyFields",V("dirtyFields")),s==="isTouched"&&m.publish("formState.touchedFields",V("touchedFields")))},[]),ee=r.useCallback(t=>{y(t,"isError",!1),y(t,"isDirty",!1),y(t,"isTouched",!1),y(t,"customState",null)},[y]),e=r.useCallback((t,s)=>{if(b.current[t]===s)return;b.current[t]=s,y(t,"isError",!!s),m.publish(`errors.${t}`,s);const _=X();v.current!==_&&(v.current=_,m.publish("formState.isError",_))},[y]),a=r.useCallback(t=>{if(!b.current[t])return;b.current[t]=null,y(t,"isError",!1),m.publish(`errors.${t}`,null);const s=X();v.current!==s&&(v.current=s,m.publish("formState.isError",s))},[y]),R=r.useCallback(()=>{if(Object.keys(b.current)===0)return;Object.keys(b.current).forEach(s=>a(s)),b.current={};const t=X();v.current!==t&&(v.current=t,m.publish("formState.isError",t))},[]),p=r.useCallback(t=>{const s=he(t.target);s?e(t.target.name,s):a(t.target.name)},[e,a]),j=r.useCallback((t,s,{shouldDirty:F=!0,shouldOnChange:_=!0}={})=>{if(s===c.current[t])return;h&&T.current.includes(t)&&(s=Number(s)||void 0),y(t,"isTouched",!0);const re=s!==f.current[t];F&&i.current[t].isDirty!==re&&y(t,"isDirty",re);const Y=H();C.current!==Y&&(C.current=Y,m.publish("formState.isDirty",Y)),c.current[t]=s;const J=u.current.get(t);J&&J(s),m.publish(`values.${t}`,s,{shouldDirty:F,shouldOnChange:_}),_&&m.publish("onChange",t,s,c.current)},[y]),w=r.useCallback((t,s)=>(u.current.set(t,s),i.current[t]={...ue},()=>{l&&u.current.delete(t)}),[]),L=r.useCallback((t,{keepError:s,keepDirty:F,keepTouched:_,keepCustomState:re,defaultValue:Y})=>{const J=u.current.get(t);if(!J)throw new Error(`Cannot reset "${t}" because it's uncontrolled field`);f.current[t]=Y,c.current[t]=Y,J&&J(Y),s||a(t),F||y(t,"isDirty",!1),_||y(t,"isTouched",!1),re||y(t,"customState",null)},[a,y]),U=r.useCallback((t,s=S.getValues(t))=>{m.publish("onBlur",t,s,S.getValues())},[]),S=r.useMemo(()=>({subscribe:$,reset:B,resetField:L,setValue:j,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V,setError:e,clearError:a,clearErrors:R,checkValidity:p,getNumberFields:ae,getFieldValidity:ne,getDefaultValues:oe,setFieldState:y,triggerFieldBlur:U,resetFieldState:ee,getControlledFields:Z}),[$,B,L,j,Q,x,M,V,e,a,R,p,ae,ne,oe,y,ee,U,Z]),N=r.useMemo(()=>({ref:E,watch:D,actions:S,registerController:w,registerHookWatcher:K,lastReloadedAt:d,loadFormValues:W,getWatchValue:q,channels:m}),[E,D,S,w,K,d,W,q,m]),te=r.useMemo(()=>({control:N,actions:S,watch:D}),[d,N,S,D]);return r.useLayoutEffect(()=>{if([...E.current.querySelectorAll("[name]")].forEach(s=>{!s.defaultValue&&!u.current.has(s.name)&&f.current[s.name]&&(s.defaultValue=f.current[s.name]),s.type==="number"&&!T.current.includes(s.name)&&T.current.push(s.name)}),E.current){const s=W();c.current={...s},f.current={...s}}},[d]),r.useLayoutEffect(()=>{O()},[]),te};A.Controller=ye,A.Form=Se,A.useController=Ee,A.useForm=je,A.useFormContext=ce,A.useWatch=me,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|