react-simple-formkit 2.1.7 → 2.1.9
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var oe={exports:{}},ee={};/**
|
|
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 ae;function Ee(){if(ae)return ee;ae=1;var n=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function
|
|
9
|
+
*/var ae;function Ee(){if(ae)return ee;ae=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 ce;function ge(){return ce||(ce=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
|
|
17
|
+
*/var ce;function ge(){return ce||(ce=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 i: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} />`,F,k,P,k),Z[k+F]=!0)}if(k=null,R!==void 0&&(f(R),k=""+R),E(a)&&(f(a.key),k=""+a.key),"key"in a){R={};for(var Q in a)Q!=="key"&&(R[Q]=a[Q])}else R=a;return k&&p(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,k,A,w,b(),R,I,B)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===u&&e._store&&(e._store.validated=1)}var l=t,u=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),Y=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=l.__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};l={"react-stack-bottom-frame":function(e){return e()}};var G,H={},X=l["react-stack-bottom-frame"].bind(l,h)(),C=V(g(h)),Z={};re.Fragment=d,re.jsx=function(e,a,R,F,w){var A=1e4>x.recentlyCreatedOwnerStacks++;return c(e,a,R,!1,F,w,A?Error("react-stack-top-frame"):X,A?V(g(e)):C)},re.jsxs=function(e,a,R,F,w){var A=1e4>x.recentlyCreatedOwnerStacks++;return c(e,a,R,!0,F,w,A?Error("react-stack-top-frame"):X,A?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=()=>{},de=t.createContext({ref:null,watch:S,actions:{reset:S,resetField:S,setValue:S,getValues:S,getErrors:S,getFieldStates:S,getFormStates:S,setError:S,clearError:S,clearErrors:S,checkValidity:S,getNumberFields:S,getFieldValidity:S,getDefaultValues:S,setFieldState:S,resetFieldState:S,getControlledFields:S},registerController:S,registerHookWatcher:S,lastReloadedAt:S,loadFormValues:S,getWatchValue:S,channels:{}}),ue=()=>t.useContext(de),Re=({id:n,control:o,method:f,action:g,children:b,onSubmit:h=()=>{},onInput:E=()=>{},onChange:p=()=>{},onBlur:v=()=>{},onReset:T=()=>{},numberFields:c=[],className:m,...l})=>(t.useEffect(()=>{const u=o.channels.subscribe("onChange",p),i=o.channels.subscribe("onBlur",v);return()=>{u(),i()}},[]),ie.jsx(de.Provider,{value:o,children:ie.jsx("form",{id:n,ref:o.ref,action:g,method:f,className:m,onInput:E,onSubmit:u=>{f||u.preventDefault();const i=o.loadFormValues();h(i)},onChange:u=>{const i=u.target.name;o.actions.getControlledFields().has(i)||o.actions.setValue(i,u.target.value)},onBlur:u=>{const i=u.target.name;if(o.actions.getControlledFields().has(i))return;const d=u.target.value;o.channels.publish("onBlur",i,d,o.actions.getValues())},onReset:u=>{o.actions.reset(),T(u)},...l,children:b},o.lastReloadedAt)})),be=({control:n,name:o,compute:f})=>{const{getWatchValue:g,registerHookWatcher:b}=n||ue(),h=g({name:o,compute:f}),[E,p]=t.useState(h);return t.useEffect(()=>{const v=b({name:o,compute:f,value:E,setValue:p});return()=>v.forEach(T=>T())},[]),E},me=({name:n,defaultValue:o})=>{const{actions:f,registerController:g,channels:b}=ue(),h=t.useRef(),E=f.getDefaultValues()[n]||o,[p,v]=t.useState(E),T=be({name:`fieldStates.${n}.customState`}),c=t.useCallback(u=>{f.setFieldState(n,"customState",u)},[]),m=t.useCallback((u,{shouldDirty:i=!0,shouldOnChange:d=!0}={})=>{v(u),f.setValue(n,u,{shouldDirty:i,shouldOnChange:d})},[f.setValue]),l=t.useCallback(()=>{b.publish("onBlur",n,p,f.getValues())},[]);return t.useEffect(()=>g(n,v),[]),{ref:h,name:n,defaultValue:E,value:p,onChange:m,onBlur:l,customState:T,setCustomState:c}},ke=({name:n,defaultValue:o,render:f=({ref:g,name:b,defaultValue:h,value:E,onChange:p,onBlur:v,customState:T,setCustomState:c})=>null})=>{const g=me({name:n,defaultValue:o});return f(g)},Se=["errors","fieldStates","formState"],U=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,f=Ce.find(g=>o[g]);if(f)return{type:f,message:n.validationMessage}};class pe{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,f){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(f),()=>{var g;return(g=this.events.get(o))==null?void 0:g.delete(f)}}publish(o,...f){const g=this.events.get(o);g&&g.forEach(b=>b(...f)),this.events.forEach((b,h)=>{o.includes(h)&&b.forEach(E=>E(...f))})}reset(){this.events.clear()}}const ye=()=>{const n=t.useRef(new pe),o=t.useCallback((b,...h)=>{n.current.publish(b,...h)},[]),f=t.useCallback((b,h)=>n.current.subscribe(b,h),[]),g=t.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:f,reset:g}},ve=()=>{const[n,o]=t.useState(),f=t.useCallback(()=>o(new Date().toString()),[]);return[n,f]},Fe=()=>{const[,n]=t.useState({});return t.useCallback(()=>n({}),[])},Te=({channels:n,getValues:o,getErrors:f,getFieldStates:g,getFormState:b})=>{const h=Fe(),E=t.useCallback(({name:c,compute:m})=>{if(typeof m=="function")return m(o());if(Array.isArray(c)){const l={};return c.forEach(u=>{l[u]=E({name:u})}),l}return c.replaceAll(/\[(\d+)\]/g,".$1").split(".").reduce((l,u)=>l&&l[u]!==void 0?l[u]:void 0,{...o(),errors:{...f()},formState:{...b()},fieldStates:{...g()}})},[]),p=t.useCallback(c=>{if(!c)return n.subscribe("values",()=>{h()}),o();if(typeof c=="string"){const m=U(c);return n.subscribe(m,()=>{h()}),E({name:c})}if(Array.isArray(c)){const m={};return c.forEach(l=>{const u=U(l);n.subscribe(u,()=>{h()}),m[l]=E({name:l})}),m}throw new Error("Parameters of watch must be string or array of string")},[]),v=t.useCallback(({name:c,compute:m,value:l,setValue:u})=>{if(typeof m=="function")return[n.subscribe("values",()=>{const d=E({compute:m});d!==l&&u(d)})];if(c)if(typeof c=="string"){const i=U(c);return[n.subscribe(i,()=>{const _=E({name:c});_!==l&&u(_)})]}else if(Array.isArray(c)){const i=E({name:c}),d=[];return c.forEach(_=>{const $=U(_),D=n.subscribe($,()=>{const Y=E({name:_});i[_]!==Y&&(i[_]=Y,u({...i}))});d.push(D)}),d}else throw new Error("Parameters of name must be string or array of string or compute must be a function");else return[n.subscribe("values",()=>{u(o())})]},[]),T=t.useCallback((c,m)=>{if(typeof c===void 0)return n.subscribe("values",m);if(typeof c=="string"){const l=U(c);return n.subscribe(l,m)}if(Array.isArray(c)){const l={},u=[];return c.forEach(i=>{const d=U(i),_=n.subscribe(d,()=>{l[i]=E({name:i}),m(l)});u.push(_)}),u}},[n]);return{watch:p,registerHookWatcher:v,getWatchValue:E,subscribe:T}},_e=[],Ae={},we=({numberFields:n=_e,defaultValues:o=Ae,shouldUnRegister:f=!1,shouldConvertNumber:g=!1}={})=>{const[b,h]=ve(),E=t.useRef(),p=t.useRef(!1),v=t.useRef(!1),T=t.useRef(n),c=t.useRef(new Map),m=t.useRef({}),l=t.useRef({}),u=t.useRef(o),i=t.useRef(o),d=ye(),_=t.useCallback(()=>{l.current=Object.keys(i.current).reduce((r,s)=>({...r,[s]:{isError:!1,isDirty:!1,isTouched:!1,customState:null}}),{})},[]),$=t.useCallback((r={})=>{i.current={...i.current,...r},u.current={...i.current},c.current.forEach((s,y)=>{s(i.current[y])}),p.current=!1,m.current={},T.current=n,c.current=new Map,d.reset(),_(),n.length>0&&(g=!0),h()},[]),D=t.useCallback(()=>{const r=Object.fromEntries(new FormData(E.current));return c.current.forEach(y=>{r[y]=u.current[y]}),g&&T.current.forEach(y=>r.hasOwnProperty(y)&&(r[y]=Number(r[y])||0)),r},[]),Y=t.useCallback(()=>!!Object.values(W()).find(r=>r.isDirty),[]),q=t.useCallback(()=>!!Object.values(x()).find(r=>!!r),[]),te=t.useCallback(r=>fe(r.target),[]),se=t.useCallback(()=>i.current,[]),ne=t.useCallback(()=>T.current,[]),J=t.useCallback(()=>c.current,[]),j=t.useCallback((r,s)=>s?Array.isArray(s)?s.map(y=>r[y]):r[s]:{...r},[]),z=t.useCallback(r=>j(u.current,r),[j]),x=t.useCallback(r=>j(m.current,r),[j]),W=t.useCallback(r=>j(l.current,r),[j]),N=t.useCallback(r=>j({isDirty:p.current,isError:v.current,errorFields:Object.keys(m.current).filter(s=>!!m.current[s]),dirtyFields:Object.keys(l.current).filter(s=>l.current[s].isDirty),touchedFields:Object.keys(l.current).filter(s=>l.current[s].isTouched)},r),[j]),{watch:V,registerHookWatcher:G,getWatchValue:H,subscribe:X}=Te({channels:d,getValues:z,getErrors:x,getFieldStates:W,getFormState:N}),C=t.useCallback((r,s,y)=>{const O=l.current[r];O[s]!==y&&(l.current[r]={...O,[s]:y},d.publish(`fieldStates.${r}.${s}`,y),s==="isError"&&d.publish("formState.errorFields",N("errorFields")),s==="isDirty"&&d.publish("formState.dirtyFields",N("dirtyFields")),s==="isTouched"&&d.publish("formState.touchedFields",N("touchedFields")))},[]),Z=t.useCallback(r=>{C(r,"isError",!1),C(r,"isDirty",!1),C(r,"isTouched",!1),C(r,"customState",null)},[C]),e=t.useCallback((r,s)=>{if(m.current[r]===s)return;m.current[r]=s,C(r,"isError",!!s),d.publish(`errors.${r}`,s);const O=q();v.current!==O&&(v.current=O,d.publish("formState.isError",O))},[C]),a=t.useCallback(r=>{if(!m.current[r])return;m.current[r]=null,C(r,"isError",!1),d.publish(`errors.${r}`,null);const s=q();v.current!==s&&(v.current=s,d.publish("formState.isError",s))},[C]),R=t.useCallback(()=>{if(Object.keys(m.current)===0)return;m.current={},d.publish("errors",m.current);const r=q();v.current!==r&&(v.current=r,d.publish("formState.isError",r))},[]),F=t.useCallback(r=>{const s=fe(r.target);s?e(r.target.name,s):a(r.target.name)},[e,a]),w=t.useCallback((r,s,{shouldDirty:y=!0,shouldOnChange:O=!0}={})=>{if(s===u.current[r])return;g&&T.current.includes(r)&&(s=Number(s)||void 0),C(r,"isTouched",!0);const K=s!==i.current[r];y&&l.current[r].isDirty!==K&&C(r,"isDirty",K);const M=Y();p.current!==M&&(p.current=M,d.publish("formState.isDirty",M)),u.current[r]=s;const L=c.current.get(r);L&&L(s),d.publish(`values.${r}`,s,{shouldDirty:y,shouldOnChange:O}),O&&d.publish("onChange",r,s,u.current)},[C]),A=t.useCallback((r,s)=>(c.current.set(r,s),()=>{f&&c.current.delete(r)}),[]),I=t.useCallback((r,{keepError:s,keepDirty:y,keepTouched:O,keepCustomState:K,defaultValue:M})=>{const L=c.current.get(r);if(!L)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);i.current[r]=M,u.current[r]=M,L&&L(M),s||a(r),y||C(r,"isDirty",!1),O||C(r,"isTouched",!1),K||C(r,"customState",null)},[a,C]),B=t.useCallback((r,s=k.getValues(r))=>{d.publish("onBlur",r,s,k.getValues())},[]),k=t.useMemo(()=>({subscribe:X,reset:$,resetField:I,setValue:w,getValues:z,getErrors:x,getFieldStates:W,getFormState:N,setError:e,clearError:a,clearErrors:R,checkValidity:F,getNumberFields:ne,getFieldValidity:te,getDefaultValues:se,setFieldState:C,triggerFieldBlur:B,resetFieldState:Z,getControlledFields:J}),[X,$,I,w,z,x,W,N,e,a,R,F,ne,te,se,C,Z,B,J]),P=t.useMemo(()=>({ref:E,watch:V,actions:k,registerController:A,registerHookWatcher:G,lastReloadedAt:b,loadFormValues:D,getWatchValue:H,channels:d}),[E,V,k,A,G,b,D,H,d]),Q=t.useMemo(()=>({control:P,actions:k,watch:V}),[b,P,k,V]);return t.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=D();u.current={...s},i.current={...s}}},[b]),t.useLayoutEffect(()=>{_()},[]),Q};exports.Controller=ke;exports.Form=Re;exports.useController=me;exports.useForm=we;exports.useFormContext=ue;exports.useWatch=be;
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Re, { createContext as Se, useContext as pe, useEffect as ie, useState as ce, useRef as
|
|
1
|
+
import Re, { createContext as Se, useContext as pe, useEffect as ie, useState as ce, useRef as C, useCallback as l, useMemo as ae, useLayoutEffect as le } from "react";
|
|
2
2
|
var ue = { exports: {} }, re = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
@@ -10,26 +10,26 @@ var ue = { exports: {} }, re = {};
|
|
|
10
10
|
* LICENSE file in the root directory of this source tree.
|
|
11
11
|
*/
|
|
12
12
|
var fe;
|
|
13
|
-
function
|
|
13
|
+
function ve() {
|
|
14
14
|
if (fe) return re;
|
|
15
15
|
fe = 1;
|
|
16
16
|
var s = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
17
|
-
function
|
|
17
|
+
function a(g, d, h) {
|
|
18
18
|
var E = null;
|
|
19
|
-
if (h !== void 0 && (E = "" + h),
|
|
19
|
+
if (h !== void 0 && (E = "" + h), d.key !== void 0 && (E = "" + d.key), "key" in d) {
|
|
20
20
|
h = {};
|
|
21
|
-
for (var
|
|
22
|
-
|
|
23
|
-
} else h =
|
|
24
|
-
return
|
|
21
|
+
for (var y in d)
|
|
22
|
+
y !== "key" && (h[y] = d[y]);
|
|
23
|
+
} else h = d;
|
|
24
|
+
return d = h.ref, {
|
|
25
25
|
$$typeof: s,
|
|
26
26
|
type: g,
|
|
27
27
|
key: E,
|
|
28
|
-
ref:
|
|
28
|
+
ref: d !== void 0 ? d : null,
|
|
29
29
|
props: h
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return re.Fragment = n, re.jsx =
|
|
32
|
+
return re.Fragment = n, re.jsx = a, re.jsxs = a, re;
|
|
33
33
|
}
|
|
34
34
|
var te = {};
|
|
35
35
|
/**
|
|
@@ -42,7 +42,7 @@ var te = {};
|
|
|
42
42
|
* LICENSE file in the root directory of this source tree.
|
|
43
43
|
*/
|
|
44
44
|
var de;
|
|
45
|
-
function
|
|
45
|
+
function ye() {
|
|
46
46
|
return de || (de = 1, process.env.NODE_ENV !== "production" && function() {
|
|
47
47
|
function s(e) {
|
|
48
48
|
if (e == null) return null;
|
|
@@ -50,11 +50,11 @@ function ve() {
|
|
|
50
50
|
return e.$$typeof === G ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
|
-
case
|
|
53
|
+
case m:
|
|
54
54
|
return "Fragment";
|
|
55
55
|
case Y:
|
|
56
56
|
return "Profiler";
|
|
57
|
-
case
|
|
57
|
+
case O:
|
|
58
58
|
return "StrictMode";
|
|
59
59
|
case se:
|
|
60
60
|
return "Suspense";
|
|
@@ -69,19 +69,19 @@ function ve() {
|
|
|
69
69
|
), e.$$typeof) {
|
|
70
70
|
case i:
|
|
71
71
|
return "Portal";
|
|
72
|
-
case
|
|
72
|
+
case q:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
74
|
case W:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
76
|
case J:
|
|
77
|
-
var
|
|
78
|
-
return e = e.displayName, e || (e =
|
|
77
|
+
var o = e.render;
|
|
78
|
+
return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
79
79
|
case oe:
|
|
80
|
-
return
|
|
80
|
+
return o = e.displayName || null, o !== null ? o : s(e.type) || "Memo";
|
|
81
81
|
case z:
|
|
82
|
-
|
|
82
|
+
o = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return s(e(
|
|
84
|
+
return s(e(o));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -90,35 +90,35 @@ function ve() {
|
|
|
90
90
|
function n(e) {
|
|
91
91
|
return "" + e;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function a(e) {
|
|
94
94
|
try {
|
|
95
95
|
n(e);
|
|
96
|
-
var
|
|
96
|
+
var o = !1;
|
|
97
97
|
} catch {
|
|
98
|
-
|
|
98
|
+
o = !0;
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
var R =
|
|
100
|
+
if (o) {
|
|
101
|
+
o = console;
|
|
102
|
+
var R = o.error, T = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
103
|
return R.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
|
|
107
107
|
), n(e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function g(e) {
|
|
111
|
-
if (e ===
|
|
111
|
+
if (e === m) return "<>";
|
|
112
112
|
if (typeof e == "object" && e !== null && e.$$typeof === z)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var
|
|
116
|
-
return
|
|
115
|
+
var o = s(e);
|
|
116
|
+
return o ? "<" + o + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function d() {
|
|
122
122
|
var e = N.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
@@ -127,16 +127,16 @@ function ve() {
|
|
|
127
127
|
}
|
|
128
128
|
function E(e) {
|
|
129
129
|
if ($.call(e, "key")) {
|
|
130
|
-
var
|
|
131
|
-
if (
|
|
130
|
+
var o = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
131
|
+
if (o && o.isReactWarning) return !1;
|
|
132
132
|
}
|
|
133
133
|
return e.key !== void 0;
|
|
134
134
|
}
|
|
135
|
-
function
|
|
135
|
+
function y(e, o) {
|
|
136
136
|
function R() {
|
|
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
142
|
R.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
@@ -150,13 +150,13 @@ function ve() {
|
|
|
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,
|
|
154
|
-
return R =
|
|
155
|
-
$$typeof:
|
|
153
|
+
function k(e, o, R, T, j, A, I, B) {
|
|
154
|
+
return R = A.ref, e = {
|
|
155
|
+
$$typeof: u,
|
|
156
156
|
type: e,
|
|
157
|
-
key:
|
|
158
|
-
props:
|
|
159
|
-
_owner:
|
|
157
|
+
key: o,
|
|
158
|
+
props: A,
|
|
159
|
+
_owner: j
|
|
160
160
|
}, (R !== void 0 ? R : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
162
|
get: F
|
|
@@ -174,111 +174,111 @@ function ve() {
|
|
|
174
174
|
configurable: !1,
|
|
175
175
|
enumerable: !1,
|
|
176
176
|
writable: !0,
|
|
177
|
-
value:
|
|
177
|
+
value: I
|
|
178
178
|
}), Object.defineProperty(e, "_debugTask", {
|
|
179
179
|
configurable: !1,
|
|
180
180
|
enumerable: !1,
|
|
181
181
|
writable: !0,
|
|
182
|
-
value:
|
|
182
|
+
value: B
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function c(e,
|
|
186
|
-
var S =
|
|
185
|
+
function c(e, o, R, T, j, A, I, B) {
|
|
186
|
+
var S = o.children;
|
|
187
187
|
if (S !== void 0)
|
|
188
|
-
if (
|
|
188
|
+
if (T)
|
|
189
189
|
if (V(S)) {
|
|
190
|
-
for (
|
|
191
|
-
|
|
190
|
+
for (T = 0; T < S.length; T++)
|
|
191
|
+
b(S[T]);
|
|
192
192
|
Object.freeze && Object.freeze(S);
|
|
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
|
|
198
|
-
if ($.call(
|
|
197
|
+
else b(S);
|
|
198
|
+
if ($.call(o, "key")) {
|
|
199
199
|
S = s(e);
|
|
200
|
-
var x = Object.keys(
|
|
200
|
+
var x = Object.keys(o).filter(function(r) {
|
|
201
201
|
return r !== "key";
|
|
202
202
|
});
|
|
203
|
-
|
|
203
|
+
T = 0 < x.length ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}", Q[S + 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} />
|
|
207
207
|
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
|
S,
|
|
212
212
|
x,
|
|
213
213
|
S
|
|
214
|
-
), Q[S +
|
|
214
|
+
), Q[S + T] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (S = null, R !== void 0 && (
|
|
216
|
+
if (S = null, R !== void 0 && (a(R), S = "" + R), E(o) && (a(o.key), S = "" + o.key), "key" in o) {
|
|
217
217
|
R = {};
|
|
218
|
-
for (var K in
|
|
219
|
-
K !== "key" && (R[K] =
|
|
220
|
-
} else R =
|
|
221
|
-
return S &&
|
|
218
|
+
for (var K in o)
|
|
219
|
+
K !== "key" && (R[K] = o[K]);
|
|
220
|
+
} else R = o;
|
|
221
|
+
return S && y(
|
|
222
222
|
R,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
224
|
), k(
|
|
225
225
|
e,
|
|
226
226
|
S,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
A,
|
|
228
|
+
j,
|
|
229
|
+
d(),
|
|
230
230
|
R,
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
I,
|
|
232
|
+
B
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
235
|
+
function b(e) {
|
|
236
|
+
typeof e == "object" && e !== null && e.$$typeof === u && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var f = Re, u = Symbol.for("react.transitional.element"), i = 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 = f.__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
|
+
f = {
|
|
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 = f["react-stack-bottom-frame"].bind(
|
|
247
|
+
f,
|
|
248
248
|
h
|
|
249
|
-
)(),
|
|
250
|
-
te.Fragment =
|
|
251
|
-
var
|
|
249
|
+
)(), v = D(g(h)), Q = {};
|
|
250
|
+
te.Fragment = m, te.jsx = function(e, o, R, T, j) {
|
|
251
|
+
var A = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return c(
|
|
253
253
|
e,
|
|
254
|
-
|
|
254
|
+
o,
|
|
255
255
|
R,
|
|
256
256
|
!1,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
T,
|
|
258
|
+
j,
|
|
259
|
+
A ? Error("react-stack-top-frame") : Z,
|
|
260
|
+
A ? D(g(e)) : v
|
|
261
261
|
);
|
|
262
|
-
}, te.jsxs = function(e,
|
|
263
|
-
var
|
|
262
|
+
}, te.jsxs = function(e, o, R, T, j) {
|
|
263
|
+
var A = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return c(
|
|
265
265
|
e,
|
|
266
|
-
|
|
266
|
+
o,
|
|
267
267
|
R,
|
|
268
268
|
!0,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
T,
|
|
270
|
+
j,
|
|
271
|
+
A ? Error("react-stack-top-frame") : Z,
|
|
272
|
+
A ? D(g(e)) : v
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
275
|
}()), te;
|
|
276
276
|
}
|
|
277
277
|
var be;
|
|
278
|
-
function
|
|
279
|
-
return be || (be = 1, process.env.NODE_ENV === "production" ? ue.exports =
|
|
278
|
+
function Fe() {
|
|
279
|
+
return be || (be = 1, process.env.NODE_ENV === "production" ? ue.exports = ve() : ue.exports = ye()), ue.exports;
|
|
280
280
|
}
|
|
281
|
-
var me =
|
|
281
|
+
var me = Fe();
|
|
282
282
|
const p = () => {
|
|
283
283
|
}, ge = Se({
|
|
284
284
|
ref: null,
|
|
@@ -311,26 +311,26 @@ const p = () => {
|
|
|
311
311
|
}), he = () => pe(ge), We = ({
|
|
312
312
|
id: s,
|
|
313
313
|
control: n,
|
|
314
|
-
method:
|
|
314
|
+
method: a,
|
|
315
315
|
action: g,
|
|
316
|
-
children:
|
|
316
|
+
children: d,
|
|
317
317
|
onSubmit: h = () => {
|
|
318
318
|
},
|
|
319
319
|
onInput: E = () => {
|
|
320
320
|
},
|
|
321
|
-
onChange:
|
|
321
|
+
onChange: y = () => {
|
|
322
322
|
},
|
|
323
323
|
onBlur: F = () => {
|
|
324
324
|
},
|
|
325
325
|
onReset: k = () => {
|
|
326
326
|
},
|
|
327
327
|
numberFields: c = [],
|
|
328
|
-
className:
|
|
329
|
-
...
|
|
328
|
+
className: b,
|
|
329
|
+
...f
|
|
330
330
|
}) => (ie(() => {
|
|
331
|
-
const
|
|
331
|
+
const u = n.channels.subscribe("onChange", y), i = n.channels.subscribe("onBlur", F);
|
|
332
332
|
return () => {
|
|
333
|
-
|
|
333
|
+
u(), i();
|
|
334
334
|
};
|
|
335
335
|
}, []), /* @__PURE__ */ me.jsx(ge.Provider, { value: n, children: /* @__PURE__ */ me.jsx(
|
|
336
336
|
"form",
|
|
@@ -338,57 +338,57 @@ const p = () => {
|
|
|
338
338
|
id: s,
|
|
339
339
|
ref: n.ref,
|
|
340
340
|
action: g,
|
|
341
|
-
method:
|
|
342
|
-
className:
|
|
341
|
+
method: a,
|
|
342
|
+
className: b,
|
|
343
343
|
onInput: E,
|
|
344
|
-
onSubmit: (
|
|
345
|
-
|
|
344
|
+
onSubmit: (u) => {
|
|
345
|
+
a || u.preventDefault();
|
|
346
346
|
const i = n.loadFormValues();
|
|
347
347
|
h(i);
|
|
348
348
|
},
|
|
349
|
-
onChange: (
|
|
350
|
-
const i =
|
|
351
|
-
n.actions.getControlledFields().has(i) || n.actions.setValue(i,
|
|
349
|
+
onChange: (u) => {
|
|
350
|
+
const i = u.target.name;
|
|
351
|
+
n.actions.getControlledFields().has(i) || n.actions.setValue(i, u.target.value);
|
|
352
352
|
},
|
|
353
|
-
onBlur: (
|
|
354
|
-
const i =
|
|
353
|
+
onBlur: (u) => {
|
|
354
|
+
const i = u.target.name;
|
|
355
355
|
if (n.actions.getControlledFields().has(i)) return;
|
|
356
|
-
const
|
|
357
|
-
n.channels.publish("onBlur", i,
|
|
356
|
+
const m = u.target.value;
|
|
357
|
+
n.channels.publish("onBlur", i, m, n.actions.getValues());
|
|
358
358
|
},
|
|
359
|
-
onReset: (
|
|
360
|
-
n.actions.reset(), k(
|
|
359
|
+
onReset: (u) => {
|
|
360
|
+
n.actions.reset(), k(u);
|
|
361
361
|
},
|
|
362
|
-
...
|
|
363
|
-
children:
|
|
362
|
+
...f,
|
|
363
|
+
children: d
|
|
364
364
|
},
|
|
365
365
|
n.lastReloadedAt
|
|
366
|
-
) })),
|
|
367
|
-
const { getWatchValue: g, registerHookWatcher:
|
|
366
|
+
) })), Te = ({ control: s, name: n, compute: a }) => {
|
|
367
|
+
const { getWatchValue: g, registerHookWatcher: d } = s || he(), h = g({ name: n, compute: a }), [E, y] = ce(h);
|
|
368
368
|
return ie(() => {
|
|
369
|
-
const F =
|
|
369
|
+
const F = d({ name: n, compute: a, value: E, setValue: y });
|
|
370
370
|
return () => F.forEach((k) => k());
|
|
371
371
|
}, []), E;
|
|
372
372
|
}, _e = ({ name: s, defaultValue: n }) => {
|
|
373
|
-
const { actions:
|
|
374
|
-
|
|
375
|
-
}, []),
|
|
376
|
-
(
|
|
377
|
-
F(
|
|
373
|
+
const { actions: a, registerController: g, channels: d } = he(), h = C(), E = a.getDefaultValues()[s] || n, [y, F] = ce(E), k = Te({ name: `fieldStates.${s}.customState` }), c = l((u) => {
|
|
374
|
+
a.setFieldState(s, "customState", u);
|
|
375
|
+
}, []), b = l(
|
|
376
|
+
(u, { shouldDirty: i = !0, shouldOnChange: m = !0 } = {}) => {
|
|
377
|
+
F(u), a.setValue(s, u, { shouldDirty: i, shouldOnChange: m });
|
|
378
378
|
},
|
|
379
|
-
[
|
|
380
|
-
),
|
|
381
|
-
|
|
379
|
+
[a.setValue]
|
|
380
|
+
), f = l(() => {
|
|
381
|
+
d.publish("onBlur", s, y, a.getValues());
|
|
382
382
|
}, []);
|
|
383
|
-
return ie(() => g(s, F), []), { ref: h, name: s, defaultValue: E, value:
|
|
383
|
+
return ie(() => g(s, F), []), { ref: h, name: s, defaultValue: E, value: y, onChange: b, onBlur: f, customState: k, setCustomState: c };
|
|
384
384
|
}, $e = ({
|
|
385
385
|
name: s,
|
|
386
386
|
defaultValue: n,
|
|
387
|
-
render:
|
|
387
|
+
render: a = ({ ref: g, name: d, defaultValue: h, value: E, onChange: y, onBlur: F, customState: k, setCustomState: c }) => null
|
|
388
388
|
}) => {
|
|
389
389
|
const g = _e({ name: s, defaultValue: n });
|
|
390
|
-
return
|
|
391
|
-
}, ke = ["errors", "fieldStates", "formState"],
|
|
390
|
+
return a(g);
|
|
391
|
+
}, ke = ["errors", "fieldStates", "formState"], U = (s) => ke.some((n) => s.startsWith(n)) ? s : "values." + s, we = [
|
|
392
392
|
"badInput",
|
|
393
393
|
"customError",
|
|
394
394
|
"patternMismatch",
|
|
@@ -401,26 +401,26 @@ const p = () => {
|
|
|
401
401
|
"valueMissing"
|
|
402
402
|
], Ee = (s) => {
|
|
403
403
|
typeof s.setCustomValidity == "function" && s.setCustomValidity("");
|
|
404
|
-
let n = s.validity,
|
|
405
|
-
if (
|
|
404
|
+
let n = s.validity, a = we.find((g) => n[g]);
|
|
405
|
+
if (a) return { type: a, message: s.validationMessage };
|
|
406
406
|
};
|
|
407
|
-
class
|
|
407
|
+
class Ae {
|
|
408
408
|
constructor() {
|
|
409
409
|
this.events = /* @__PURE__ */ new Map();
|
|
410
410
|
}
|
|
411
411
|
getEvents() {
|
|
412
412
|
return this.events;
|
|
413
413
|
}
|
|
414
|
-
subscribe(n,
|
|
415
|
-
return this.events.has(n) || this.events.set(n, /* @__PURE__ */ new Set()), this.events.get(n).add(
|
|
414
|
+
subscribe(n, a) {
|
|
415
|
+
return this.events.has(n) || this.events.set(n, /* @__PURE__ */ new Set()), this.events.get(n).add(a), () => {
|
|
416
416
|
var g;
|
|
417
|
-
return (g = this.events.get(n)) == null ? void 0 : g.delete(
|
|
417
|
+
return (g = this.events.get(n)) == null ? void 0 : g.delete(a);
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
|
-
publish(n, ...
|
|
420
|
+
publish(n, ...a) {
|
|
421
421
|
const g = this.events.get(n);
|
|
422
|
-
g && g.forEach((
|
|
423
|
-
n.includes(h) &&
|
|
422
|
+
g && g.forEach((d) => d(...a)), this.events.forEach((d, h) => {
|
|
423
|
+
n.includes(h) && d.forEach((E) => E(...a));
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
426
|
reset() {
|
|
@@ -428,245 +428,241 @@ class we {
|
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
const Oe = () => {
|
|
431
|
-
const s =
|
|
432
|
-
s.current.publish(
|
|
433
|
-
}, []),
|
|
431
|
+
const s = C(new Ae()), n = l((d, ...h) => {
|
|
432
|
+
s.current.publish(d, ...h);
|
|
433
|
+
}, []), a = l((d, h) => s.current.subscribe(d, h), []), g = l(() => {
|
|
434
434
|
s.current.reset();
|
|
435
435
|
}, []);
|
|
436
|
-
return { publish: n, subscribe:
|
|
437
|
-
}, Ce = () => {
|
|
438
|
-
const [s, n] = ce(), l = f(() => n((/* @__PURE__ */ new Date()).toString()), []);
|
|
439
|
-
return [s, l];
|
|
436
|
+
return { publish: n, subscribe: a, reset: g };
|
|
440
437
|
}, je = () => {
|
|
438
|
+
const [s, n] = ce(), a = l(() => n((/* @__PURE__ */ new Date()).toString()), []);
|
|
439
|
+
return [s, a];
|
|
440
|
+
}, Ce = () => {
|
|
441
441
|
const [, s] = ce({});
|
|
442
|
-
return
|
|
443
|
-
}, Pe = ({ channels: s, getValues: n, getErrors:
|
|
444
|
-
const h =
|
|
445
|
-
if (typeof
|
|
442
|
+
return l(() => s({}), []);
|
|
443
|
+
}, Pe = ({ channels: s, getValues: n, getErrors: a, getFieldStates: g, getFormState: d }) => {
|
|
444
|
+
const h = Ce(), E = l(({ name: c, compute: b }) => {
|
|
445
|
+
if (typeof b == "function") return b(n());
|
|
446
446
|
if (Array.isArray(c)) {
|
|
447
|
-
const
|
|
448
|
-
return c.forEach((
|
|
449
|
-
|
|
450
|
-
}),
|
|
447
|
+
const f = {};
|
|
448
|
+
return c.forEach((u) => {
|
|
449
|
+
f[u] = E({ name: u });
|
|
450
|
+
}), f;
|
|
451
451
|
}
|
|
452
|
-
return c.
|
|
453
|
-
(
|
|
452
|
+
return c.split(".").reduce(
|
|
453
|
+
(f, u) => f && f[u] !== void 0 ? f[u] : void 0,
|
|
454
454
|
{
|
|
455
455
|
...n(),
|
|
456
|
-
errors: { ...
|
|
457
|
-
formState: { ...
|
|
456
|
+
errors: { ...a() },
|
|
457
|
+
formState: { ...d() },
|
|
458
458
|
fieldStates: { ...g() }
|
|
459
459
|
}
|
|
460
460
|
);
|
|
461
|
-
}, []),
|
|
461
|
+
}, []), y = l((c) => {
|
|
462
462
|
if (!c)
|
|
463
|
-
return s.subscribe("values", () =>
|
|
464
|
-
h();
|
|
465
|
-
}), n();
|
|
463
|
+
return s.subscribe("values", () => h()), n();
|
|
466
464
|
if (typeof c == "string") {
|
|
467
|
-
const
|
|
468
|
-
return s.subscribe(
|
|
469
|
-
h();
|
|
470
|
-
}), E({ name: c });
|
|
465
|
+
const b = U(c);
|
|
466
|
+
return s.subscribe(b, () => h()), E({ name: c });
|
|
471
467
|
}
|
|
472
468
|
if (Array.isArray(c)) {
|
|
473
|
-
const
|
|
474
|
-
return c.forEach((
|
|
475
|
-
const
|
|
476
|
-
s.subscribe(
|
|
477
|
-
|
|
478
|
-
}), m[a] = E({ name: a });
|
|
479
|
-
}), m;
|
|
469
|
+
const b = {};
|
|
470
|
+
return c.forEach((f) => {
|
|
471
|
+
const u = U(f);
|
|
472
|
+
s.subscribe(u, () => h()), b[f] = E({ name: f });
|
|
473
|
+
}), { ...b };
|
|
480
474
|
}
|
|
481
475
|
throw new Error("Parameters of watch must be string or array of string");
|
|
482
|
-
}, []), F =
|
|
483
|
-
if (typeof
|
|
476
|
+
}, []), F = l(({ name: c, compute: b, value: f, setValue: u }) => {
|
|
477
|
+
if (typeof b == "function")
|
|
484
478
|
return [s.subscribe("values", () => {
|
|
485
|
-
const
|
|
486
|
-
|
|
479
|
+
const m = E({ compute: b });
|
|
480
|
+
u(m);
|
|
487
481
|
})];
|
|
488
|
-
if (c)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
482
|
+
if (!c)
|
|
483
|
+
return [s.subscribe("values", () => {
|
|
484
|
+
u(n());
|
|
485
|
+
})];
|
|
486
|
+
if (typeof c == "string") {
|
|
487
|
+
const i = U(c);
|
|
488
|
+
return [s.subscribe(i, () => {
|
|
489
|
+
const O = E({ name: c });
|
|
490
|
+
u(O);
|
|
491
|
+
})];
|
|
492
|
+
}
|
|
493
|
+
if (Array.isArray(c)) {
|
|
494
|
+
const i = E({ name: c }), m = [];
|
|
495
|
+
return c.forEach((O) => {
|
|
496
|
+
const Y = U(O), W = s.subscribe(Y, () => {
|
|
497
|
+
const q = E({ name: O });
|
|
498
|
+
i[O] = q, u({ ...i });
|
|
499
|
+
});
|
|
500
|
+
m.push(W);
|
|
501
|
+
}), m;
|
|
502
|
+
}
|
|
503
|
+
throw new Error("Parameters of name must be string or array of string or compute must be a function");
|
|
504
|
+
}, []), k = l(
|
|
505
|
+
(c, b) => {
|
|
506
|
+
if (!c)
|
|
507
|
+
return s.subscribe("values", b);
|
|
513
508
|
if (typeof c == "string") {
|
|
514
|
-
const
|
|
515
|
-
return s.subscribe(
|
|
509
|
+
const f = U(c);
|
|
510
|
+
return s.subscribe(f, b);
|
|
516
511
|
}
|
|
517
512
|
if (Array.isArray(c)) {
|
|
518
|
-
const
|
|
513
|
+
const f = {}, u = [];
|
|
519
514
|
return c.forEach((i) => {
|
|
520
|
-
const
|
|
521
|
-
|
|
515
|
+
const m = U(i), O = s.subscribe(m, () => {
|
|
516
|
+
f[i] = E({ name: i }), b({ ...f });
|
|
522
517
|
});
|
|
523
|
-
|
|
524
|
-
}),
|
|
518
|
+
u.push(O);
|
|
519
|
+
}), u;
|
|
525
520
|
}
|
|
521
|
+
throw new Error("Parameters of name must be string or array of string");
|
|
526
522
|
},
|
|
527
523
|
[s]
|
|
528
524
|
);
|
|
529
|
-
return { watch:
|
|
525
|
+
return { watch: y, registerHookWatcher: F, getWatchValue: E, subscribe: k };
|
|
530
526
|
}, xe = [], Ne = {}, Me = ({
|
|
531
527
|
numberFields: s = xe,
|
|
532
528
|
defaultValues: n = Ne,
|
|
533
|
-
shouldUnRegister:
|
|
529
|
+
shouldUnRegister: a = !1,
|
|
534
530
|
shouldConvertNumber: g = !1
|
|
535
531
|
} = {}) => {
|
|
536
|
-
const [
|
|
537
|
-
|
|
532
|
+
const [d, h] = je(), E = C(), y = C(!1), F = C(!1), k = C(s), c = C(/* @__PURE__ */ new Map()), b = C({}), f = C({}), u = C(n), i = C(n), m = Oe(), O = l(() => {
|
|
533
|
+
f.current = Object.keys(i.current).reduce(
|
|
538
534
|
(r, t) => ({ ...r, [t]: { isError: !1, isDirty: !1, isTouched: !1, customState: null } }),
|
|
539
535
|
{}
|
|
540
536
|
);
|
|
541
|
-
}, []), Y =
|
|
542
|
-
i.current = { ...i.current, ...r },
|
|
543
|
-
t(i.current[
|
|
544
|
-
}),
|
|
545
|
-
}, []), W =
|
|
537
|
+
}, []), Y = l((r = {}) => {
|
|
538
|
+
i.current = { ...i.current, ...r }, u.current = { ...i.current }, c.current.forEach((t, _) => {
|
|
539
|
+
t(i.current[_]);
|
|
540
|
+
}), y.current = !1, b.current = {}, k.current = s, c.current = /* @__PURE__ */ new Map(), m.reset(), O(), s.length > 0 && (g = !0), h();
|
|
541
|
+
}, []), W = l(() => {
|
|
546
542
|
const r = Object.fromEntries(new FormData(E.current));
|
|
547
|
-
return c.current.forEach((
|
|
548
|
-
r[
|
|
543
|
+
return c.current.forEach((_, w) => {
|
|
544
|
+
r[w] = u.current[w];
|
|
549
545
|
}), g && k.current.forEach(
|
|
550
|
-
(
|
|
546
|
+
(_) => r.hasOwnProperty(_) && (r[_] = Number(r[_]) || 0)
|
|
551
547
|
), r;
|
|
552
|
-
}, []),
|
|
548
|
+
}, []), q = l(() => !!Object.values($()).find((r) => r.isDirty), []), J = l(() => !!Object.values(N()).find((r) => !!r), []), se = l((r) => Ee(r.target), []), ne = l(() => i.current, []), oe = l(() => k.current, []), z = l(() => c.current, []), P = l((r, t) => t ? Array.isArray(t) ? t.map((_) => r[_]) : r[t] : { ...r }, []), G = l((r) => P(u.current, r), [P]), N = l((r) => P(b.current, r), [P]), $ = l((r) => P(f.current, r), [P]), V = l(
|
|
553
549
|
(r) => P(
|
|
554
550
|
{
|
|
555
|
-
isDirty:
|
|
551
|
+
isDirty: y.current,
|
|
556
552
|
isError: F.current,
|
|
557
|
-
errorFields: Object.keys(
|
|
558
|
-
dirtyFields: Object.keys(
|
|
559
|
-
touchedFields: Object.keys(
|
|
553
|
+
errorFields: Object.keys(b.current).filter((t) => !!b.current[t]),
|
|
554
|
+
dirtyFields: Object.keys(f.current).filter((t) => f.current[t].isDirty),
|
|
555
|
+
touchedFields: Object.keys(f.current).filter((t) => f.current[t].isTouched)
|
|
560
556
|
},
|
|
561
557
|
r
|
|
562
558
|
),
|
|
563
559
|
[P]
|
|
564
560
|
), { watch: D, registerHookWatcher: H, getWatchValue: X, subscribe: Z } = Pe({
|
|
565
|
-
channels:
|
|
561
|
+
channels: m,
|
|
566
562
|
getValues: G,
|
|
567
563
|
getErrors: N,
|
|
568
564
|
getFieldStates: $,
|
|
569
565
|
getFormState: V
|
|
570
|
-
}),
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
}, []), Q =
|
|
566
|
+
}), v = l((r, t, _) => {
|
|
567
|
+
const w = f.current[r];
|
|
568
|
+
w[t] !== _ && (f.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")));
|
|
569
|
+
}, []), Q = l(
|
|
574
570
|
(r) => {
|
|
575
|
-
|
|
571
|
+
v(r, "isError", !1), v(r, "isDirty", !1), v(r, "isTouched", !1), v(r, "customState", null);
|
|
576
572
|
},
|
|
577
|
-
[
|
|
578
|
-
), e =
|
|
573
|
+
[v]
|
|
574
|
+
), e = l(
|
|
579
575
|
(r, t) => {
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
F.current !==
|
|
576
|
+
if (b.current[r] === t) return;
|
|
577
|
+
b.current[r] = t, v(r, "isError", !!t), m.publish(`errors.${r}`, t);
|
|
578
|
+
const w = J();
|
|
579
|
+
F.current !== w && (F.current = w, m.publish("formState.isError", w));
|
|
584
580
|
},
|
|
585
|
-
[
|
|
586
|
-
),
|
|
581
|
+
[v]
|
|
582
|
+
), o = l(
|
|
587
583
|
(r) => {
|
|
588
|
-
if (!
|
|
589
|
-
|
|
584
|
+
if (!b.current[r]) return;
|
|
585
|
+
b.current[r] = null, v(r, "isError", !1), m.publish(`errors.${r}`, null);
|
|
590
586
|
const t = J();
|
|
591
|
-
F.current !== t && (F.current = t,
|
|
587
|
+
F.current !== t && (F.current = t, m.publish("formState.isError", t));
|
|
592
588
|
},
|
|
593
|
-
[
|
|
594
|
-
), R =
|
|
595
|
-
if (Object.keys(
|
|
596
|
-
|
|
589
|
+
[v]
|
|
590
|
+
), R = l(() => {
|
|
591
|
+
if (Object.keys(b.current) === 0) return;
|
|
592
|
+
Object.keys(b.current).forEach((t) => o(t)), b.current = {};
|
|
597
593
|
const r = J();
|
|
598
|
-
F.current !== r && (F.current = r,
|
|
599
|
-
}, []),
|
|
594
|
+
F.current !== r && (F.current = r, m.publish("formState.isError", r));
|
|
595
|
+
}, []), T = l(
|
|
600
596
|
(r) => {
|
|
601
597
|
const t = Ee(r.target);
|
|
602
|
-
t ? e(r.target.name, t) :
|
|
598
|
+
t ? e(r.target.name, t) : o(r.target.name);
|
|
603
599
|
},
|
|
604
|
-
[e,
|
|
605
|
-
),
|
|
606
|
-
(r, t, { shouldDirty:
|
|
607
|
-
if (t ===
|
|
608
|
-
g && k.current.includes(r) && (t = Number(t) || void 0),
|
|
600
|
+
[e, o]
|
|
601
|
+
), j = l(
|
|
602
|
+
(r, t, { shouldDirty: _ = !0, shouldOnChange: w = !0 } = {}) => {
|
|
603
|
+
if (t === u.current[r]) return;
|
|
604
|
+
g && k.current.includes(r) && (t = Number(t) || void 0), v(r, "isTouched", !0);
|
|
609
605
|
const ee = t !== i.current[r];
|
|
610
|
-
|
|
611
|
-
const M =
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
606
|
+
_ && f.current[r].isDirty !== ee && v(r, "isDirty", ee);
|
|
607
|
+
const M = q();
|
|
608
|
+
y.current !== M && (y.current = M, m.publish("formState.isDirty", M)), u.current[r] = t;
|
|
609
|
+
const L = c.current.get(r);
|
|
610
|
+
L && L(t), m.publish(`values.${r}`, t, { shouldDirty: _, shouldOnChange: w }), w && m.publish("onChange", r, t, u.current);
|
|
615
611
|
},
|
|
616
|
-
[
|
|
617
|
-
),
|
|
618
|
-
|
|
619
|
-
}), []),
|
|
620
|
-
(r, { keepError: t, keepDirty:
|
|
621
|
-
const
|
|
622
|
-
if (!
|
|
612
|
+
[v]
|
|
613
|
+
), A = l((r, t) => (c.current.set(r, t), () => {
|
|
614
|
+
a && c.current.delete(r);
|
|
615
|
+
}), []), I = l(
|
|
616
|
+
(r, { keepError: t, keepDirty: _, keepTouched: w, keepCustomState: ee, defaultValue: M }) => {
|
|
617
|
+
const L = c.current.get(r);
|
|
618
|
+
if (!L)
|
|
623
619
|
throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);
|
|
624
|
-
i.current[r] = M,
|
|
620
|
+
i.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);
|
|
625
621
|
},
|
|
626
|
-
[
|
|
627
|
-
),
|
|
628
|
-
|
|
622
|
+
[o, v]
|
|
623
|
+
), B = l((r, t = S.getValues(r)) => {
|
|
624
|
+
m.publish("onBlur", r, t, S.getValues());
|
|
629
625
|
}, []), S = ae(
|
|
630
626
|
() => ({
|
|
631
627
|
subscribe: Z,
|
|
632
628
|
reset: Y,
|
|
633
|
-
resetField:
|
|
634
|
-
setValue:
|
|
629
|
+
resetField: I,
|
|
630
|
+
setValue: j,
|
|
635
631
|
getValues: G,
|
|
636
632
|
getErrors: N,
|
|
637
633
|
getFieldStates: $,
|
|
638
634
|
getFormState: V,
|
|
639
635
|
setError: e,
|
|
640
|
-
clearError:
|
|
636
|
+
clearError: o,
|
|
641
637
|
clearErrors: R,
|
|
642
|
-
checkValidity:
|
|
638
|
+
checkValidity: T,
|
|
643
639
|
getNumberFields: oe,
|
|
644
640
|
getFieldValidity: se,
|
|
645
641
|
getDefaultValues: ne,
|
|
646
|
-
setFieldState:
|
|
647
|
-
triggerFieldBlur:
|
|
642
|
+
setFieldState: v,
|
|
643
|
+
triggerFieldBlur: B,
|
|
648
644
|
resetFieldState: Q,
|
|
649
645
|
getControlledFields: z
|
|
650
646
|
}),
|
|
651
647
|
[
|
|
652
648
|
Z,
|
|
653
649
|
Y,
|
|
654
|
-
|
|
655
|
-
|
|
650
|
+
I,
|
|
651
|
+
j,
|
|
656
652
|
G,
|
|
657
653
|
N,
|
|
658
654
|
$,
|
|
659
655
|
V,
|
|
660
656
|
e,
|
|
661
|
-
|
|
657
|
+
o,
|
|
662
658
|
R,
|
|
663
|
-
|
|
659
|
+
T,
|
|
664
660
|
oe,
|
|
665
661
|
se,
|
|
666
662
|
ne,
|
|
667
|
-
|
|
663
|
+
v,
|
|
668
664
|
Q,
|
|
669
|
-
|
|
665
|
+
B,
|
|
670
666
|
z
|
|
671
667
|
]
|
|
672
668
|
), x = ae(
|
|
@@ -674,34 +670,34 @@ const Oe = () => {
|
|
|
674
670
|
ref: E,
|
|
675
671
|
watch: D,
|
|
676
672
|
actions: S,
|
|
677
|
-
registerController:
|
|
673
|
+
registerController: A,
|
|
678
674
|
registerHookWatcher: H,
|
|
679
|
-
lastReloadedAt:
|
|
675
|
+
lastReloadedAt: d,
|
|
680
676
|
loadFormValues: W,
|
|
681
677
|
getWatchValue: X,
|
|
682
|
-
channels:
|
|
678
|
+
channels: m
|
|
683
679
|
}),
|
|
684
680
|
[
|
|
685
681
|
E,
|
|
686
682
|
D,
|
|
687
683
|
S,
|
|
688
|
-
|
|
684
|
+
A,
|
|
689
685
|
H,
|
|
690
|
-
|
|
686
|
+
d,
|
|
691
687
|
W,
|
|
692
688
|
X,
|
|
693
|
-
|
|
689
|
+
m
|
|
694
690
|
]
|
|
695
|
-
), K = ae(() => ({ control: x, actions: S, watch: D }), [
|
|
691
|
+
), K = ae(() => ({ control: x, actions: S, watch: D }), [d, x, S, D]);
|
|
696
692
|
return le(() => {
|
|
697
693
|
if ([...E.current.querySelectorAll("[name]")].forEach((t) => {
|
|
698
694
|
!t.defaultValue && i.current[t.name] && (t.defaultValue = i.current[t.name]), t.type === "number" && !k.current.includes(t.name) && k.current.push(t.name);
|
|
699
695
|
}), E.current) {
|
|
700
696
|
const t = W();
|
|
701
|
-
|
|
697
|
+
u.current = { ...t }, i.current = { ...t };
|
|
702
698
|
}
|
|
703
|
-
}, [
|
|
704
|
-
|
|
699
|
+
}, [d]), le(() => {
|
|
700
|
+
O();
|
|
705
701
|
}, []), K;
|
|
706
702
|
};
|
|
707
703
|
export {
|
|
@@ -710,5 +706,5 @@ export {
|
|
|
710
706
|
_e as useController,
|
|
711
707
|
Me as useForm,
|
|
712
708
|
he as useFormContext,
|
|
713
|
-
|
|
709
|
+
Te as useWatch
|
|
714
710
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(A,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(A=typeof globalThis<"u"?globalThis:A||self,r(A.Name={},A.React))})(this,function(A,r){"use strict";var se={exports:{}},z={};/**
|
|
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 ue;function he(){if(ue)return
|
|
9
|
+
*/var ue;function he(){if(ue)return z;ue=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 le;function ge(){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===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case
|
|
17
|
+
*/var le;function ge(){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===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 i: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} />`,T,S,N,S),ee[S+T]=!0)}if(S=null,R!==void 0&&(f(R),S=""+R),E(c)&&(f(c.key),S=""+c.key),"key"in c){R={};for(var te in c)te!=="key"&&(R[te]=c[te])}else R=c;return S&&y(R,typeof e=="function"?e.displayName||e.name||"Unknown":e),F(e,S,A,O,b(),R,U,J)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===a&&e._store&&(e._store.validated=1)}var l=r,a=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),_=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),W=Symbol.for("react.consumer"),L=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=l.__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};l={"react-stack-bottom-frame":function(e){return e()}};var K,q={},$=l["react-stack-bottom-frame"].bind(l,g)(),C=D(h(g)),ee={};H.Fragment=d,H.jsx=function(e,c,R,T,O){var A=1e4>x.recentlyCreatedOwnerStacks++;return u(e,c,R,!1,T,O,A?Error("react-stack-top-frame"):$,A?D(h(e)):C)},H.jsxs=function(e,c,R,T,O){var A=1e4>x.recentlyCreatedOwnerStacks++;return u(e,c,R,!0,T,O,A?Error("react-stack-top-frame"):$,A?D(h(e)):C)}}()),H}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:f,action:h,children:b,onSubmit:g=()=>{},onInput:E=()=>{},onChange:y=()=>{},onBlur:v=()=>{},onReset:F=()=>{},numberFields:u=[],className:m,...l})=>(r.useEffect(()=>{const a=o.channels.subscribe("onChange",y),i=o.channels.subscribe("onBlur",v);return()=>{a(),i()}},[]),fe.jsx(de.Provider,{value:o,children:fe.jsx("form",{id:n,ref:o.ref,action:h,method:f,className:m,onInput:E,onSubmit:a=>{f||a.preventDefault();const i=o.loadFormValues();g(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 d=a.target.value;o.channels.publish("onBlur",i,d,o.actions.getValues())},onReset:a=>{o.actions.reset(),F(a)},...l,children:b},o.lastReloadedAt)})),be=({control:n,name:o,compute:f})=>{const{getWatchValue:h,registerHookWatcher:b}=n||ce(),g=h({name:o,compute:f}),[E,y]=r.useState(g);return r.useEffect(()=>{const v=b({name:o,compute:f,value:E,setValue:y});return()=>v.forEach(F=>F())},[]),E},me=({name:n,defaultValue:o})=>{const{actions:f,registerController:h,channels:b}=ce(),g=r.useRef(),E=f.getDefaultValues()[n]||o,[y,v]=r.useState(E),F=be({name:`fieldStates.${n}.customState`}),u=r.useCallback(a=>{f.setFieldState(n,"customState",a)},[]),m=r.useCallback((a,{shouldDirty:i=!0,shouldOnChange:d=!0}={})=>{v(a),f.setValue(n,a,{shouldDirty:i,shouldOnChange:d})},[f.setValue]),l=r.useCallback(()=>{b.publish("onBlur",n,y,f.getValues())},[]);return r.useEffect(()=>h(n,v),[]),{ref:g,name:n,defaultValue:E,value:y,onChange:m,onBlur:l,customState:F,setCustomState:u}},Se=({name:n,defaultValue:o,render:f=({ref:h,name:b,defaultValue:g,value:E,onChange:y,onBlur:v,customState:F,setCustomState:u})=>null})=>{const h=me({name:n,defaultValue:o});return f(h)},Ce=["errors","fieldStates","formState"],I=n=>Ce.some(o=>n.startsWith(o))?n:"values."+n,ye=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],Ee=n=>{typeof n.setCustomValidity=="function"&&n.setCustomValidity("");let o=n.validity,f=ye.find(h=>o[h]);if(f)return{type:f,message:n.validationMessage}};class pe{constructor(){this.events=new Map}getEvents(){return this.events}subscribe(o,f){return this.events.has(o)||this.events.set(o,new Set),this.events.get(o).add(f),()=>{var h;return(h=this.events.get(o))==null?void 0:h.delete(f)}}publish(o,...f){const h=this.events.get(o);h&&h.forEach(b=>b(...f)),this.events.forEach((b,g)=>{o.includes(g)&&b.forEach(E=>E(...f))})}reset(){this.events.clear()}}const ve=()=>{const n=r.useRef(new pe),o=r.useCallback((b,...g)=>{n.current.publish(b,...g)},[]),f=r.useCallback((b,g)=>n.current.subscribe(b,g),[]),h=r.useCallback(()=>{n.current.reset()},[]);return{publish:o,subscribe:f,reset:h}},Te=()=>{const[n,o]=r.useState(),f=r.useCallback(()=>o(new Date().toString()),[]);return[n,f]},Fe=()=>{const[,n]=r.useState({});return r.useCallback(()=>n({}),[])},_e=({channels:n,getValues:o,getErrors:f,getFieldStates:h,getFormState:b})=>{const g=Fe(),E=r.useCallback(({name:u,compute:m})=>{if(typeof m=="function")return m(o());if(Array.isArray(u)){const l={};return u.forEach(a=>{l[a]=E({name:a})}),l}return u.replaceAll(/\[(\d+)\]/g,".$1").split(".").reduce((l,a)=>l&&l[a]!==void 0?l[a]:void 0,{...o(),errors:{...f()},formState:{...b()},fieldStates:{...h()}})},[]),y=r.useCallback(u=>{if(!u)return n.subscribe("values",()=>{g()}),o();if(typeof u=="string"){const m=I(u);return n.subscribe(m,()=>{g()}),E({name:u})}if(Array.isArray(u)){const m={};return u.forEach(l=>{const a=I(l);n.subscribe(a,()=>{g()}),m[l]=E({name:l})}),m}throw new Error("Parameters of watch must be string or array of string")},[]),v=r.useCallback(({name:u,compute:m,value:l,setValue:a})=>{if(typeof m=="function")return[n.subscribe("values",()=>{const d=E({compute:m});d!==l&&a(d)})];if(u)if(typeof u=="string"){const i=I(u);return[n.subscribe(i,()=>{const _=E({name:u});_!==l&&a(_)})]}else if(Array.isArray(u)){const i=E({name:u}),d=[];return u.forEach(_=>{const B=I(_),W=n.subscribe(B,()=>{const L=E({name:_});i[_]!==L&&(i[_]=L,a({...i}))});d.push(W)}),d}else throw new Error("Parameters of name must be string or array of string or compute must be a function");else return[n.subscribe("values",()=>{a(o())})]},[]),F=r.useCallback((u,m)=>{if(typeof u===void 0)return n.subscribe("values",m);if(typeof u=="string"){const l=I(u);return n.subscribe(l,m)}if(Array.isArray(u)){const l={},a=[];return u.forEach(i=>{const d=I(i),_=n.subscribe(d,()=>{l[i]=E({name:i}),m(l)});a.push(_)}),a}},[n]);return{watch:y,registerHookWatcher:v,getWatchValue:E,subscribe:F}},Ae=[],we={},Oe=({numberFields:n=Ae,defaultValues:o=we,shouldUnRegister:f=!1,shouldConvertNumber:h=!1}={})=>{const[b,g]=Te(),E=r.useRef(),y=r.useRef(!1),v=r.useRef(!1),F=r.useRef(n),u=r.useRef(new Map),m=r.useRef({}),l=r.useRef({}),a=r.useRef(o),i=r.useRef(o),d=ve(),_=r.useCallback(()=>{l.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},a.current={...i.current},u.current.forEach((s,p)=>{s(i.current[p])}),y.current=!1,m.current={},F.current=n,u.current=new Map,d.reset(),_(),n.length>0&&(h=!0),g()},[]),W=r.useCallback(()=>{const t=Object.fromEntries(new FormData(E.current));return u.current.forEach(p=>{t[p]=a.current[p]}),h&&F.current.forEach(p=>t.hasOwnProperty(p)&&(t[p]=Number(t[p])||0)),t},[]),L=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(()=>F.current,[]),Z=r.useCallback(()=>u.current,[]),P=r.useCallback((t,s)=>s?Array.isArray(s)?s.map(p=>t[p]):t[s]:{...t},[]),Q=r.useCallback(t=>P(a.current,t),[P]),x=r.useCallback(t=>P(m.current,t),[P]),M=r.useCallback(t=>P(l.current,t),[P]),V=r.useCallback(t=>P({isDirty:y.current,isError:v.current,errorFields:Object.keys(m.current).filter(s=>!!m.current[s]),dirtyFields:Object.keys(l.current).filter(s=>l.current[s].isDirty),touchedFields:Object.keys(l.current).filter(s=>l.current[s].isTouched)},t),[P]),{watch:D,registerHookWatcher:K,getWatchValue:q,subscribe:$}=_e({channels:d,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V}),C=r.useCallback((t,s,p)=>{const j=l.current[t];j[s]!==p&&(l.current[t]={...j,[s]:p},d.publish(`fieldStates.${t}.${s}`,p),s==="isError"&&d.publish("formState.errorFields",V("errorFields")),s==="isDirty"&&d.publish("formState.dirtyFields",V("dirtyFields")),s==="isTouched"&&d.publish("formState.touchedFields",V("touchedFields")))},[]),ee=r.useCallback(t=>{C(t,"isError",!1),C(t,"isDirty",!1),C(t,"isTouched",!1),C(t,"customState",null)},[C]),e=r.useCallback((t,s)=>{if(m.current[t]===s)return;m.current[t]=s,C(t,"isError",!!s),d.publish(`errors.${t}`,s);const j=X();v.current!==j&&(v.current=j,d.publish("formState.isError",j))},[C]),c=r.useCallback(t=>{if(!m.current[t])return;m.current[t]=null,C(t,"isError",!1),d.publish(`errors.${t}`,null);const s=X();v.current!==s&&(v.current=s,d.publish("formState.isError",s))},[C]),R=r.useCallback(()=>{if(Object.keys(m.current)===0)return;m.current={},d.publish("errors",m.current);const t=X();v.current!==t&&(v.current=t,d.publish("formState.isError",t))},[]),T=r.useCallback(t=>{const s=Ee(t.target);s?e(t.target.name,s):c(t.target.name)},[e,c]),O=r.useCallback((t,s,{shouldDirty:p=!0,shouldOnChange:j=!0}={})=>{if(s===a.current[t])return;h&&F.current.includes(t)&&(s=Number(s)||void 0),C(t,"isTouched",!0);const re=s!==i.current[t];p&&l.current[t].isDirty!==re&&C(t,"isDirty",re);const Y=L();y.current!==Y&&(y.current=Y,d.publish("formState.isDirty",Y)),a.current[t]=s;const z=u.current.get(t);z&&z(s),d.publish(`values.${t}`,s,{shouldDirty:p,shouldOnChange:j}),j&&d.publish("onChange",t,s,a.current)},[C]),A=r.useCallback((t,s)=>(u.current.set(t,s),()=>{f&&u.current.delete(t)}),[]),U=r.useCallback((t,{keepError:s,keepDirty:p,keepTouched:j,keepCustomState:re,defaultValue:Y})=>{const z=u.current.get(t);if(!z)throw new Error(`Cannot reset "${t}" because it's uncontrolled field`);i.current[t]=Y,a.current[t]=Y,z&&z(Y),s||c(t),p||C(t,"isDirty",!1),j||C(t,"isTouched",!1),re||C(t,"customState",null)},[c,C]),J=r.useCallback((t,s=S.getValues(t))=>{d.publish("onBlur",t,s,S.getValues())},[]),S=r.useMemo(()=>({subscribe:$,reset:B,resetField:U,setValue:O,getValues:Q,getErrors:x,getFieldStates:M,getFormState:V,setError:e,clearError:c,clearErrors:R,checkValidity:T,getNumberFields:ae,getFieldValidity:ne,getDefaultValues:oe,setFieldState:C,triggerFieldBlur:J,resetFieldState:ee,getControlledFields:Z}),[$,B,U,O,Q,x,M,V,e,c,R,T,ae,ne,oe,C,ee,J,Z]),N=r.useMemo(()=>({ref:E,watch:D,actions:S,registerController:A,registerHookWatcher:K,lastReloadedAt:b,loadFormValues:W,getWatchValue:q,channels:d}),[E,D,S,A,K,b,W,q,d]),te=r.useMemo(()=>({control:N,actions:S,watch:D}),[b,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"&&!F.current.includes(s.name)&&F.current.push(s.name)}),E.current){const s=W();a.current={...s},i.current={...s}}},[b]),r.useLayoutEffect(()=>{_()},[]),te};w.Controller=Se,w.Form=ke,w.useController=me,w.useForm=Oe,w.useFormContext=ce,w.useWatch=be,Object.defineProperty(w,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 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"})});
|