react-simple-formkit 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -3
- package/dist/react-simple-formkit.js +4 -4
- package/dist/react-simple-formkit.mjs +531 -545
- package/dist/react-simple-formkit.umd.js +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(M,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],s):(M=typeof globalThis<"u"?globalThis:M||self,s(M.Name={},M.React))})(this,function(M,s){"use strict";var q={exports:{}},H={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var fe;function ke(){if(fe)return H;fe=1;var c=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function o(i,u,f){var a=null;if(f!==void 0&&(a=""+f),u.key!==void 0&&(a=""+u.key),"key"in u){f={};for(var b in u)b!=="key"&&(f[b]=u[b])}else f=u;return u=f.ref,{$$typeof:c,type:i,key:a,ref:u!==void 0?u:null,props:f}}return H.Fragment=r,H.jsx=o,H.jsxs=o,H}var X={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var de;function ye(){return de||(de=1,process.env.NODE_ENV!=="production"&&function(){function c(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===le?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case v:return"Fragment";case w:return"Profiler";case F:return"StrictMode";case ue:return"Suspense";case $:return"SuspenseList";case ee:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case S:return"Portal";case I:return(t.displayName||"Context")+".Provider";case N:return(t._context.displayName||"Context")+".Consumer";case z:var g=t.render;return t=t.displayName,t||(t=g.displayName||g.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case J:return g=t.displayName||null,g!==null?g:c(t.type)||"Memo";case y:g=t._payload,t=t._init;try{return c(t(g))}catch{}}return null}function r(t){return""+t}function o(t){try{r(t);var g=!1}catch{g=!0}if(g){g=console;var p=g.error,_=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return p.call(g,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",_),r(t)}}function i(t){if(t===v)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===y)return"<...>";try{var g=c(t);return g?"<"+g+">":"<...>"}catch{return"<...>"}}function u(){var t=Z.A;return t===null?null:t.getOwner()}function f(){return Error("react-stack-top-frame")}function a(t){if(te.call(t,"key")){var g=Object.getOwnPropertyDescriptor(t,"key").get;if(g&&g.isReactWarning)return!1}return t.key!==void 0}function b(t,g){function p(){se||(se=!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)",g))}p.isReactWarning=!0,Object.defineProperty(t,"key",{get:p,configurable:!0})}function d(){var t=c(this.type);return x[t]||(x[t]=!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.")),t=this.props.ref,t!==void 0?t:null}function m(t,g,p,_,Y,D,G,K){return p=D.ref,t={$$typeof:O,type:t,key:g,props:D,_owner:Y},(p!==void 0?p:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:d}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function l(t,g,p,_,Y,D,G,K){var A=g.children;if(A!==void 0)if(_)if(re(A)){for(_=0;_<A.length;_++)R(A[_]);Object.freeze&&Object.freeze(A)}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 R(A);if(te.call(g,"key")){A=c(t);var e=Object.keys(g).filter(function(E){return E!=="key"});_=0<e.length?"{key: someKey, "+e.join(": ..., ")+": ...}":"{key: someKey}",Q[A+_]||(e=0<e.length?"{"+e.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} />`,_,n,d,n),te[n+_]=!0)}if(n=null,y!==void 0&&(c(y),n=""+y),a(m)&&(c(m.key),n=""+m.key),"key"in m){y={};for(var g in m)g!=="key"&&(y[g]=m[g])}else y=m;return n&&h(y,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,n,D,x,u(),y,Z,r)}function R(e){typeof e=="object"&&e!==null&&e.$$typeof===A&&e._store&&(e._store.validated=1)}var k=s,A=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),V=Symbol.for("react.consumer"),I=Symbol.for("react.context"),B=Symbol.for("react.forward_ref"),q=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),v=Symbol.for("react.memo"),H=Symbol.for("react.lazy"),oe=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),X=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=Object.prototype.hasOwnProperty,ae=Array.isArray,U=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var Y,$={},ee=k["react-stack-bottom-frame"].bind(k,b)(),re=U(l(b)),te={};z.Fragment=S,z.jsx=function(e,m,y,_,x){var D=1e4>X.recentlyCreatedOwnerStacks++;return f(e,m,y,!1,_,x,D?Error("react-stack-top-frame"):ee,D?U(l(e)):re)},z.jsxs=function(e,m,y,_,x){var D=1e4>X.recentlyCreatedOwnerStacks++;return f(e,m,y,!0,_,x,D?Error("react-stack-top-frame"):ee,D?U(l(e)):re)}}()),z}var de;function Fe(){return de||(de=1,process.env.NODE_ENV==="production"?Q.exports=ke():Q.exports=ve()),Q.exports}var be=Fe();const F=()=>{},Ee=s.createContext({ref:null,watch:F,actions:{reset:F,resetField:F,setValue:F,getValues:F,getErrors:F,getFieldStates:F,getFormStates:F,setError:F,clearError:F,clearErrors:F,checkValidity:F,getNumberFields:F,getFieldValidity:F,getDefaultValues:F,setFieldState:F,resetFieldState:F,getControlledFields:F},registerController:F,registerHookWatcher:F,lastReloadedAt:F,loadFormValues:F,getWatchValue:F,channels:{}}),ne=()=>s.useContext(Ee),pe=({id:o,control:t,method:c,action:l,children:u,onChange:b,onBlur:a,onSubmit:h=()=>{},onInput:i=()=>{},onReset:E=()=>{},numberFields:f=[],className:R,...k})=>{const A=s.useCallback(C=>{t.ref&&(t.ref.current=C,t.ref.current&&t.initForm())},[t]);return s.useEffect(()=>{let C=()=>{},S=()=>{};return b&&(C=t.channels.subscribe("onChange",b)),a&&(S=t.channels.subscribe("onBlur",a)),()=>{C(),S()}},[t.lastReloadedAt]),be.jsx(Ee.Provider,{value:t,children:be.jsx("form",{id:o,ref:A,action:l,method:c,className:R,onInput:i,onSubmit:C=>{c||C.preventDefault();const S=t.loadFormValues();h(S)},onChange:C=>{const S=C.target.name;!S||t.actions.getControlledFields().has(S)||t.actions.setValue(S,C.target.value)},onBlur:C=>{const S=C.target.name;if(!S||t.actions.getControlledFields().has(S))return;const T=C.target.value;t.channels.publish("onBlur",S,T,t.actions.getValues())},onReset:C=>{t.actions.reset(),E(C)},...k,children:u},t.lastReloadedAt)})},se={isDirty:!1,isTouched:!1,error:null},ge={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},Te={},w=(o={},t="")=>t.split(".").reduce((c,l)=>c&&c[l]!==void 0?c[l]:void 0,o),M=(o={},t="",c)=>{const l={...o};let u=l;const b=t.split(".");return b.forEach((a,h)=>{h<b.length-1?(u[a]=u[a]?{...u[a]}:{},u=u[a]):u[a]=c}),l},G=(o,t)=>{const c=w(o,t);return typeof c=="object"&&!Array.isArray(c)},_e=["errors","fieldStates","formState"],W=o=>_e.some(t=>o.startsWith(t))?o:"values."+o,we=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],he=o=>{typeof o.setCustomValidity=="function"&&o.setCustomValidity("");let t=o.validity,c=we.find(l=>t[l]);if(c)return{type:c,message:o.validationMessage}},Ae=({control:o,name:t,compute:c})=>{const{getWatchValue:l,registerHookWatcher:u}=o||ne(),b=l({name:t,compute:c}),[a,h]=s.useState(b);return s.useEffect(()=>u({name:t,compute:c,value:a,setValue:h}),[]),a},me=({control:o,name:t,defaultValue:c})=>{const{actions:l,registerController:u,channels:b,getWatchValue:a}=o||ne(),h=s.useRef(),i=s.useRef(),E=w(l.getDefaultValues(),t)||c||"",[f,R]=s.useState(E),[k,A]=s.useState({}),C=s.useCallback((T,{shouldDirty:p=!0,shouldOnChange:V=!0}={})=>{var B;let I=T;((B=T==null?void 0:T.target)==null?void 0:B.value)!==void 0&&(I=T.target.value),R(I),l.setValue(t,I,{shouldDirty:p,shouldOnChange:V})},[l.setValue]),S=s.useCallback(T=>{const p=l.getValues(),V=T??w(p,t);b.publish("onBlur",t,V,p)},[]);return s.useEffect(()=>{const T=u(t,R);return()=>{T(),i.current&&i.current()}},[]),new Proxy({ref:h,name:t,defaultValue:E,value:f,onChange:C,onBlur:S,fieldState:k},{get(T,p,V){return typeof p=="string"&&p==="fieldState"&&(i.current&&i.current(),i.current=l.subscribe(`fieldStates.${t}`,()=>{A(a({name:`fieldStates.${t}`}))})),Reflect.get(T,p,V)}})},Oe=({name:o,control:t,defaultValue:c,render:l=({ref:u,name:b,defaultValue:a,value:h,onChange:i,onBlur:E,fieldState:f})=>null})=>{const u=me({name:o,defaultValue:c,control:t});return l(u)},je=()=>{const[o,t]=s.useState(),c=s.useCallback(()=>t(new Date().toString()),[]);return[o,c]},Pe=()=>{const[,o]=s.useState({});return s.useCallback(()=>o({}),[])},Ne=({channels:o,getWatchValue:t})=>{const c=Pe(),l=s.useCallback(a=>{if(!a)return o.subscribeWatch("values",()=>c()),t();if(typeof a=="string"){const h=W(a);o.subscribeWatch(h,(i,E)=>{i!==E&&c()})}return Array.isArray(a)&&a.forEach(h=>{const i=W(h);o.subscribeWatch(i,(E,f)=>{E!==f&&c()})}),t({name:a})},[]),u=s.useCallback(({name:a,compute:h,setValue:i})=>{if(typeof h=="function")return o.subscribe("values",()=>{const f=t({compute:h});i(f)});if(!a)return o.subscribe("values",()=>{i(t())});if(typeof a=="string"){const E=W(a);return o.subscribe(E,()=>{const R=t({name:a});i(R)})}if(Array.isArray(a)){const E=[];return a.forEach(f=>{const R=W(f),k=o.subscribe(R,()=>{const A=t({name:a});i(A)});E.push(k)}),()=>E.forEach(f=>f())}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),b=s.useCallback((a,h)=>{if(!a)return o.subscribe("values",()=>h(t()));if(["onChange","onBlur"].includes(a))return o.subscribe(a,h);if(typeof a=="string"){const i=W(a);return o.subscribe(i,()=>h(t({name:a})))}if(Array.isArray(a)){const i=[];return a.forEach(E=>{const f=W(E),R=o.subscribe(f,()=>{h(t({name:a}))});i.push(R)}),()=>i.forEach(E=>E())}throw new Error("Parameters of name must be string or array of string")},[]);return{watch:l,registerHookWatcher:u,getWatchValue:t,subscribe:b}},De=({getWatchValue:o})=>{const t=s.useRef(new Map),c=s.useRef(new Map),l=s.useCallback(()=>c.current,[]),u=s.useCallback(()=>t.current,[]),b=s.useCallback(()=>{t.current.clear(),c.current.clear()},[]),a=s.useCallback((f,...R)=>{const k=t.current.get(f),A=c.current.get(f);k&&k.forEach(C=>C(...R)),A&&A.forEach(C=>C(...R)),t.current.forEach((C,S)=>{if(S!==f&&f.startsWith(S)){const T=o({name:S.replace("values.","").replace("values","")});C.forEach(p=>p(M(T,f.replace(`${S}.`,""),R[0])))}}),c.current.forEach((C,S)=>{if(S!==f&&f.startsWith(S)){const T=o({name:S.replace("values.","").replace("values","")});C.forEach(p=>p(M(T,f.replace(`${S}.`,""),R[0])))}})},[]),h=s.useCallback(f=>{t.current.forEach((R,k)=>{k.startsWith(f)&&R.forEach(A=>A(o({name:k.replace("values.","").replace("values","")})))}),c.current.forEach((R,k)=>{k.startsWith(f)&&R.forEach(A=>A(o({name:k.replace("values.","").replace("values","")})))})},[]),i=s.useCallback((f,R)=>(t.current.has(f)||t.current.set(f,new Set),t.current.get(f).add(R),()=>{var k;return(k=t.current.get(f))==null?void 0:k.delete(R)}),[]),E=s.useCallback((f,R)=>{c.current.has(f)||(c.current.set(f,new Set),c.current.get(f).add(R))},[]);return{reset:b,publish:a,subscribe:i,subscribeWatch:E,getEvents:u,getWatchEvents:l,trigger:h}},Re=(o,t={},c="")=>!!Object.keys(t).find(l=>{const u=t[l];return G(o,c+l)?Re(o,u,c+l+"."):!!u.isDirty}),K=(o,t={},c="")=>!!Object.keys(t).find(l=>{const u=t[l];return G(o,c+l)?K(o,u,c+l+"."):!!u}),Se=(o,t={},c="")=>Object.keys(t).reduce((l,u)=>{const b=t[u];return G(o,c+u)?[...l,...Se(o,b,c+u+".")]:b.isDirty?[...l,c+u]:l},[]),Ce=(o,t={},c="")=>Object.keys(t).reduce((l,u)=>{const b=t[u];return G(o,c+u)?[...l,...Ce(o,b,c+u+".")]:b.isTouched?[...l,c+u]:l},[]),ye=(o,t={},c="")=>Object.keys(t).reduce((l,u)=>{const b=t[u];return G(o,c+u)?[...l,...ye(o,b,c+u+".")]:b?[...l,c+u]:l},[]),Ve=({defaultValues:o=Te,shouldUnRegister:t=!1}={})=>{const[c,l]=je(),u=s.useRef(),b=s.useRef(new Map),a=s.useRef({}),h=s.useRef({}),i=s.useRef({...ge}),E=s.useRef({...o}),f=s.useRef({...o}),R=s.useCallback((r,n=f.current)=>Object.keys(n).reduce((d,g)=>{if(typeof n[g]=="object")return{...d,[g]:R(r,n[g])};const O={...r?{}:h.current[g]||{},...se};return{...d,[g]:O}},{}),[]),k=s.useCallback((r={},{clearCustomFormStates:n=!1,clearCustomFieldStates:d=!1}={})=>{f.current={...f.current,...r},E.current={...f.current},b.current.forEach((g,O)=>{g(w(f.current,O)??"")}),a.current={},i.current={...n?{}:i.current,...ge},b.current=new Map,v.reset(),h.current=R(d),l()},[]),A=s.useCallback(()=>{let r=Object.fromEntries(new FormData(u.current));b.current.forEach((d,g)=>{r=M(r,g,w(E.current,g))});let n={...E.current,...r};return Object.keys(n).forEach(d=>{if(d.includes(".")){const g=w(n,d);n=M(n,d,g||""),delete n[d]}}),n},[]),C=s.useCallback(r=>he(r.target),[]),S=s.useCallback(()=>f.current,[]),T=s.useCallback(()=>b.current,[]),p=s.useCallback((r,n)=>n?Array.isArray(n)?n.reduce((d,g)=>({...d,[g]:w(r,g)}),{}):w(r,n):{...r},[]),V=s.useCallback(r=>p(E.current,r),[p]),I=s.useCallback(r=>p(a.current,r),[p]),B=s.useCallback(r=>p(h.current,r),[p]),q=s.useCallback(r=>p({...i.current,lastReset:c},r),[c]),L=s.useCallback(({name:r,compute:n}={})=>{if(!r&&!n||r==="values")return V();if(typeof n=="function")return n(V());if(Array.isArray(r)){const d={};return r.forEach(g=>{d[g]=L({name:g})}),d}return w({...E.current,errors:a.current,fieldStates:h.current,formState:q()},r)},[]),v=De({getWatchValue:L}),{watch:H,registerHookWatcher:oe,subscribe:ce}=Ne({getWatchValue:L,channels:v}),X=s.useCallback((r,n)=>{const d=i.current,g=w(d,r);g!==n&&(i.current=M(i.current,r,n),v.publish(`formState.${r}`,n,g))},[]),P=s.useCallback((r,n,d)=>{try{const g=w(h.current,r)||{...se},O=w(g,n);if(O!==d){if(h.current=M(h.current,`${r}.${n}`,d),v.publish(`fieldStates.${r}.${n}`,d,O),n==="error"){const j=ye(E.current,a.current);i.current.errorFields=j,v.publish("formState.errorFields",j)}if(n==="isDirty"){const j=Se(E.current,h.current);i.current.dirtyFields=j,v.publish("formState.dirtyFields",j)}if(n==="isTouched"){const j=Ce(E.current,h.current);i.current.touchedFields=j,v.publish("formState.touchedFields",j)}}}catch(g){console.log(g)}},[]),ae=s.useCallback(r=>{P(r,"isDirty",!1),P(r,"isTouched",!1),P(r,"error",null)},[]),U=s.useCallback((r,n)=>{try{const d=w(a.current,r);if(d===n)return;a.current=M(a.current,r,n),v.publish(`errors.${r}`,n,d),P(r,"error",n);const g=K(E.current,a.current);if(i.current.isError!==g){const O=i.current.isError;i.current.isError=g,v.publish("formState.isError",g,O)}}catch(d){console.error(d)}},[]),Y=s.useCallback(r=>{try{const n=w(a.current,r);if(!n)return;a.current=M(a.current,r,null),v.publish(`errors.${r}`,null,n),P(r,"error",null);const d=K(E.current,a.current);if(i.current.isError!==d){const g=i.current.isError;i.current.isError=d,v.publish("formState.isError",d,g)}}catch(n){console.error(n)}},[]),$=s.useCallback(()=>{if(!i.current.isError)return;Object.keys(a.current).forEach(n=>Y(n)),a.current={};const r=K(E.current,a.current);if(i.current.isError!==r){const n=i.current.isError;i.current.isError=r,v.publish("formState.isError",r,n)}},[]),ee=s.useCallback(r=>{const n=he(r.target);n?U(r.target.name,n):Y(r.target.name)},[]),re=s.useCallback((r,n,{shouldDirty:d=!0,shouldOnChange:g=!0}={})=>{const O=w(E.current,r);if(n===O)return;if(P(r,"isTouched",!0),d){const le=n!==(w(f.current,r)||"");P(r,"isDirty",le)}E.current=M(E.current,r,n),v.publish(`values.${r}`,n,O);const j=b.current.get(r);j&&j(n),g&&v.publish("onChange",r,n,E.current);const ue=Re(E.current,h.current);if(i.current.isDirty!==ue){const le=i.current.isDirty;i.current.isDirty=ue,v.publish("formState.isDirty",ue,le)}},[]),te=s.useCallback((r,n)=>(b.current.set(r,n),h.current=M(h.current,r,{...se}),()=>{t&&b.current.delete(r)}),[]),e=s.useCallback((r,{keepError:n,keepDirty:d,keepTouched:g,defaultValue:O})=>{const j=b.current.get(r);if(!j)throw new Error(`Cannot reset "${r}" because it's uncontrolled field`);f.current[r]=O,E.current[r]=O,j&&j(O),n||Y(r),d||P(r,"isDirty",!1),g||P(r,"isTouched",!1)},[]),m=s.useCallback(r=>{if(!r)return v.trigger("values");if(!Array.isArray(r)){const n=W(r);v.trigger(n);return}r.forEach(n=>{const d=W(n);v.trigger(d)})},[]),y=s.useCallback((r,n=_.getValues(r))=>{v.publish("onBlur",r,n,_.getValues())},[]),_=s.useMemo(()=>({subscribe:ce,reset:k,trigger:m,reload:l,resetField:e,setValue:re,getValues:V,getErrors:I,getFieldStates:B,getFormState:q,setError:U,clearError:Y,clearErrors:$,checkValidity:ee,getFieldValidity:C,getDefaultValues:S,setFieldState:P,triggerFieldBlur:y,resetFieldState:ae,getControlledFields:T,setFormState:X,getEvents:v.getEvents,getWatchEvents:v.getWatchEvents}),[c]),x=s.useCallback(()=>{[...u.current.querySelectorAll("[name]")].forEach(d=>{const g=d.name;!d.defaultValue&&!b.current.has(g)&&w(f.current,g)&&(d.defaultValue=w(f.current,g))});const n=A();E.current={...n},f.current={...n}},[]),D=s.useMemo(()=>({ref:u,watch:H,actions:_,initForm:x,registerController:te,registerHookWatcher:oe,lastReloadedAt:c,loadFormValues:A,getWatchValue:L,channels:v}),[c]),Z=s.useMemo(()=>({control:D,actions:_,watch:H}),[c]);return s.useLayoutEffect(()=>{u.current&&x()},[c]),s.useLayoutEffect(()=>{h.current=R(!1)},[]),Z};N.Controller=Oe,N.Form=pe,N.useController=me,N.useForm=Ve,N.useFormContext=ne,N.useWatch=Ae,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,_,A,e,A),Q[A+_]=!0)}if(A=null,p!==void 0&&(o(p),A=""+p),a(g)&&(o(g.key),A=""+g.key),"key"in g){p={};for(var n in g)n!=="key"&&(p[n]=g[n])}else p=g;return A&&b(p,typeof t=="function"?t.displayName||t.name||"Unknown":t),m(t,A,D,Y,u(),p,G,K)}function R(t){typeof t=="object"&&t!==null&&t.$$typeof===O&&t._store&&(t._store.validated=1)}var C=s,O=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),F=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),I=Symbol.for("react.context"),z=Symbol.for("react.forward_ref"),ue=Symbol.for("react.suspense"),$=Symbol.for("react.suspense_list"),J=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),ee=Symbol.for("react.activity"),le=Symbol.for("react.client.reference"),Z=C.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,te=Object.prototype.hasOwnProperty,re=Array.isArray,B=console.createTask?console.createTask:function(){return null};C={"react-stack-bottom-frame":function(t){return t()}};var se,x={},ne=C["react-stack-bottom-frame"].bind(C,f)(),oe=B(i(f)),Q={};X.Fragment=v,X.jsx=function(t,g,p,_,Y){var D=1e4>Z.recentlyCreatedOwnerStacks++;return l(t,g,p,!1,_,Y,D?Error("react-stack-top-frame"):ne,D?B(i(t)):oe)},X.jsxs=function(t,g,p,_,Y){var D=1e4>Z.recentlyCreatedOwnerStacks++;return l(t,g,p,!0,_,Y,D?Error("react-stack-top-frame"):ne,D?B(i(t)):oe)}}()),X}var be;function Fe(){return be||(be=1,process.env.NODE_ENV==="production"?q.exports=ke():q.exports=ye()),q.exports}var Ee=Fe();const k=()=>{},ge=s.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=()=>s.useContext(ge),Te=({id:c,control:r,method:o,action:i,children:u,onChange:f,onBlur:a,onSubmit:b=()=>{},onInput:d=()=>{},onReset:m=()=>{},numberFields:l=[],className:R,...C})=>{const O=s.useCallback(S=>{r.ref&&(r.ref.current=S,r.ref.current&&r.initForm())},[r]);return s.useEffect(()=>{let S=()=>{},v=()=>{};return f&&(S=r.channels.subscribe("onChange",f)),a&&(v=r.channels.subscribe("onBlur",a)),()=>{S(),v()}},[r.lastReloadedAt]),Ee.jsx(ge.Provider,{value:r,children:Ee.jsx("form",{id:c,ref:O,action:i,method:o,className:R,onInput:d,onSubmit:S=>{o||S.preventDefault();const v=r.loadFormValues();b(v)},onChange:S=>{const v=S.target.name;!v||r.actions.getControlledFields().has(v)||r.actions.setValue(v,S.target.value)},onBlur:S=>{const v=S.target.name;if(!v||r.actions.getControlledFields().has(v))return;const F=S.target.value;r.channels.publish("onBlur",v,F,r.actions.getValues())},onReset:S=>{r.actions.reset(),m(S)},...C,children:u},r.lastReloadedAt)})},ae={isDirty:!1,isTouched:!1,error:null},he={lastReset:null,isDirty:!1,isError:!1,errorFields:[],dirtyFields:[],touchedFields:[]},_e={},Ae=["badInput","customError","patternMismatch","rangeOverflow","rangeUnderflow","stepMismatch","tooLong","tooShort","typeMismatch","valueMissing"],j=(c={},r="")=>r.split(".").reduce((o,i)=>o&&o[i]!==void 0?o[i]:void 0,c),W=(c={},r="",o)=>{const i={...c};let u=i;const f=r.split(".");return f.forEach((a,b)=>{b<f.length-1?(u[a]||(u[a]={}),Array.isArray(u[a])?u[a]=[...u[a]]:u[a]={...u[a]},u=u[a]):u[a]=o}),i},me=c=>{let r={...c};return Object.keys(r).forEach(o=>{if(o.includes(".")){const i=j(r,o);r=W(r,o,i||""),delete r[o]}}),r},Oe=["errors","fieldStates","formState"],L=c=>Oe.some(r=>c.startsWith(r))?c:"values."+c,Re=c=>{typeof c.setCustomValidity=="function"&&c.setCustomValidity("");let r=c.validity,o=Ae.find(i=>r[i]);if(o)return{type:o,message:c.validationMessage}},ve=(c=new Set,r={},o="")=>Object.keys(r).reduce((i,u)=>{const f=r[u];return c.has(o+u)?[...i,...ve(c,f,o+u+".")]:f.isDirty?[...i,o+u]:i},[]),Se=(c=new Set,r={},o="")=>Object.keys(r).reduce((i,u)=>{const f=r[u];return c.has(o+u)?[...i,...Se(c,f,o+u+".")]:f.isTouched?[...i,o+u]:i},[]),Ce=(c=new Set,r={},o="")=>Object.keys(r).reduce((i,u)=>{const f=r[u];return c.has(o+u)?[...i,...Ce(c,f,o+u+".")]:f?[...i,o+u]:i},[]),je=({control:c,name:r,compute:o})=>{const{getWatchValue:i,registerHookWatcher:u}=c||ce(),f=i({name:r,compute:o}),[a,b]=s.useState(f);return s.useEffect(()=>u({name:r,compute:o,value:a,setValue:b}),[]),a},pe=({control:c,name:r,defaultValue:o})=>{const{actions:i,registerController:u,channels:f,getWatchValue:a}=c||ce(),b=s.useRef(),d=s.useRef(),m=j(i.getDefaultValues(),r)||o||"",[l,R]=s.useState(m),[C,O]=s.useState({}),S=s.useCallback((F,{shouldDirty:w=!0,shouldOnChange:N=!0}={})=>{var z;let I=F;((z=F==null?void 0:F.target)==null?void 0:z.value)!==void 0&&(I=F.target.value),R(I),i.setValue(r,I,{shouldDirty:w,shouldOnChange:N})},[i.setValue]),v=s.useCallback(F=>{const w=i.getValues(),N=F??j(w,r);f.publish("onBlur",r,N,w)},[]);return s.useEffect(()=>{const F=u(r,R);return()=>{F(),d.current&&d.current()}},[]),new Proxy({ref:b,name:r,defaultValue:m,value:l,onChange:S,onBlur:v,fieldState:C},{get(F,w,N){return typeof w=="string"&&w==="fieldState"&&(d.current&&d.current(),d.current=i.subscribe(`fieldStates.${r}`,()=>{O(a({name:`fieldStates.${r}`}))})),Reflect.get(F,w,N)}})},we=({name:c,control:r,defaultValue:o,render:i=({ref:u,name:f,defaultValue:a,value:b,onChange:d,onBlur:m,fieldState:l})=>null})=>{const u=pe({name:c,defaultValue:o,control:r});return i(u)},Pe=()=>{const[c,r]=s.useState(),o=s.useCallback(()=>r(new Date().toString()),[]);return[c,o]},Ne=()=>{const[,c]=s.useState({});return s.useCallback(()=>c({}),[])},De=({channels:c,getWatchValue:r})=>{const o=Ne(),i=s.useCallback(a=>{if(!a)return c.subscribeWatch("values",()=>o()),r();if(typeof a=="string"){const b=L(a);c.subscribeWatch(b,(d,m)=>{d!==m&&o()})}return Array.isArray(a)&&a.forEach(b=>{const d=L(b);c.subscribeWatch(d,(m,l)=>{m!==l&&o()})}),r({name:a})},[]),u=s.useCallback(({name:a,compute:b,setValue:d})=>{if(typeof b=="function")return c.subscribe("values",()=>{const l=r({compute:b});d(l)});if(!a)return c.subscribe("values",()=>{d(r())});if(typeof a=="string"){const m=L(a);return c.subscribe(m,()=>{const R=r({name:a});d(R)})}if(Array.isArray(a)){const m=[];return a.forEach(l=>{const R=L(l),C=c.subscribe(R,()=>{const O=r({name:a});d(O)});m.push(C)}),()=>m.forEach(l=>l())}throw new Error("Parameters of name must be string or array of string or compute must be a function")},[]),f=s.useCallback((a,b)=>{if(!a)return c.subscribe("values",()=>b(r()));if(["onChange","onBlur"].includes(a))return c.subscribe(a,b);if(typeof a=="string"){const d=L(a);return c.subscribe(d,()=>b(r({name:a})))}if(Array.isArray(a)){const d=[];return a.forEach(m=>{const l=L(m),R=c.subscribe(l,()=>{b(r({name:a}))});d.push(R)}),()=>d.forEach(m=>m())}throw new Error("Parameters of name must be string or array of string")},[]);return{watch:i,registerHookWatcher:u,getWatchValue:r,subscribe:f}},xe=({getWatchValue:c})=>{const r=s.useRef(new Map),o=s.useRef(new Map),i=s.useCallback(()=>o.current,[]),u=s.useCallback(()=>r.current,[]),f=s.useCallback(()=>{r.current.clear(),o.current.clear()},[]),a=s.useCallback((l,...R)=>{const C=r.current.get(l),O=o.current.get(l);C&&C.forEach(S=>S(...R)),O&&O.forEach(S=>S(...R)),r.current.forEach((S,v)=>{if(v!==l&&l.startsWith(v)){const F=c({name:v.replace("values.","").replace("values","")});S.forEach(w=>w(W(F,l.replace(`${v}.`,""),R[0])))}}),o.current.forEach((S,v)=>{if(v!==l&&l.startsWith(v)){const F=c({name:v.replace("values.","").replace("values","")});S.forEach(w=>w(W(F,l.replace(`${v}.`,""),R[0])))}})},[]),b=s.useCallback(l=>{r.current.forEach((R,C)=>{C.startsWith(l)&&R.forEach(O=>O(c({name:C.replace("values.","").replace("values","")})))}),o.current.forEach((R,C)=>{C.startsWith(l)&&R.forEach(O=>O(c({name:C.replace("values.","").replace("values","")})))})},[]),d=s.useCallback((l,R)=>(r.current.has(l)||r.current.set(l,new Set),r.current.get(l).add(R),()=>{var C;return(C=r.current.get(l))==null?void 0:C.delete(R)}),[]),m=s.useCallback((l,R)=>{o.current.has(l)||(o.current.set(l,new Set),o.current.get(l).add(R))},[]);return{reset:f,publish:a,subscribe:d,subscribeWatch:m,getEvents:u,getWatchEvents:i,trigger:b}},Me=({defaultValues:c=_e,shouldUnRegister:r=!1}={})=>{const[o,i]=Pe(),u=s.useRef(),f=s.useRef(new Map),a=s.useRef({}),b=s.useRef({}),d=s.useRef({...he}),m=s.useRef({...c}),l=s.useRef({...c}),R=s.useRef(new Set),C=s.useCallback((e,n=l.current)=>Object.keys(n).reduce((E,h)=>{if(typeof n[h]=="object")return{...E,[h]:C(e,n[h])};const P={...e?{}:b.current[h]||{},...ae};return{...E,[h]:P}},{}),[]),O=s.useCallback((e={},{clearCustomFormStates:n=!1,clearCustomFieldStates:E=!1}={})=>{l.current={...l.current,...e},m.current={...l.current},f.current.forEach((h,P)=>{h(j(l.current,P)??"")}),a.current={},f.current=new Map,d.current={...n?{}:d.current,...he},b.current=C(E),y.reset(),i()},[]),S=s.useCallback(()=>{let e=Object.fromEntries(new FormData(u.current));f.current.forEach((E,h)=>{e=W(e,h,j(m.current,h))});let n={...m.current,...e};return me(n)},[]),v=s.useCallback(e=>Re(e.target),[]),F=s.useCallback(()=>l.current,[]),w=s.useCallback(()=>f.current,[]),N=s.useCallback((e,n)=>n?Array.isArray(n)?n.reduce((E,h)=>({...E,[h]:j(e,h)}),{}):j(e,n):{...e},[]),I=s.useCallback(e=>N(m.current,e),[N]),z=s.useCallback(e=>N(a.current,e),[N]),ue=s.useCallback(e=>N(b.current,e),[N]),$=s.useCallback(e=>N({...d.current,lastReset:o},e),[o]),J=s.useCallback(({name:e,compute:n}={})=>!e&&!n||e==="values"?I():typeof n=="function"?n(I()):Array.isArray(e)?e.reduce((E,h)=>({...E,[h]:J({name:h})}),{}):j({...m.current,errors:a.current,fieldStates:b.current,formState:$()},e),[]),y=xe({getWatchValue:J}),{watch:ee,registerHookWatcher:le,subscribe:Z}=De({getWatchValue:J,channels:y}),te=s.useCallback((e,n)=>{const E=d.current,h=j(E,e);h!==n&&(d.current=W(d.current,e,n),y.publish(`formState.${e}`,n,h))},[]),re=s.useCallback((e,n)=>{x(e,"error",n)},[]),B=s.useCallback(e=>{x(e,"error",null)},[]),se=s.useCallback(()=>{d.current.isError&&Object.keys(a.current).forEach(e=>B(e))},[]),x=s.useCallback((e,n,E)=>{try{if(typeof E=="function"&&(E=E(J({name:e}))),R.current.has(e))if(typeof E=="object"&&E!==null){Object.keys(E).forEach(T=>{x(`${e}.${T}`,n,E[T])});return}else return console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);const h=j(b.current,e)||{...ae},P=j(h,n);if(P!==E){if(b.current=W(b.current,`${e}.${n}`,E),y.publish(`fieldStates.${e}.${n}`,E,P),n==="error"){const T=j(a.current,e),V=E||null;T!==V&&(a.current=W(a.current,e,V),y.publish(`errors.${e}`,V,T));const U=Ce(R.current,a.current);d.current.errorFields=U,y.publish("formState.errorFields",U);const ie=U.length>0;if(d.current.isError!==ie){const We=d.current.isError;d.current.isError=ie,y.publish("formState.isError",ie,We)}}if(n==="isDirty"){const T=ve(R.current,b.current);d.current.dirtyFields=T,y.publish("formState.dirtyFields",T);const V=T.length>0;if(d.current.isDirty!==V){const U=d.current.isDirty;d.current.isDirty=V,y.publish("formState.isDirty",V,U)}}if(n==="isTouched"){const T=Se(R.current,b.current);d.current.touchedFields=T,y.publish("formState.touchedFields",T)}}}catch(h){console.log(h)}},[]),ne=s.useCallback(e=>{x(e,"isDirty",!1),x(e,"isTouched",!1),x(e,"error",!1)},[]),oe=s.useCallback(e=>{const n=Re(e.target);n?re(e.target.name,n):B(e.target.name)},[]),Q=s.useCallback((e,n,{shouldDirty:E=!0,shouldOnChange:h=!0}={})=>{if(typeof n=="function"&&(n=n(I(e))),R.current.has(e)){typeof n=="object"&&n!==null?Object.keys(n).forEach(U=>{Q(`${e}.${U}`,n[U],{shouldDirty:E,shouldOnChange:h})}):console.error(`Cannot set primitive value for nested parent field "${e}". Please set value for its children or provide an object.`);return}const P=j(m.current,e);if(n===P)return;m.current=W(m.current,e,n),y.publish(`values.${e}`,n,P);const T=f.current.get(e);T&&T(n),n&&x(e,"isTouched",!0);const V=n!==(j(l.current,e)||"");E&&x(e,"isDirty",V),h&&y.publish("onChange",e,n,P)},[]),t=s.useCallback(e=>{const n=e.split(".");let E="";n.forEach((h,P)=>{P<n.length-1&&(E=E?`${E}.${h}`:h,R.current.add(E))})},[]),g=s.useCallback((e="",n)=>(f.current.set(e,n),b.current=W(b.current,e,{...ae}),e.includes(".")&&t(e),()=>{r&&f.current.delete(e)}),[]),p=s.useCallback((e,{keepError:n,keepDirty:E,keepTouched:h,defaultValue:P})=>{const T=f.current.get(e);if(!T)throw new Error(`Cannot reset "${e}" because it's uncontrolled field`);l.current=W(l.current,e,P),m.current=W(m.current,e,P),T&&T(P),n||B(e),E||x(e,"isDirty",!1),h||x(e,"isTouched",!1)},[]),_=s.useCallback(e=>{if(!e)return y.trigger("values");if(!Array.isArray(e)){const n=L(e);y.trigger(n);return}e.forEach(n=>{const E=L(n);y.trigger(E)})},[]),Y=s.useCallback((e,n=D.getValues(e))=>{y.publish("onBlur",e,n,D.getValues())},[]),D=s.useMemo(()=>({subscribe:Z,reset:O,trigger:_,reload:i,resetField:p,setValue:Q,getValues:I,getErrors:z,getFieldStates:ue,getFormState:$,setError:re,clearError:B,clearErrors:se,checkValidity:oe,getFieldValidity:v,getDefaultValues:F,setFieldState:x,triggerFieldBlur:Y,resetFieldState:ne,getControlledFields:w,setFormState:te,getEvents:y.getEvents,getWatchEvents:y.getWatchEvents}),[o]),G=s.useCallback(()=>{[...u.current.querySelectorAll("[name]")].forEach(E=>{const h=E.name||"";h.includes(".")&&t(h),!E.defaultValue&&!f.current.has(h)&&j(l.current,h)&&(E.defaultValue=j(l.current,h))});const n=S();m.current={...n},l.current={...n}},[]),K=s.useMemo(()=>({ref:u,watch:ee,actions:D,initForm:G,registerController:g,registerHookWatcher:le,lastReloadedAt:o,loadFormValues:S,getWatchValue:J,channels:y}),[o]),A=s.useMemo(()=>({control:K,actions:D,watch:ee}),[o]);return s.useLayoutEffect(()=>{u.current&&G()},[o]),s.useLayoutEffect(()=>{b.current=C(!1)},[]),A};M.Controller=we,M.Form=Te,M.restoreFromDotNotation=me,M.useController=pe,M.useForm=Me,M.useFormContext=ce,M.useWatch=je,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|