react-simple-formkit 1.3.1 → 1.3.2
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.
|
@@ -19,4 +19,4 @@
|
|
|
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} />`,k,_,x,_),S[_+k]=!0)}if(_=null,c!==void 0&&(o(c),_=""+c),E(r)&&(o(r.key),_=""+r.key),"key"in r){c={};for(var H in r)H!=="key"&&(c[H]=r[H])}else c=r;return _&&d(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),v(e,_,w,C,u(),c,X,B)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===N&&e._store&&(e._store.validated=1)}var T=n,N=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),G=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),q=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),U=Symbol.for("react.activity"),j=Symbol.for("react.client.reference"),F=T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,Y=Array.isArray,P=console.createTask?console.createTask:function(){return null};T={"react-stack-bottom-frame":function(e){return e()}};var J,t={},f=T["react-stack-bottom-frame"].bind(T,i)(),R=P(l(i)),S={};$.Fragment=h,$.jsx=function(e,r,c,k,C){var w=1e4>F.recentlyCreatedOwnerStacks++;return p(e,r,c,!1,k,C,w?Error("react-stack-top-frame"):f,w?P(l(e)):R)},$.jsxs=function(e,r,c,k,C){var w=1e4>F.recentlyCreatedOwnerStacks++;return p(e,r,c,!0,k,C,w?Error("react-stack-top-frame"):f,w?P(l(e)):R)}}()),$}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=se():z.exports=oe()),z.exports}var ee=ce();const te=n.createContext({}),ue=()=>n.useContext(te),le=({id:s,form:a,method:o,action:l,children:u,onSubmit:i=()=>{},onInput:E=()=>{},onChange:d=()=>{},numberFields:b=[],className:v,...p})=>(n.useEffect(()=>a.actions.registerOnchange(d),[d]),ee.jsx(te.Provider,{value:a,children:ee.jsx("form",{id:s,ref:a==null?void 0:a.ref,action:l,method:o,className:v,onSubmit:m=>{o||m.preventDefault();const T=a.actions.loadFormValues();i(T)},onInput:m=>{if(m.target.tagName==="FORM"){const T=a.actions.loadFormValues();a.actions.setFormState(T)}else E(m)},onChange:()=>{const m=a.actions.loadFormValues();a.actions.setFormState(m)},onReset:m=>{a&&(m.preventDefault(),a.actions.reset())},...p,children:u},a==null?void 0:a.lastReloadedAt)})),ie=({name:s,render:a=({ref:o,name:l,defaultValue:u,value:i,setValue:E})=>null})=>{const o=n.useRef(),l=ue(),u=l.actions.getDefaultValues()[s],[i,E]=n.useState(u),d=n.useCallback((b,{shouldDirty:v=!1}={})=>{l.actions.setFormState(p=>({...p,[s]:b}),{shouldDirty:v}),E(b)},[E,l.actions.setFormState]);return n.useEffect(()=>l.subscribe(s,(v,{shouldDirty:p=!0,shouldOnChange:m=!0}={})=>{E(v),l.actions.setFormState(T=>({...T,[s]:v}),{shouldDirty:p,shouldOnChange:m}),o.current&&typeof o.current.dispatchEvent=="function"&&m&&o.current.dispatchEvent(new Event("change"))}),[]),a({ref:o,name:s,defaultValue:u,value:i,setValue:d})},fe=(s,a)=>{let o=!1;return Object.keys(a).forEach(l=>{if(!(l in s)||o)return;const u=a[l],i=s[l];(typeof u=="object"||u!==i)&&(o=!0)}),o},re=s=>(typeof s.setCustomValidity=="function"&&s.setCustomValidity(""),!s||typeof s.checkValidity!="function"||s.checkValidity()?null:s.validationMessage),ne=()=>{const[s,a]=n.useState({}),o=n.useMemo(()=>Object.values(s).filter(Boolean).length>0,[s]),l=n.useCallback((d,b)=>{a(v=>v[d]===b?v:{...v,[d]:b})},[]),u=n.useCallback(d=>{a(b=>({...b,...d}))},[]),i=n.useCallback(d=>{a(b=>b[d]?{...b,[d]:""}:b)},[]),E=n.useCallback(()=>{a({})},[]);return{isError:o,errors:s,changeError:l,changeErrors:u,clearError:i,clearErrors:E}},de=()=>{const[s,a]=n.useState(),o=n.useCallback(()=>a(new Date().toString()),[]);return[s,o]},be=()=>{const[,s]=n.useState({});return n.useCallback(()=>s({}),[])},Ee=[],me=({numberFields:s=Ee,defaultValues:a={}}={})=>{const{changeError:o,errors:l,changeErrors:u,clearError:i,clearErrors:E,isError:d}=ne(),[b,v]=n.useState(!1),[p,m]=de(),T=be(),N=n.useRef(new Set),g=n.useRef(
|
|
22
|
+
<%s key={someKey} {...props} />`,k,_,x,_),S[_+k]=!0)}if(_=null,c!==void 0&&(o(c),_=""+c),E(r)&&(o(r.key),_=""+r.key),"key"in r){c={};for(var H in r)H!=="key"&&(c[H]=r[H])}else c=r;return _&&d(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),v(e,_,w,C,u(),c,X,B)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===N&&e._store&&(e._store.validated=1)}var T=n,N=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),G=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),q=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),U=Symbol.for("react.activity"),j=Symbol.for("react.client.reference"),F=T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,D=Object.prototype.hasOwnProperty,Y=Array.isArray,P=console.createTask?console.createTask:function(){return null};T={"react-stack-bottom-frame":function(e){return e()}};var J,t={},f=T["react-stack-bottom-frame"].bind(T,i)(),R=P(l(i)),S={};$.Fragment=h,$.jsx=function(e,r,c,k,C){var w=1e4>F.recentlyCreatedOwnerStacks++;return p(e,r,c,!1,k,C,w?Error("react-stack-top-frame"):f,w?P(l(e)):R)},$.jsxs=function(e,r,c,k,C){var w=1e4>F.recentlyCreatedOwnerStacks++;return p(e,r,c,!0,k,C,w?Error("react-stack-top-frame"):f,w?P(l(e)):R)}}()),$}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=se():z.exports=oe()),z.exports}var ee=ce();const te=n.createContext({}),ue=()=>n.useContext(te),le=({id:s,form:a,method:o,action:l,children:u,onSubmit:i=()=>{},onInput:E=()=>{},onChange:d=()=>{},numberFields:b=[],className:v,...p})=>(n.useEffect(()=>a.actions.registerOnchange(d),[d]),ee.jsx(te.Provider,{value:a,children:ee.jsx("form",{id:s,ref:a==null?void 0:a.ref,action:l,method:o,className:v,onSubmit:m=>{o||m.preventDefault();const T=a.actions.loadFormValues();i(T)},onInput:m=>{if(m.target.tagName==="FORM"){const T=a.actions.loadFormValues();a.actions.setFormState(T)}else E(m)},onChange:()=>{const m=a.actions.loadFormValues();a.actions.setFormState(m)},onReset:m=>{a&&(m.preventDefault(),a.actions.reset())},...p,children:u},a==null?void 0:a.lastReloadedAt)})),ie=({name:s,render:a=({ref:o,name:l,defaultValue:u,value:i,setValue:E})=>null})=>{const o=n.useRef(),l=ue(),u=l.actions.getDefaultValues()[s],[i,E]=n.useState(u),d=n.useCallback((b,{shouldDirty:v=!1}={})=>{l.actions.setFormState(p=>({...p,[s]:b}),{shouldDirty:v}),E(b)},[E,l.actions.setFormState]);return n.useEffect(()=>l.subscribe(s,(v,{shouldDirty:p=!0,shouldOnChange:m=!0}={})=>{E(v),l.actions.setFormState(T=>({...T,[s]:v}),{shouldDirty:p,shouldOnChange:m}),o.current&&typeof o.current.dispatchEvent=="function"&&m&&o.current.dispatchEvent(new Event("change"))}),[]),a({ref:o,name:s,defaultValue:u,value:i,setValue:d})},fe=(s,a)=>{let o=!1;return Object.keys(a).forEach(l=>{if(!(l in s)||o)return;const u=a[l],i=s[l];(typeof u=="object"||u!==i)&&(o=!0)}),o},re=s=>(typeof s.setCustomValidity=="function"&&s.setCustomValidity(""),!s||typeof s.checkValidity!="function"||s.checkValidity()?null:s.validationMessage),ne=()=>{const[s,a]=n.useState({}),o=n.useMemo(()=>Object.values(s).filter(Boolean).length>0,[s]),l=n.useCallback((d,b)=>{a(v=>v[d]===b?v:{...v,[d]:b})},[]),u=n.useCallback(d=>{a(b=>({...b,...d}))},[]),i=n.useCallback(d=>{a(b=>b[d]?{...b,[d]:""}:b)},[]),E=n.useCallback(()=>{a({})},[]);return{isError:o,errors:s,changeError:l,changeErrors:u,clearError:i,clearErrors:E}},de=()=>{const[s,a]=n.useState(),o=n.useCallback(()=>a(new Date().toString()),[]);return[s,o]},be=()=>{const[,s]=n.useState({});return n.useCallback(()=>s({}),[])},Ee=[],me=({numberFields:s=Ee,defaultValues:a={}}={})=>{const{changeError:o,errors:l,changeErrors:u,clearError:i,clearErrors:E,isError:d}=ne(),[b,v]=n.useState(!1),[p,m]=de(),T=be(),N=n.useRef(new Set),g=n.useRef(a),h=n.useRef(a),A=n.useRef({}),V=n.useRef(()=>{}),y=n.useRef(),M=n.useCallback((t,{shouldDirty:f=!0,shouldOnChange:R=!0}={})=>{let S=t;typeof t=="function"&&(S=t(g.current)),[...N.current].forEach(c=>{g.current[c]!==S[c]&&T()}),g.current=S;let r=b;f&&(r=fe(g.current,h.current),r!==b&&v(r)),R&&V.current(g.current)},[b]),L=n.useCallback(()=>{v(!1),E();const t=A.current;Object.keys(t).forEach(f=>{const R=t[f];R(h.current[f],{shouldDirty:!1,shouldOnChange:!1})}),y.current&&y.current.reset(),m()},[E]),G=n.useCallback((t,f)=>{const R=A.current;return R[t]=f,()=>{delete R[t],delete g.current[t],delete h.current[t]}},[]),W=n.useCallback(t=>(V.current=t,()=>V.current=()=>{})),q=n.useCallback(t=>re(t.target),[]),O=n.useCallback(t=>t?g.current[t]:g.current,[]),U=n.useCallback(()=>h.current,[]),j=n.useCallback(()=>{setTimeout(()=>y.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),F=n.useCallback(t=>{const f=re(t.target);f?o(t.target.name,f):o(t.target.name,null)},[o]),D=n.useCallback((t,f,{shouldDirty:R=!0,shouldOnChange:S=!0}={})=>{const e=A.current;switch(typeof t){case"string":{const r=e[t];if(!r)throw new Error(`${t} is uncontrolled, please use Controller for it!`);r(f,{shouldDirty:R,shouldOnChange:S}),S&&j()}break;case"object":Object.entries(t).forEach(([r,c])=>{const k=e[r];if(!k)throw new Error(`${r} is uncontrolled, please use Controller for it!`);k(c,{shouldDirty:R,shouldOnChange:S})}),S&&j();default:return}},[j]),Y=n.useCallback(()=>{const t=Object.fromEntries(new FormData(y.current)),f=A.current;return Object.keys(f).map(R=>{t[R]=g.current[R]}),s.forEach(R=>t.hasOwnProperty(R)&&(t[R]=+t[R])),t},[]),P=t=>(N.current.add(t),t==="data"?O():O()[t]),J=n.useMemo(()=>({setValue:D,instantChange:j,getDefaultValues:U,getFormState:O,setFormState:M,changeError:o,changeErrors:u,clearError:i,clearErrors:E,loadFormValues:Y,checkValidity:F,getFieldValidity:q,registerOnchange:W,reload:m,reset:L,watch:P}),[D,j,U,O,M,o,u,i,Y,q,F,W,m,L,P]);return n.useEffect(()=>{if(y.current){const t=Y();h.current=t,g.current=t}return()=>{h.current={},g.current={},v(!1),E()}},[p]),n.useLayoutEffect(()=>{y.current&&[...y.current.querySelectorAll("[name]")].forEach(f=>{!f.defaultValue&&a[f.name]&&(f.defaultValue=a[f.name])})},[p]),{ref:y,lastReloadedAt:p,isDirty:b,isError:d,errors:l,numberFields:s,subscribe:G,actions:J}};exports.Controller=ie;exports.Form=le;exports.useForm=me;exports.useValidateForm=ne;
|
|
@@ -360,7 +360,7 @@ const se = le({}), me = () => ie(se), he = ({
|
|
|
360
360
|
const [, o] = L({});
|
|
361
361
|
return p(() => o({}), []);
|
|
362
362
|
}, ge = [], ke = ({ numberFields: o = ge, defaultValues: n = {} } = {}) => {
|
|
363
|
-
const { changeError: a, errors: u, changeErrors: c, clearError: l, clearErrors: E, isError: f } = pe(), [d, _] = L(!1), [T, b] = _e(), h = ve(), V = x(/* @__PURE__ */ new Set()), g = x(
|
|
363
|
+
const { changeError: a, errors: u, changeErrors: c, clearError: l, clearErrors: E, isError: f } = pe(), [d, _] = L(!1), [T, b] = _e(), h = ve(), V = x(/* @__PURE__ */ new Set()), g = x(n), k = x(n), F = x({}), D = x(() => {
|
|
364
364
|
}), w = x(), W = p(
|
|
365
365
|
(t, { shouldDirty: i = !0, shouldOnChange: m = !0 } = {}) => {
|
|
366
366
|
let S = t;
|
|
@@ -19,4 +19,4 @@
|
|
|
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} />`,k,v,N,v),g[v+k]=!0)}if(v=null,c!==void 0&&(o(c),v=""+c),E(t)&&(o(t.key),v=""+t.key),"key"in t){c={};for(var K in t)K!=="key"&&(c[K]=t[K])}else c=t;return v&&d(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),p(e,v,C,O,u(),c,Z,Q)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===Y&&e._store&&(e._store.validated=1)}var h=n,Y=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),F=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),H=Symbol.for("react.suspense"),z=Symbol.for("react.suspense_list"),G=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),A=Symbol.for("react.client.reference"),P=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,L=Array.isArray,x=console.createTask?console.createTask:function(){return null};h={"react-stack-bottom-frame":function(e){return e()}};var B,r={},f=h["react-stack-bottom-frame"].bind(h,i)(),R=x(l(i)),g={};D.Fragment=y,D.jsx=function(e,t,c,k,O){var C=1e4>P.recentlyCreatedOwnerStacks++;return _(e,t,c,!1,k,O,C?Error("react-stack-top-frame"):f,C?x(l(e)):R)},D.jsxs=function(e,t,c,k,O){var C=1e4>P.recentlyCreatedOwnerStacks++;return _(e,t,c,!0,k,O,C?Error("react-stack-top-frame"):f,C?x(l(e)):R)}}()),D}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?W.exports=se():W.exports=oe()),W.exports}var te=ce();const re=n.createContext({}),ue=()=>n.useContext(re),le=({id:s,form:a,method:o,action:l,children:u,onSubmit:i=()=>{},onInput:E=()=>{},onChange:d=()=>{},numberFields:b=[],className:p,..._})=>(n.useEffect(()=>a.actions.registerOnchange(d),[d]),te.jsx(re.Provider,{value:a,children:te.jsx("form",{id:s,ref:a==null?void 0:a.ref,action:l,method:o,className:p,onSubmit:m=>{o||m.preventDefault();const h=a.actions.loadFormValues();i(h)},onInput:m=>{if(m.target.tagName==="FORM"){const h=a.actions.loadFormValues();a.actions.setFormState(h)}else E(m)},onChange:()=>{const m=a.actions.loadFormValues();a.actions.setFormState(m)},onReset:m=>{a&&(m.preventDefault(),a.actions.reset())},..._,children:u},a==null?void 0:a.lastReloadedAt)})),ie=({name:s,render:a=({ref:o,name:l,defaultValue:u,value:i,setValue:E})=>null})=>{const o=n.useRef(),l=ue(),u=l.actions.getDefaultValues()[s],[i,E]=n.useState(u),d=n.useCallback((b,{shouldDirty:p=!1}={})=>{l.actions.setFormState(_=>({..._,[s]:b}),{shouldDirty:p}),E(b)},[E,l.actions.setFormState]);return n.useEffect(()=>l.subscribe(s,(p,{shouldDirty:_=!0,shouldOnChange:m=!0}={})=>{E(p),l.actions.setFormState(h=>({...h,[s]:p}),{shouldDirty:_,shouldOnChange:m}),o.current&&typeof o.current.dispatchEvent=="function"&&m&&o.current.dispatchEvent(new Event("change"))}),[]),a({ref:o,name:s,defaultValue:u,value:i,setValue:d})},fe=(s,a)=>{let o=!1;return Object.keys(a).forEach(l=>{if(!(l in s)||o)return;const u=a[l],i=s[l];(typeof u=="object"||u!==i)&&(o=!0)}),o},ne=s=>(typeof s.setCustomValidity=="function"&&s.setCustomValidity(""),!s||typeof s.checkValidity!="function"||s.checkValidity()?null:s.validationMessage),ae=()=>{const[s,a]=n.useState({}),o=n.useMemo(()=>Object.values(s).filter(Boolean).length>0,[s]),l=n.useCallback((d,b)=>{a(p=>p[d]===b?p:{...p,[d]:b})},[]),u=n.useCallback(d=>{a(b=>({...b,...d}))},[]),i=n.useCallback(d=>{a(b=>b[d]?{...b,[d]:""}:b)},[]),E=n.useCallback(()=>{a({})},[]);return{isError:o,errors:s,changeError:l,changeErrors:u,clearError:i,clearErrors:E}},de=()=>{const[s,a]=n.useState(),o=n.useCallback(()=>a(new Date().toString()),[]);return[s,o]},be=()=>{const[,s]=n.useState({});return n.useCallback(()=>s({}),[])},Ee=[],me=({numberFields:s=Ee,defaultValues:a={}}={})=>{const{changeError:o,errors:l,changeErrors:u,clearError:i,clearErrors:E,isError:d}=ae(),[b,p]=n.useState(!1),[_,m]=de(),h=be(),Y=n.useRef(new Set),T=n.useRef(
|
|
22
|
+
<%s key={someKey} {...props} />`,k,v,N,v),g[v+k]=!0)}if(v=null,c!==void 0&&(o(c),v=""+c),E(t)&&(o(t.key),v=""+t.key),"key"in t){c={};for(var K in t)K!=="key"&&(c[K]=t[K])}else c=t;return v&&d(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),p(e,v,C,O,u(),c,Z,Q)}function m(e){typeof e=="object"&&e!==null&&e.$$typeof===Y&&e._store&&(e._store.validated=1)}var h=n,Y=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),F=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),H=Symbol.for("react.suspense"),z=Symbol.for("react.suspense_list"),G=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),A=Symbol.for("react.client.reference"),P=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,L=Array.isArray,x=console.createTask?console.createTask:function(){return null};h={"react-stack-bottom-frame":function(e){return e()}};var B,r={},f=h["react-stack-bottom-frame"].bind(h,i)(),R=x(l(i)),g={};D.Fragment=y,D.jsx=function(e,t,c,k,O){var C=1e4>P.recentlyCreatedOwnerStacks++;return _(e,t,c,!1,k,O,C?Error("react-stack-top-frame"):f,C?x(l(e)):R)},D.jsxs=function(e,t,c,k,O){var C=1e4>P.recentlyCreatedOwnerStacks++;return _(e,t,c,!0,k,O,C?Error("react-stack-top-frame"):f,C?x(l(e)):R)}}()),D}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?W.exports=se():W.exports=oe()),W.exports}var te=ce();const re=n.createContext({}),ue=()=>n.useContext(re),le=({id:s,form:a,method:o,action:l,children:u,onSubmit:i=()=>{},onInput:E=()=>{},onChange:d=()=>{},numberFields:b=[],className:p,..._})=>(n.useEffect(()=>a.actions.registerOnchange(d),[d]),te.jsx(re.Provider,{value:a,children:te.jsx("form",{id:s,ref:a==null?void 0:a.ref,action:l,method:o,className:p,onSubmit:m=>{o||m.preventDefault();const h=a.actions.loadFormValues();i(h)},onInput:m=>{if(m.target.tagName==="FORM"){const h=a.actions.loadFormValues();a.actions.setFormState(h)}else E(m)},onChange:()=>{const m=a.actions.loadFormValues();a.actions.setFormState(m)},onReset:m=>{a&&(m.preventDefault(),a.actions.reset())},..._,children:u},a==null?void 0:a.lastReloadedAt)})),ie=({name:s,render:a=({ref:o,name:l,defaultValue:u,value:i,setValue:E})=>null})=>{const o=n.useRef(),l=ue(),u=l.actions.getDefaultValues()[s],[i,E]=n.useState(u),d=n.useCallback((b,{shouldDirty:p=!1}={})=>{l.actions.setFormState(_=>({..._,[s]:b}),{shouldDirty:p}),E(b)},[E,l.actions.setFormState]);return n.useEffect(()=>l.subscribe(s,(p,{shouldDirty:_=!0,shouldOnChange:m=!0}={})=>{E(p),l.actions.setFormState(h=>({...h,[s]:p}),{shouldDirty:_,shouldOnChange:m}),o.current&&typeof o.current.dispatchEvent=="function"&&m&&o.current.dispatchEvent(new Event("change"))}),[]),a({ref:o,name:s,defaultValue:u,value:i,setValue:d})},fe=(s,a)=>{let o=!1;return Object.keys(a).forEach(l=>{if(!(l in s)||o)return;const u=a[l],i=s[l];(typeof u=="object"||u!==i)&&(o=!0)}),o},ne=s=>(typeof s.setCustomValidity=="function"&&s.setCustomValidity(""),!s||typeof s.checkValidity!="function"||s.checkValidity()?null:s.validationMessage),ae=()=>{const[s,a]=n.useState({}),o=n.useMemo(()=>Object.values(s).filter(Boolean).length>0,[s]),l=n.useCallback((d,b)=>{a(p=>p[d]===b?p:{...p,[d]:b})},[]),u=n.useCallback(d=>{a(b=>({...b,...d}))},[]),i=n.useCallback(d=>{a(b=>b[d]?{...b,[d]:""}:b)},[]),E=n.useCallback(()=>{a({})},[]);return{isError:o,errors:s,changeError:l,changeErrors:u,clearError:i,clearErrors:E}},de=()=>{const[s,a]=n.useState(),o=n.useCallback(()=>a(new Date().toString()),[]);return[s,o]},be=()=>{const[,s]=n.useState({});return n.useCallback(()=>s({}),[])},Ee=[],me=({numberFields:s=Ee,defaultValues:a={}}={})=>{const{changeError:o,errors:l,changeErrors:u,clearError:i,clearErrors:E,isError:d}=ae(),[b,p]=n.useState(!1),[_,m]=de(),h=be(),Y=n.useRef(new Set),T=n.useRef(a),y=n.useRef(a),F=n.useRef({}),I=n.useRef(()=>{}),w=n.useRef(),U=n.useCallback((r,{shouldDirty:f=!0,shouldOnChange:R=!0}={})=>{let g=r;typeof r=="function"&&(g=r(T.current)),[...Y.current].forEach(c=>{T.current[c]!==g[c]&&h()}),T.current=g;let t=b;f&&(t=fe(T.current,y.current),t!==b&&p(t)),R&&I.current(T.current)},[b]),J=n.useCallback(()=>{p(!1),E();const r=F.current;Object.keys(r).forEach(f=>{const R=r[f];R(y.current[f],{shouldDirty:!1,shouldOnChange:!1})}),w.current&&w.current.reset(),m()},[E]),H=n.useCallback((r,f)=>{const R=F.current;return R[r]=f,()=>{delete R[r],delete T.current[r],delete y.current[r]}},[]),z=n.useCallback(r=>(I.current=r,()=>I.current=()=>{})),G=n.useCallback(r=>ne(r.target),[]),j=n.useCallback(r=>r?T.current[r]:T.current,[]),X=n.useCallback(()=>y.current,[]),A=n.useCallback(()=>{setTimeout(()=>w.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),P=n.useCallback(r=>{const f=ne(r.target);f?o(r.target.name,f):o(r.target.name,null)},[o]),M=n.useCallback((r,f,{shouldDirty:R=!0,shouldOnChange:g=!0}={})=>{const e=F.current;switch(typeof r){case"string":{const t=e[r];if(!t)throw new Error(`${r} is uncontrolled, please use Controller for it!`);t(f,{shouldDirty:R,shouldOnChange:g}),g&&A()}break;case"object":Object.entries(r).forEach(([t,c])=>{const k=e[t];if(!k)throw new Error(`${t} is uncontrolled, please use Controller for it!`);k(c,{shouldDirty:R,shouldOnChange:g})}),g&&A();default:return}},[A]),L=n.useCallback(()=>{const r=Object.fromEntries(new FormData(w.current)),f=F.current;return Object.keys(f).map(R=>{r[R]=T.current[R]}),s.forEach(R=>r.hasOwnProperty(R)&&(r[R]=+r[R])),r},[]),x=r=>(Y.current.add(r),r==="data"?j():j()[r]),B=n.useMemo(()=>({setValue:M,instantChange:A,getDefaultValues:X,getFormState:j,setFormState:U,changeError:o,changeErrors:u,clearError:i,clearErrors:E,loadFormValues:L,checkValidity:P,getFieldValidity:G,registerOnchange:z,reload:m,reset:J,watch:x}),[M,A,X,j,U,o,u,i,L,G,P,z,m,J,x]);return n.useEffect(()=>{if(w.current){const r=L();y.current=r,T.current=r}return()=>{y.current={},T.current={},p(!1),E()}},[_]),n.useLayoutEffect(()=>{w.current&&[...w.current.querySelectorAll("[name]")].forEach(f=>{!f.defaultValue&&a[f.name]&&(f.defaultValue=a[f.name])})},[_]),{ref:w,lastReloadedAt:_,isDirty:b,isError:d,errors:l,numberFields:s,subscribe:H,actions:B}};S.Controller=ie,S.Form=le,S.useForm=me,S.useValidateForm=ae,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|