react-simple-formkit 1.1.15 → 1.1.16
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} />`,v,_,A,_),V[_+v]=!0)}if(_=null,i!==void 0&&(f(i),_=""+i),m(n)&&(f(n.key),_=""+n.key),"key"in n){i={};for(var H in n)H!=="key"&&(i[H]=n[H])}else i=n;return _&&l(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,_,h,O,c(),i,X,B)}function u(e){typeof e=="object"&&e!==null&&e.$$typeof===j&&e._store&&(e._store.validated=1)}var k=a,j=Symbol.for("react.transitional.element"),P=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),N=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,t=Object.prototype.hasOwnProperty,p=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var S,y={},C=k["react-stack-bottom-frame"].bind(k,s)(),J=d(b(s)),V={};Y.Fragment=g,Y.jsx=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!1,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)},Y.jsxs=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!0,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)}}()),Y}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=oe():z.exports=se()),z.exports}var ee=ce();const te=a.createContext({}),ue=()=>a.useContext(te),le=({id:o,form:r,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:l=()=>{},numberFields:E=[],className:R,...T})=>(a.useEffect(()=>r.actions.registerOnchange(l),[l]),ee.jsx(te.Provider,{value:r,children:ee.jsx("form",{ref:r==null?void 0:r.ref,action:b,className:R,onSubmit:u=>{f||u.preventDefault();const k=r.actions.loadFormValues();s(k)},onInput:u=>{if(u.target.tagName==="FORM"){const k=r.actions.loadFormValues();r.actions.setFormState(k)}else m(u)},onChange:()=>{const u=r.actions.loadFormValues();r.actions.setFormState(u)},onReset:u=>{r&&(u.preventDefault(),r.actions.reset())},...T,children:c},r==null?void 0:r.lastReloadedAt)})),ie=({name:o,defaultValue:r,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:l})=>null})=>{const[b,c]=a.useState(r),s=ue(),m=a.useRef(),l=a.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(T=>({...T,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return a.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:r}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:T=!0,shouldOnChange:u=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:T,shouldOnChange:u}),m.current&&typeof m.current.dispatchEvent=="function"&&u&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:r,value:b,setValue:l})},fe=(o,r)=>{let f=!1;return Object.keys(r).forEach(b=>{if(!(b in o)||f)return;const c=r[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},re=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ne=()=>{const[o,r]=a.useState({}),f=a.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=a.useCallback((l,E)=>{r(R=>R[l]===E?R:{...R,[l]:E})},[]),c=a.useCallback(l=>{r(E=>({...E,...l}))},[]),s=a.useCallback(l=>{r(E=>E[l]?{...E,[l]:""}:E)},[]),m=a.useCallback(()=>{r({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,r]=a.useState(),f=a.useCallback(()=>r(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:r,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ne(),[l,E]=a.useState(!1),[R,T]=de(),u=a.useRef({}),k=a.useRef({}),j=a.useRef({}),P=a.useRef(()=>{}),g=a.useRef(),I=a.useCallback((t,{shouldDirty:p=!0,shouldOnChange:d=!0}={})=>{let S=t;typeof t=="function"&&(S=t(u.current)),u.current=S;let y=l;p&&(y=fe(u.current,k.current),y!==l&&E(y)),d&&P.current(u.current)},[l]),$=a.useCallback(()=>{E(!1),s();const t=j.current;Object.keys(t).forEach(p=>{const d=t[p];d(k.current[p],{shouldDirty:!1,shouldOnChange:!1})}),g.current&&g.current.reset(),T()},[s]),G=a.useCallback((t,p)=>{const d=j.current;return d[t]=p,()=>{delete d[t],delete u.current[t],delete k.current[t]}},[]),M=a.useCallback(t=>(P.current=t,()=>P.current=()=>{})),L=a.useCallback(t=>re(t.target),[]),W=a.useCallback(t=>t?u.current[t]:u.current,[]),U=a.useCallback(()=>k.current,[]),w=a.useCallback(()=>{setTimeout(()=>g.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),x=a.useCallback(t=>{const p=re(t.target);p?r(t.target.name,p):r(t.target.name,null)},[r]),q=a.useCallback((t,p,{shouldDirty:d=!0,shouldOnChange:S=!0}={})=>{const y=j.current;switch(typeof t){case"string":{const C=y[t];if(!C)throw new Error(`${t} is uncontrolled, please use Controller for it!`);C(p,{shouldDirty:d,shouldOnChange:S}),S&&w()}break;case"object":Object.entries(t).forEach(([C,J])=>{const V=y[C];if(!V)throw new Error(`${C} is uncontrolled, please use Controller for it!`);V(J,{shouldDirty:d,shouldOnChange:S})}),S&&w();default:return}},[w]),F=a.useCallback(()=>{const t=Object.fromEntries(new FormData(g.current)),p=j.current;return Object.keys(p).map(d=>{t[d]=u.current[d]}),o.forEach(d=>t.hasOwnProperty(d)&&(t[d]=+t[d])),t},[]),N=a.useMemo(()=>({setValue:q,instantChange:w,getDefaultValues:U,getFormState:W,setFormState:I,changeError:r,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:F,checkValidity:x,getFieldValidity:L,registerOnchange:M,reload:T,reset:$}),[q,w,U,W,I,r,b,c,F,L,x,M,T,$]);return a.useEffect(()=>{if(g.current){const t=F();k.current=t,u.current=t}return()=>{k.current={},u.current={},E(!1),s()}},[R]),{ref:g,lastReloadedAt:R,isDirty:l,isError:m,errors:f,numberFields:o,subscribe:G,actions:N}};exports.Controller=ie;exports.Form=le;exports.useForm=Ee;exports.useValidateForm=ne;
|
|
22
|
+
<%s key={someKey} {...props} />`,v,_,A,_),V[_+v]=!0)}if(_=null,i!==void 0&&(f(i),_=""+i),m(n)&&(f(n.key),_=""+n.key),"key"in n){i={};for(var H in n)H!=="key"&&(i[H]=n[H])}else i=n;return _&&l(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,_,h,O,c(),i,X,B)}function u(e){typeof e=="object"&&e!==null&&e.$$typeof===j&&e._store&&(e._store.validated=1)}var k=a,j=Symbol.for("react.transitional.element"),P=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),N=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,t=Object.prototype.hasOwnProperty,p=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var S,y={},C=k["react-stack-bottom-frame"].bind(k,s)(),J=d(b(s)),V={};Y.Fragment=g,Y.jsx=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!1,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)},Y.jsxs=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!0,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)}}()),Y}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=oe():z.exports=se()),z.exports}var ee=ce();const te=a.createContext({}),ue=()=>a.useContext(te),le=({id:o,form:r,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:l=()=>{},numberFields:E=[],className:R,...T})=>(a.useEffect(()=>r.actions.registerOnchange(l),[l]),ee.jsx(te.Provider,{value:r,children:ee.jsx("form",{id:o,ref:r==null?void 0:r.ref,action:b,method:f,className:R,onSubmit:u=>{f||u.preventDefault();const k=r.actions.loadFormValues();s(k)},onInput:u=>{if(u.target.tagName==="FORM"){const k=r.actions.loadFormValues();r.actions.setFormState(k)}else m(u)},onChange:()=>{const u=r.actions.loadFormValues();r.actions.setFormState(u)},onReset:u=>{r&&(u.preventDefault(),r.actions.reset())},...T,children:c},r==null?void 0:r.lastReloadedAt)})),ie=({name:o,defaultValue:r,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:l})=>null})=>{const[b,c]=a.useState(r),s=ue(),m=a.useRef(),l=a.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(T=>({...T,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return a.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:r}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:T=!0,shouldOnChange:u=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:T,shouldOnChange:u}),m.current&&typeof m.current.dispatchEvent=="function"&&u&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:r,value:b,setValue:l})},fe=(o,r)=>{let f=!1;return Object.keys(r).forEach(b=>{if(!(b in o)||f)return;const c=r[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},re=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ne=()=>{const[o,r]=a.useState({}),f=a.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=a.useCallback((l,E)=>{r(R=>R[l]===E?R:{...R,[l]:E})},[]),c=a.useCallback(l=>{r(E=>({...E,...l}))},[]),s=a.useCallback(l=>{r(E=>E[l]?{...E,[l]:""}:E)},[]),m=a.useCallback(()=>{r({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,r]=a.useState(),f=a.useCallback(()=>r(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:r,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ne(),[l,E]=a.useState(!1),[R,T]=de(),u=a.useRef({}),k=a.useRef({}),j=a.useRef({}),P=a.useRef(()=>{}),g=a.useRef(),I=a.useCallback((t,{shouldDirty:p=!0,shouldOnChange:d=!0}={})=>{let S=t;typeof t=="function"&&(S=t(u.current)),u.current=S;let y=l;p&&(y=fe(u.current,k.current),y!==l&&E(y)),d&&P.current(u.current)},[l]),$=a.useCallback(()=>{E(!1),s();const t=j.current;Object.keys(t).forEach(p=>{const d=t[p];d(k.current[p],{shouldDirty:!1,shouldOnChange:!1})}),g.current&&g.current.reset(),T()},[s]),G=a.useCallback((t,p)=>{const d=j.current;return d[t]=p,()=>{delete d[t],delete u.current[t],delete k.current[t]}},[]),M=a.useCallback(t=>(P.current=t,()=>P.current=()=>{})),L=a.useCallback(t=>re(t.target),[]),W=a.useCallback(t=>t?u.current[t]:u.current,[]),U=a.useCallback(()=>k.current,[]),w=a.useCallback(()=>{setTimeout(()=>g.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),x=a.useCallback(t=>{const p=re(t.target);p?r(t.target.name,p):r(t.target.name,null)},[r]),q=a.useCallback((t,p,{shouldDirty:d=!0,shouldOnChange:S=!0}={})=>{const y=j.current;switch(typeof t){case"string":{const C=y[t];if(!C)throw new Error(`${t} is uncontrolled, please use Controller for it!`);C(p,{shouldDirty:d,shouldOnChange:S}),S&&w()}break;case"object":Object.entries(t).forEach(([C,J])=>{const V=y[C];if(!V)throw new Error(`${C} is uncontrolled, please use Controller for it!`);V(J,{shouldDirty:d,shouldOnChange:S})}),S&&w();default:return}},[w]),F=a.useCallback(()=>{const t=Object.fromEntries(new FormData(g.current)),p=j.current;return Object.keys(p).map(d=>{t[d]=u.current[d]}),o.forEach(d=>t.hasOwnProperty(d)&&(t[d]=+t[d])),t},[]),N=a.useMemo(()=>({setValue:q,instantChange:w,getDefaultValues:U,getFormState:W,setFormState:I,changeError:r,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:F,checkValidity:x,getFieldValidity:L,registerOnchange:M,reload:T,reset:$}),[q,w,U,W,I,r,b,c,F,L,x,M,T,$]);return a.useEffect(()=>{if(g.current){const t=F();k.current=t,u.current=t}return()=>{k.current={},u.current={},E(!1),s()}},[R]),{ref:g,lastReloadedAt:R,isDirty:l,isError:m,errors:f,numberFields:o,subscribe:G,actions:N}};exports.Controller=ie;exports.Form=le;exports.useForm=Ee;exports.useValidateForm=ne;
|
|
@@ -50,7 +50,7 @@ function de() {
|
|
|
50
50
|
return e.$$typeof === N ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
|
-
case
|
|
53
|
+
case k:
|
|
54
54
|
return "Fragment";
|
|
55
55
|
case M:
|
|
56
56
|
return "Profiler";
|
|
@@ -108,7 +108,7 @@ function de() {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function d(e) {
|
|
111
|
-
if (e ===
|
|
111
|
+
if (e === k) return "<>";
|
|
112
112
|
if (typeof e == "object" && e !== null && e.$$typeof === C)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
@@ -134,7 +134,7 @@ function de() {
|
|
|
134
134
|
}
|
|
135
135
|
function u(e, n) {
|
|
136
136
|
function l() {
|
|
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
|
n
|
|
140
140
|
));
|
|
@@ -235,7 +235,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
235
235
|
function c(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === w && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var R = ue, w = Symbol.for("react.transitional.element"), F = Symbol.for("react.portal"),
|
|
238
|
+
var R = ue, w = Symbol.for("react.transitional.element"), F = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), $ = Symbol.for("react.strict_mode"), M = Symbol.for("react.profiler"), B = Symbol.for("react.consumer"), L = Symbol.for("react.context"), W = Symbol.for("react.forward_ref"), U = Symbol.for("react.suspense"), q = Symbol.for("react.suspense_list"), A = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), J = Symbol.for("react.activity"), N = Symbol.for("react.client.reference"), D = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, t = Object.prototype.hasOwnProperty, T = Array.isArray, f = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
241
|
R = {
|
|
@@ -243,11 +243,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
246
|
+
var h, y = {}, O = R["react-stack-bottom-frame"].bind(
|
|
247
247
|
R,
|
|
248
248
|
a
|
|
249
249
|
)(), z = f(d(a)), V = {};
|
|
250
|
-
I.Fragment =
|
|
250
|
+
I.Fragment = k, I.jsx = function(e, n, l, _, j) {
|
|
251
251
|
var S = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return g(
|
|
253
253
|
e,
|
|
@@ -297,8 +297,10 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
297
297
|
}) => (K(() => r.actions.registerOnchange(u), [u]), /* @__PURE__ */ ne.jsx(se.Provider, { value: r, children: /* @__PURE__ */ ne.jsx(
|
|
298
298
|
"form",
|
|
299
299
|
{
|
|
300
|
+
id: o,
|
|
300
301
|
ref: r == null ? void 0 : r.ref,
|
|
301
302
|
action: d,
|
|
303
|
+
method: i,
|
|
302
304
|
className: m,
|
|
303
305
|
onSubmit: (c) => {
|
|
304
306
|
i || c.preventDefault();
|
|
@@ -354,12 +356,12 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
354
356
|
}, pe = () => {
|
|
355
357
|
const [o, r] = X(), i = p(() => r((/* @__PURE__ */ new Date()).toString()), []);
|
|
356
358
|
return [o, i];
|
|
357
|
-
}, _e = [],
|
|
359
|
+
}, _e = [], ke = ({ numberFields: o = _e } = {}) => {
|
|
358
360
|
const { changeError: r, errors: i, changeErrors: d, clearError: s, clearErrors: a, isError: b } = Re(), [u, E] = X(!1), [m, g] = pe(), c = P({}), R = P({}), w = P({}), F = P(() => {
|
|
359
|
-
}),
|
|
361
|
+
}), k = P(), $ = p(
|
|
360
362
|
(t, { shouldDirty: T = !0, shouldOnChange: f = !0 } = {}) => {
|
|
361
|
-
let
|
|
362
|
-
typeof t == "function" && (
|
|
363
|
+
let h = t;
|
|
364
|
+
typeof t == "function" && (h = t(c.current)), c.current = h;
|
|
363
365
|
let y = u;
|
|
364
366
|
T && (y = me(c.current, R.current), y !== u && E(y)), f && F.current(c.current);
|
|
365
367
|
},
|
|
@@ -370,7 +372,7 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
370
372
|
Object.keys(t).forEach((T) => {
|
|
371
373
|
const f = t[T];
|
|
372
374
|
f(R.current[T], { shouldDirty: !1, shouldOnChange: !1 });
|
|
373
|
-
}),
|
|
375
|
+
}), k.current && k.current.reset(), g();
|
|
374
376
|
}, [a]), B = p((t, T) => {
|
|
375
377
|
const f = w.current;
|
|
376
378
|
return f[t] = T, () => {
|
|
@@ -378,7 +380,7 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
378
380
|
};
|
|
379
381
|
}, []), L = p((t) => (F.current = t, () => F.current = () => {
|
|
380
382
|
})), W = p((t) => oe(t.target), []), U = p((t) => t ? c.current[t] : c.current, []), q = p(() => R.current, []), A = p(() => {
|
|
381
|
-
setTimeout(() =>
|
|
383
|
+
setTimeout(() => k.current.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
382
384
|
}, []), C = p(
|
|
383
385
|
(t) => {
|
|
384
386
|
const T = oe(t.target);
|
|
@@ -386,7 +388,7 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
386
388
|
},
|
|
387
389
|
[r]
|
|
388
390
|
), J = p(
|
|
389
|
-
(t, T, { shouldDirty: f = !0, shouldOnChange:
|
|
391
|
+
(t, T, { shouldDirty: f = !0, shouldOnChange: h = !0 } = {}) => {
|
|
390
392
|
const y = w.current;
|
|
391
393
|
switch (typeof t) {
|
|
392
394
|
case "string":
|
|
@@ -394,7 +396,7 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
394
396
|
const O = y[t];
|
|
395
397
|
if (!O)
|
|
396
398
|
throw new Error(`${t} is uncontrolled, please use Controller for it!`);
|
|
397
|
-
O(T, { shouldDirty: f, shouldOnChange:
|
|
399
|
+
O(T, { shouldDirty: f, shouldOnChange: h }), h && A();
|
|
398
400
|
}
|
|
399
401
|
break;
|
|
400
402
|
case "object":
|
|
@@ -402,15 +404,15 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
402
404
|
const V = y[O];
|
|
403
405
|
if (!V)
|
|
404
406
|
throw new Error(`${O} is uncontrolled, please use Controller for it!`);
|
|
405
|
-
V(z, { shouldDirty: f, shouldOnChange:
|
|
406
|
-
}),
|
|
407
|
+
V(z, { shouldDirty: f, shouldOnChange: h });
|
|
408
|
+
}), h && A();
|
|
407
409
|
default:
|
|
408
410
|
return;
|
|
409
411
|
}
|
|
410
412
|
},
|
|
411
413
|
[A]
|
|
412
414
|
), N = p(() => {
|
|
413
|
-
const t = Object.fromEntries(new FormData(
|
|
415
|
+
const t = Object.fromEntries(new FormData(k.current)), T = w.current;
|
|
414
416
|
return Object.keys(T).map((f) => {
|
|
415
417
|
t[f] = c.current[f];
|
|
416
418
|
}), o.forEach((f) => t.hasOwnProperty(f) && (t[f] = +t[f])), t;
|
|
@@ -450,18 +452,18 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
450
452
|
]
|
|
451
453
|
);
|
|
452
454
|
return K(() => {
|
|
453
|
-
if (
|
|
455
|
+
if (k.current) {
|
|
454
456
|
const t = N();
|
|
455
457
|
R.current = t, c.current = t;
|
|
456
458
|
}
|
|
457
459
|
return () => {
|
|
458
460
|
R.current = {}, c.current = {}, E(!1), a();
|
|
459
461
|
};
|
|
460
|
-
}, [m]), { ref:
|
|
462
|
+
}, [m]), { ref: k, lastReloadedAt: m, isDirty: u, isError: b, errors: i, numberFields: o, subscribe: B, actions: D };
|
|
461
463
|
};
|
|
462
464
|
export {
|
|
463
465
|
ge as Controller,
|
|
464
466
|
Te as Form,
|
|
465
|
-
|
|
467
|
+
ke as useForm,
|
|
466
468
|
Re as useValidateForm
|
|
467
469
|
};
|
|
@@ -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} />`,p,v,P,v),I[v+p]=!0)}if(v=null,i!==void 0&&(f(i),v=""+i),m(a)&&(f(a.key),v=""+a.key),"key"in a){i={};for(var K in a)K!=="key"&&(i[K]=a[K])}else i=a;return v&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,v,y,j,c(),i,Z,Q)}function l(e){typeof e=="object"&&e!==null&&e.$$typeof===w&&e._store&&(e._store.validated=1)}var k=r,w=Symbol.for("react.transitional.element"),N=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),L=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),H=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),z=Symbol.for("react.suspense"),G=Symbol.for("react.suspense_list"),A=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),Y=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,n=Object.prototype.hasOwnProperty,T=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var h,C={},O=k["react-stack-bottom-frame"].bind(k,s)(),B=d(b(s)),I={};x.Fragment=S,x.jsx=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!1,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)},x.jsxs=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!0,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)}}()),x}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?M.exports=oe():M.exports=se()),M.exports}var te=ce();const re=r.createContext({}),le=()=>r.useContext(re),ue=({id:o,form:t,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:u=()=>{},numberFields:E=[],className:R,..._})=>(r.useEffect(()=>t.actions.registerOnchange(u),[u]),te.jsx(re.Provider,{value:t,children:te.jsx("form",{ref:t==null?void 0:t.ref,action:b,className:R,onSubmit:l=>{f||l.preventDefault();const k=t.actions.loadFormValues();s(k)},onInput:l=>{if(l.target.tagName==="FORM"){const k=t.actions.loadFormValues();t.actions.setFormState(k)}else m(l)},onChange:()=>{const l=t.actions.loadFormValues();t.actions.setFormState(l)},onReset:l=>{t&&(l.preventDefault(),t.actions.reset())},..._,children:c},t==null?void 0:t.lastReloadedAt)})),ie=({name:o,defaultValue:t,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:u})=>null})=>{const[b,c]=r.useState(t),s=le(),m=r.useRef(),u=r.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(_=>({..._,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return r.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:t}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:_=!0,shouldOnChange:l=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:_,shouldOnChange:l}),m.current&&typeof m.current.dispatchEvent=="function"&&l&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:t,value:b,setValue:u})},fe=(o,t)=>{let f=!1;return Object.keys(t).forEach(b=>{if(!(b in o)||f)return;const c=t[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},ne=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ae=()=>{const[o,t]=r.useState({}),f=r.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=r.useCallback((u,E)=>{t(R=>R[u]===E?R:{...R,[u]:E})},[]),c=r.useCallback(u=>{t(E=>({...E,...u}))},[]),s=r.useCallback(u=>{t(E=>E[u]?{...E,[u]:""}:E)},[]),m=r.useCallback(()=>{t({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,t]=r.useState(),f=r.useCallback(()=>t(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:t,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ae(),[u,E]=r.useState(!1),[R,_]=de(),l=r.useRef({}),k=r.useRef({}),w=r.useRef({}),N=r.useRef(()=>{}),S=r.useRef(),L=r.useCallback((n,{shouldDirty:T=!0,shouldOnChange:d=!0}={})=>{let h=n;typeof n=="function"&&(h=n(l.current)),l.current=h;let C=u;T&&(C=fe(l.current,k.current),C!==u&&E(C)),d&&N.current(l.current)},[u]),W=r.useCallback(()=>{E(!1),s();const n=w.current;Object.keys(n).forEach(T=>{const d=n[T];d(k.current[T],{shouldDirty:!1,shouldOnChange:!1})}),S.current&&S.current.reset(),_()},[s]),H=r.useCallback((n,T)=>{const d=w.current;return d[n]=T,()=>{delete d[n],delete l.current[n],delete k.current[n]}},[]),U=r.useCallback(n=>(N.current=n,()=>N.current=()=>{})),J=r.useCallback(n=>ne(n.target),[]),z=r.useCallback(n=>n?l.current[n]:l.current,[]),G=r.useCallback(()=>k.current,[]),A=r.useCallback(()=>{setTimeout(()=>S.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),V=r.useCallback(n=>{const T=ne(n.target);T?t(n.target.name,T):t(n.target.name,null)},[t]),X=r.useCallback((n,T,{shouldDirty:d=!0,shouldOnChange:h=!0}={})=>{const C=w.current;switch(typeof n){case"string":{const O=C[n];if(!O)throw new Error(`${n} is uncontrolled, please use Controller for it!`);O(T,{shouldDirty:d,shouldOnChange:h}),h&&A()}break;case"object":Object.entries(n).forEach(([O,B])=>{const I=C[O];if(!I)throw new Error(`${O} is uncontrolled, please use Controller for it!`);I(B,{shouldDirty:d,shouldOnChange:h})}),h&&A();default:return}},[A]),D=r.useCallback(()=>{const n=Object.fromEntries(new FormData(S.current)),T=w.current;return Object.keys(T).map(d=>{n[d]=l.current[d]}),o.forEach(d=>n.hasOwnProperty(d)&&(n[d]=+n[d])),n},[]),Y=r.useMemo(()=>({setValue:X,instantChange:A,getDefaultValues:G,getFormState:z,setFormState:L,changeError:t,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:D,checkValidity:V,getFieldValidity:J,registerOnchange:U,reload:_,reset:W}),[X,A,G,z,L,t,b,c,D,J,V,U,_,W]);return r.useEffect(()=>{if(S.current){const n=D();k.current=n,l.current=n}return()=>{k.current={},l.current={},E(!1),s()}},[R]),{ref:S,lastReloadedAt:R,isDirty:u,isError:m,errors:f,numberFields:o,subscribe:H,actions:Y}};g.Controller=ie,g.Form=ue,g.useForm=Ee,g.useValidateForm=ae,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
22
|
+
<%s key={someKey} {...props} />`,p,v,P,v),I[v+p]=!0)}if(v=null,i!==void 0&&(f(i),v=""+i),m(a)&&(f(a.key),v=""+a.key),"key"in a){i={};for(var K in a)K!=="key"&&(i[K]=a[K])}else i=a;return v&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,v,y,j,c(),i,Z,Q)}function l(e){typeof e=="object"&&e!==null&&e.$$typeof===w&&e._store&&(e._store.validated=1)}var k=r,w=Symbol.for("react.transitional.element"),N=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),L=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),H=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),z=Symbol.for("react.suspense"),G=Symbol.for("react.suspense_list"),A=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),Y=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,n=Object.prototype.hasOwnProperty,T=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var h,C={},O=k["react-stack-bottom-frame"].bind(k,s)(),B=d(b(s)),I={};x.Fragment=S,x.jsx=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!1,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)},x.jsxs=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!0,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)}}()),x}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?M.exports=oe():M.exports=se()),M.exports}var te=ce();const re=r.createContext({}),le=()=>r.useContext(re),ue=({id:o,form:t,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:u=()=>{},numberFields:E=[],className:R,..._})=>(r.useEffect(()=>t.actions.registerOnchange(u),[u]),te.jsx(re.Provider,{value:t,children:te.jsx("form",{id:o,ref:t==null?void 0:t.ref,action:b,method:f,className:R,onSubmit:l=>{f||l.preventDefault();const k=t.actions.loadFormValues();s(k)},onInput:l=>{if(l.target.tagName==="FORM"){const k=t.actions.loadFormValues();t.actions.setFormState(k)}else m(l)},onChange:()=>{const l=t.actions.loadFormValues();t.actions.setFormState(l)},onReset:l=>{t&&(l.preventDefault(),t.actions.reset())},..._,children:c},t==null?void 0:t.lastReloadedAt)})),ie=({name:o,defaultValue:t,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:u})=>null})=>{const[b,c]=r.useState(t),s=le(),m=r.useRef(),u=r.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(_=>({..._,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return r.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:t}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:_=!0,shouldOnChange:l=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:_,shouldOnChange:l}),m.current&&typeof m.current.dispatchEvent=="function"&&l&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:t,value:b,setValue:u})},fe=(o,t)=>{let f=!1;return Object.keys(t).forEach(b=>{if(!(b in o)||f)return;const c=t[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},ne=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ae=()=>{const[o,t]=r.useState({}),f=r.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=r.useCallback((u,E)=>{t(R=>R[u]===E?R:{...R,[u]:E})},[]),c=r.useCallback(u=>{t(E=>({...E,...u}))},[]),s=r.useCallback(u=>{t(E=>E[u]?{...E,[u]:""}:E)},[]),m=r.useCallback(()=>{t({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,t]=r.useState(),f=r.useCallback(()=>t(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:t,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ae(),[u,E]=r.useState(!1),[R,_]=de(),l=r.useRef({}),k=r.useRef({}),w=r.useRef({}),N=r.useRef(()=>{}),S=r.useRef(),L=r.useCallback((n,{shouldDirty:T=!0,shouldOnChange:d=!0}={})=>{let h=n;typeof n=="function"&&(h=n(l.current)),l.current=h;let C=u;T&&(C=fe(l.current,k.current),C!==u&&E(C)),d&&N.current(l.current)},[u]),W=r.useCallback(()=>{E(!1),s();const n=w.current;Object.keys(n).forEach(T=>{const d=n[T];d(k.current[T],{shouldDirty:!1,shouldOnChange:!1})}),S.current&&S.current.reset(),_()},[s]),H=r.useCallback((n,T)=>{const d=w.current;return d[n]=T,()=>{delete d[n],delete l.current[n],delete k.current[n]}},[]),U=r.useCallback(n=>(N.current=n,()=>N.current=()=>{})),J=r.useCallback(n=>ne(n.target),[]),z=r.useCallback(n=>n?l.current[n]:l.current,[]),G=r.useCallback(()=>k.current,[]),A=r.useCallback(()=>{setTimeout(()=>S.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),V=r.useCallback(n=>{const T=ne(n.target);T?t(n.target.name,T):t(n.target.name,null)},[t]),X=r.useCallback((n,T,{shouldDirty:d=!0,shouldOnChange:h=!0}={})=>{const C=w.current;switch(typeof n){case"string":{const O=C[n];if(!O)throw new Error(`${n} is uncontrolled, please use Controller for it!`);O(T,{shouldDirty:d,shouldOnChange:h}),h&&A()}break;case"object":Object.entries(n).forEach(([O,B])=>{const I=C[O];if(!I)throw new Error(`${O} is uncontrolled, please use Controller for it!`);I(B,{shouldDirty:d,shouldOnChange:h})}),h&&A();default:return}},[A]),D=r.useCallback(()=>{const n=Object.fromEntries(new FormData(S.current)),T=w.current;return Object.keys(T).map(d=>{n[d]=l.current[d]}),o.forEach(d=>n.hasOwnProperty(d)&&(n[d]=+n[d])),n},[]),Y=r.useMemo(()=>({setValue:X,instantChange:A,getDefaultValues:G,getFormState:z,setFormState:L,changeError:t,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:D,checkValidity:V,getFieldValidity:J,registerOnchange:U,reload:_,reset:W}),[X,A,G,z,L,t,b,c,D,J,V,U,_,W]);return r.useEffect(()=>{if(S.current){const n=D();k.current=n,l.current=n}return()=>{k.current={},l.current={},E(!1),s()}},[R]),{ref:S,lastReloadedAt:R,isDirty:u,isError:m,errors:f,numberFields:o,subscribe:H,actions:Y}};g.Controller=ie,g.Form=ue,g.useForm=Ee,g.useValidateForm=ae,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|