react-simple-formkit 1.0.3 → 1.0.5
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.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react");var J={exports:{}},V={};/**
|
|
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 K;function
|
|
9
|
+
*/var K;function le(){if(K)return V;K=1;var o=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function b(i,c,s){var m=null;if(s!==void 0&&(m=""+s),c.key!==void 0&&(m=""+c.key),"key"in c){s={};for(var u in c)u!=="key"&&(s[u]=c[u])}else s=c;return c=s.ref,{$$typeof:o,type:i,key:m,ref:c!==void 0?c:null,props:s}}return V.Fragment=a,V.jsx=b,V.jsxs=b,V}var D={};/**
|
|
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 ee;function
|
|
17
|
+
*/var ee;function ie(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===P?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case h:return"Fragment";case I:return"Profiler";case Y:return"StrictMode";case L:return"Suspense";case W:return"SuspenseList";case U: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 w:return"Portal";case $:return(e.displayName||"Context")+".Provider";case z:return(e._context.displayName||"Context")+".Consumer";case M:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case j:return r=e.displayName||null,r!==null?r:o(e.type)||"Memo";case x:r=e._payload,e=e._init;try{return o(e(r))}catch{}}return null}function a(e){return""+e}function b(e){try{a(e);var r=!1}catch{r=!0}if(r){r=console;var l=r.error,k=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",k),a(e)}}function i(e){if(e===h)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===x)return"<...>";try{var r=o(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function c(){var e=A.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function m(e){if(t.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function u(e,r){function l(){S||(S=!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)",r))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function R(){var e=o(this.type);return O[e]||(O[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 E(e,r,l,k,C,g,G,X){return l=g.ref,e={$$typeof:y,type:e,key:r,props:g,_owner:C},(l!==void 0?l:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):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:G}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function T(e,r,l,k,C,g,G,X){var _=r.children;if(_!==void 0)if(k)if(v(_)){for(k=0;k<_.length;k++)f(_[k]);Object.freeze&&Object.freeze(_)}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 f(_);if(t.call(r,"key")){_=o(e);var F=Object.keys(r).filter(function(ue){return ue!=="key"});k=0<F.length?"{key: someKey, "+F.join(": ..., ")+": ...}":"{key: someKey}",Q[_+k]||(F=0<F.length?"{"+F.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} />`,k,
|
|
22
|
+
<%s key={someKey} {...props} />`,k,_,F,_),Q[_+k]=!0)}if(_=null,l!==void 0&&(b(l),_=""+l),m(r)&&(b(r.key),_=""+r.key),"key"in r){l={};for(var B in r)B!=="key"&&(l[B]=r[B])}else l=r;return _&&u(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,_,g,C,c(),l,G,X)}function f(e){typeof e=="object"&&e!==null&&e.$$typeof===y&&e._store&&(e._store.validated=1)}var p=n,y=Symbol.for("react.transitional.element"),w=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),Y=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),z=Symbol.for("react.consumer"),$=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),L=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),U=Symbol.for("react.activity"),P=Symbol.for("react.client.reference"),A=p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,t=Object.prototype.hasOwnProperty,v=Array.isArray,d=console.createTask?console.createTask:function(){return null};p={"react-stack-bottom-frame":function(e){return e()}};var S,O={},q=p["react-stack-bottom-frame"].bind(p,s)(),N=d(i(s)),Q={};D.Fragment=h,D.jsx=function(e,r,l,k,C){var g=1e4>A.recentlyCreatedOwnerStacks++;return T(e,r,l,!1,k,C,g?Error("react-stack-top-frame"):q,g?d(i(e)):N)},D.jsxs=function(e,r,l,k,C){var g=1e4>A.recentlyCreatedOwnerStacks++;return T(e,r,l,!0,k,C,g?Error("react-stack-top-frame"):q,g?d(i(e)):N)}}()),D}var re;function fe(){return re||(re=1,process.env.NODE_ENV==="production"?J.exports=le():J.exports=ie()),J.exports}var te=fe();const ae=n.createContext({}),de=()=>n.useContext(ae),be=(o,a)=>{let b=!1;return Object.keys(a).forEach(i=>{if(!(i in o)||b)return;const c=a[i],s=o[i];(typeof c=="object"||c!==s)&&(b=!0)}),b},ne=o=>!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage,oe=({id:o,form:a,method:b,action:i,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:u=()=>{},numberFields:R=[],className:E,...T})=>(n.useEffect(()=>a.actions.registerOnchange(u),[u]),te.jsx(ae.Provider,{value:a,children:te.jsx("form",{ref:a==null?void 0:a.ref,action:i,className:E,onSubmit:f=>{b||f.preventDefault();const p=a.actions.loadFormValues();s(p)},onInput:f=>{if(f.target.tagName==="FORM"){const p=a.actions.loadFormValues();a.actions.setFormState(p)}else m(f)},onChange:()=>{const f=a.actions.loadFormValues();a.actions.setFormState(f)},...T,children:c})})),se=({name:o,defaultValue:a,render:b=({ref:i,name:c,defaultValue:s,value:m,setValue:u})=>null})=>{const[i,c]=n.useState(a),s=de(),m=n.useRef(),u=n.useCallback((R,{shouldDirty:E=!1}={})=>{s.actions.setFormState(T=>({...T,[o]:R}),{shouldDirty:E}),c(R)},[c,s.actions.setFormState]);return n.useEffect(()=>(s.actions.setFormState(E=>({...E,[o]:a}),{shouldDirty:!1}),s.subscribe(o,(E,{shouldDirty:T=!0})=>{c(E),s.actions.setFormState(f=>({...f,[o]:E}),{shouldDirty:T}),m.current&&typeof m.current.dispatchEvent=="function"&&m.current.dispatchEvent(new Event("change"))})),[]),b({ref:m,name:o,defaultValue:a,value:i,setValue:u})},Z=()=>{const[o,a]=n.useState({}),b=n.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),i=n.useCallback((u,R)=>{a(E=>E[u]===R?E:{...E,[u]:R})},[]),c=n.useCallback(u=>{a(R=>({...R,...u}))},[]),s=n.useCallback(u=>{a(R=>R[u]?{...R,[u]:""}:R)},[]),m=n.useCallback(()=>{a({})},[]);return{isError:b,errors:o,changeError:i,changeErrors:c,clearError:s,clearErrors:m}},H={defaultValues:{},numberFields:[]},ce=(o=H)=>{const{defaultValues:a=H.defaultValues,numberFields:b=H.numberFields}=o,{changeError:i,errors:c,changeErrors:s,clearError:m,clearErrors:u,isError:R}=Z(),[E,T]=n.useState(!1),f=n.useRef({}),p=n.useRef(a),y=n.useRef({}),w=n.useRef(()=>{}),h=n.useRef(),Y=n.useCallback((t,{shouldDirty:v=!0}={})=>{let d=t;typeof t=="function"&&(d=t(f.current)),f.current=d;let S=E;v&&(S=be(f.current,p.current),S!==E&&T(S)),w.current(f.current)},[E]),I=n.useCallback(()=>{T(!1),u();const t=y.current;Object.values(t).forEach(d=>d("")),h.current.reset(),f.current=p.current},[u]),z=n.useCallback((t,v)=>{const d=y.current;return d[t]=v,()=>d[t]=null},[]),$=n.useCallback(t=>(w.current=t,()=>w.current=()=>{})),M=n.useCallback(t=>ne(t.target),[]),L=n.useCallback(t=>t?f.current[t]:f.current,[]),W=n.useCallback(()=>p.current,[]),j=n.useCallback(()=>{setTimeout(()=>h.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),x=n.useCallback(t=>{const v=ne(t.target);v?i(t.target.name,v):i(t.target.name,null)},[i]),U=n.useCallback((t,v,{shouldDirty:d=!0}={})=>{const S=y.current;if(typeof t=="string"){const O=S[t];if(!O)throw new Error(`${t} is uncontrolled, please use Controller for it!`);O(v,{shouldDirty:d}),j()}typeof t=="object"&&(Object.entries(t).forEach(([O,q])=>{const N=S[O];if(!N)throw new Error(`${O} is uncontrolled, please use Controller for it!`);N(q,{shouldDirty:d})}),j())},[j]),P=n.useCallback(()=>{const t=Object.fromEntries(new FormData(h.current)),v=y.current;return Object.keys(v).map(d=>{t[d]=f.current[d]}),b.forEach(d=>t.hasOwnProperty(d)&&(t[d]=+t[d])),t},[]),A=n.useMemo(()=>({setValue:U,instantChange:j,getDefaultValues:W,getFormState:L,setFormState:Y,changeError:i,changeErrors:s,clearError:m,clearErrors:u,loadFormValues:P,checkValidity:x,getFieldValidity:M,registerOnchange:$,reset:I}),[U,j,W,L,Y,i,s,m,P,M,x,$,I]);return n.useEffect(()=>{if(h.current){const t=P();p.current={...t,...a},f.current={...t,...a}}},[]),{ref:h,isDirty:E,isError:R,errors:c,numberFields:b,subscribe:z,actions:A}},Ee={Form:oe,Controller:se,useForm:ce,useValidateForm:Z};exports.Controller=se;exports.Form=oe;exports.default=Ee;exports.useForm=ce;exports.useValidateForm=Z;
|
|
@@ -1,113 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
const de = (o, n) => {
|
|
3
|
-
let d = !1;
|
|
4
|
-
return Object.keys(n).forEach((l) => {
|
|
5
|
-
if (!(l in o) || d) return;
|
|
6
|
-
const s = n[l], a = o[l];
|
|
7
|
-
(typeof s == "object" || s !== a) && (d = !0);
|
|
8
|
-
}), d;
|
|
9
|
-
}, re = (o) => !o || typeof o.checkValidity != "function" || o.checkValidity() ? null : o.validationMessage, Ee = () => {
|
|
10
|
-
const [o, n] = Q({}), d = se(() => Object.values(o).filter(Boolean).length > 0, [o]), l = _((c, b) => {
|
|
11
|
-
n((E) => E[c] === b ? E : { ...E, [c]: b });
|
|
12
|
-
}, []), s = _((c) => {
|
|
13
|
-
n((b) => ({ ...b, ...c }));
|
|
14
|
-
}, []), a = _((c) => {
|
|
15
|
-
n((b) => b[c] ? { ...b, [c]: "" } : b);
|
|
16
|
-
}, []), m = _(() => {
|
|
17
|
-
n({});
|
|
18
|
-
}, []);
|
|
19
|
-
return { isError: d, errors: o, changeError: l, changeErrors: s, clearError: a, clearErrors: m };
|
|
20
|
-
}, Z = {
|
|
21
|
-
defaultValues: {},
|
|
22
|
-
numberFields: []
|
|
23
|
-
}, ve = (o = Z) => {
|
|
24
|
-
const { defaultValues: n = Z.defaultValues, numberFields: d = Z.numberFields } = o, { changeError: l, errors: s, changeErrors: a, clearError: m, clearErrors: c, isError: b } = Ee(), [E, g] = Q(!1), i = A({}), v = A(n), j = A({}), F = A(() => {
|
|
25
|
-
}), O = A(), I = _(
|
|
26
|
-
(t, { shouldDirty: T = !0 } = {}) => {
|
|
27
|
-
let f = t;
|
|
28
|
-
typeof t == "function" && (f = t(i.current)), i.current = f;
|
|
29
|
-
let h = E;
|
|
30
|
-
T && (h = de(i.current, v.current), h !== E && g(h)), F.current({ formState: i.current, isDirty: h });
|
|
31
|
-
},
|
|
32
|
-
[E]
|
|
33
|
-
), $ = _(() => {
|
|
34
|
-
g(!1), c();
|
|
35
|
-
const t = j.current;
|
|
36
|
-
Object.values(t).forEach((f) => f("")), O.current.reset(), i.current = v.current;
|
|
37
|
-
}, [c]), G = _((t, T) => {
|
|
38
|
-
const f = j.current;
|
|
39
|
-
return f[t] = T, () => f[t] = null;
|
|
40
|
-
}, []), M = _((t) => (F.current = t, () => F.current = () => {
|
|
41
|
-
})), L = _((t) => re(t.target), []), W = _((t) => t ? i.current[t] : i.current, []), U = _(() => v.current, []), w = _(() => {
|
|
42
|
-
setTimeout(() => O.current.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
43
|
-
}, []), P = _(
|
|
44
|
-
(t) => {
|
|
45
|
-
const T = re(t.target);
|
|
46
|
-
T ? l(t.target.name, T) : l(t.target.name, null);
|
|
47
|
-
},
|
|
48
|
-
[l]
|
|
49
|
-
), q = _(
|
|
50
|
-
(t, T, { shouldDirty: f = !0 } = {}) => {
|
|
51
|
-
const h = j.current;
|
|
52
|
-
if (typeof t == "string") {
|
|
53
|
-
const S = h[t];
|
|
54
|
-
if (!S)
|
|
55
|
-
throw new Error(`${t} is uncontrolled, please use Controller for it!`);
|
|
56
|
-
S(T, { shouldDirty: f }), w();
|
|
57
|
-
}
|
|
58
|
-
typeof t == "object" && (Object.entries(t).forEach(([S, J]) => {
|
|
59
|
-
const V = h[S];
|
|
60
|
-
if (!V)
|
|
61
|
-
throw new Error(`${S} is uncontrolled, please use Controller for it!`);
|
|
62
|
-
V(J, { shouldDirty: f });
|
|
63
|
-
}), w());
|
|
64
|
-
},
|
|
65
|
-
[w]
|
|
66
|
-
), C = _(() => {
|
|
67
|
-
const t = Object.fromEntries(new FormData(O.current)), T = j.current;
|
|
68
|
-
return Object.keys(T).map((f) => {
|
|
69
|
-
t[f] = i.current[f];
|
|
70
|
-
}), d.forEach((f) => t.hasOwnProperty(f) && (t[f] = +t[f])), t;
|
|
71
|
-
}, []), N = se(
|
|
72
|
-
() => ({
|
|
73
|
-
setValue: q,
|
|
74
|
-
instantChange: w,
|
|
75
|
-
getDefaultValues: U,
|
|
76
|
-
getFormState: W,
|
|
77
|
-
setFormState: I,
|
|
78
|
-
changeError: l,
|
|
79
|
-
changeErrors: a,
|
|
80
|
-
clearError: m,
|
|
81
|
-
clearErrors: c,
|
|
82
|
-
loadFormValues: C,
|
|
83
|
-
checkValidity: P,
|
|
84
|
-
getFieldValidity: L,
|
|
85
|
-
registerOnchange: M,
|
|
86
|
-
reset: $
|
|
87
|
-
}),
|
|
88
|
-
[
|
|
89
|
-
q,
|
|
90
|
-
w,
|
|
91
|
-
U,
|
|
92
|
-
W,
|
|
93
|
-
I,
|
|
94
|
-
l,
|
|
95
|
-
a,
|
|
96
|
-
m,
|
|
97
|
-
C,
|
|
98
|
-
L,
|
|
99
|
-
P,
|
|
100
|
-
M,
|
|
101
|
-
$
|
|
102
|
-
]
|
|
103
|
-
);
|
|
104
|
-
return K(() => {
|
|
105
|
-
if (O.current) {
|
|
106
|
-
const t = C();
|
|
107
|
-
v.current = { ...t, ...n }, i.current = { ...t, ...n };
|
|
108
|
-
}
|
|
109
|
-
}, []), { ref: O, isDirty: E, isError: b, errors: s, numberFields: d, subscribe: G, actions: N };
|
|
110
|
-
};
|
|
1
|
+
import ie, { createContext as fe, useContext as de, useEffect as Q, useState as K, useRef as A, useCallback as _, useMemo as se } from "react";
|
|
111
2
|
var z = { exports: {} }, D = {};
|
|
112
3
|
/**
|
|
113
4
|
* @license React
|
|
@@ -118,10 +9,10 @@ var z = { exports: {} }, D = {};
|
|
|
118
9
|
* This source code is licensed under the MIT license found in the
|
|
119
10
|
* LICENSE file in the root directory of this source tree.
|
|
120
11
|
*/
|
|
121
|
-
var
|
|
122
|
-
function
|
|
123
|
-
if (
|
|
124
|
-
|
|
12
|
+
var re;
|
|
13
|
+
function Ee() {
|
|
14
|
+
if (re) return D;
|
|
15
|
+
re = 1;
|
|
125
16
|
var o = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
126
17
|
function d(l, s, a) {
|
|
127
18
|
var m = null;
|
|
@@ -150,16 +41,16 @@ var Y = {};
|
|
|
150
41
|
* This source code is licensed under the MIT license found in the
|
|
151
42
|
* LICENSE file in the root directory of this source tree.
|
|
152
43
|
*/
|
|
153
|
-
var
|
|
154
|
-
function
|
|
155
|
-
return
|
|
44
|
+
var te;
|
|
45
|
+
function me() {
|
|
46
|
+
return te || (te = 1, process.env.NODE_ENV !== "production" && function() {
|
|
156
47
|
function o(e) {
|
|
157
48
|
if (e == null) return null;
|
|
158
49
|
if (typeof e == "function")
|
|
159
50
|
return e.$$typeof === C ? null : e.displayName || e.name || null;
|
|
160
51
|
if (typeof e == "string") return e;
|
|
161
52
|
switch (e) {
|
|
162
|
-
case
|
|
53
|
+
case k:
|
|
163
54
|
return "Fragment";
|
|
164
55
|
case $:
|
|
165
56
|
return "Profiler";
|
|
@@ -185,7 +76,7 @@ function be() {
|
|
|
185
76
|
case L:
|
|
186
77
|
var r = e.render;
|
|
187
78
|
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
188
|
-
case
|
|
79
|
+
case x:
|
|
189
80
|
return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
|
|
190
81
|
case P:
|
|
191
82
|
r = e._payload, e = e._init;
|
|
@@ -217,7 +108,7 @@ function be() {
|
|
|
217
108
|
}
|
|
218
109
|
}
|
|
219
110
|
function l(e) {
|
|
220
|
-
if (e ===
|
|
111
|
+
if (e === k) return "<>";
|
|
221
112
|
if (typeof e == "object" && e !== null && e.$$typeof === P)
|
|
222
113
|
return "<...>";
|
|
223
114
|
try {
|
|
@@ -243,7 +134,7 @@ function be() {
|
|
|
243
134
|
}
|
|
244
135
|
function c(e, r) {
|
|
245
136
|
function u() {
|
|
246
|
-
|
|
137
|
+
O || (O = !0, console.error(
|
|
247
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)",
|
|
248
139
|
r
|
|
249
140
|
));
|
|
@@ -259,12 +150,12 @@ function be() {
|
|
|
259
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."
|
|
260
151
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
261
152
|
}
|
|
262
|
-
function E(e, r, u, R, y,
|
|
263
|
-
return u =
|
|
153
|
+
function E(e, r, u, R, y, h, X, B) {
|
|
154
|
+
return u = h.ref, e = {
|
|
264
155
|
$$typeof: j,
|
|
265
156
|
type: e,
|
|
266
157
|
key: r,
|
|
267
|
-
props:
|
|
158
|
+
props: h,
|
|
268
159
|
_owner: y
|
|
269
160
|
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
270
161
|
enumerable: !1,
|
|
@@ -291,7 +182,7 @@ function be() {
|
|
|
291
182
|
value: B
|
|
292
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
293
184
|
}
|
|
294
|
-
function g(e, r, u, R, y,
|
|
185
|
+
function g(e, r, u, R, y, h, X, B) {
|
|
295
186
|
var p = r.children;
|
|
296
187
|
if (p !== void 0)
|
|
297
188
|
if (R)
|
|
@@ -306,10 +197,10 @@ function be() {
|
|
|
306
197
|
else i(p);
|
|
307
198
|
if (t.call(r, "key")) {
|
|
308
199
|
p = o(e);
|
|
309
|
-
var
|
|
310
|
-
return
|
|
200
|
+
var w = Object.keys(r).filter(function(le) {
|
|
201
|
+
return le !== "key";
|
|
311
202
|
});
|
|
312
|
-
R = 0 <
|
|
203
|
+
R = 0 < w.length ? "{key: someKey, " + w.join(": ..., ") + ": ...}" : "{key: someKey}", ee[p + R] || (w = 0 < w.length ? "{" + w.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
313
204
|
`A props object containing a "key" prop is being spread into JSX:
|
|
314
205
|
let props = %s;
|
|
315
206
|
<%s {...props} />
|
|
@@ -318,7 +209,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
318
209
|
<%s key={someKey} {...props} />`,
|
|
319
210
|
R,
|
|
320
211
|
p,
|
|
321
|
-
|
|
212
|
+
w,
|
|
322
213
|
p
|
|
323
214
|
), ee[p + R] = !0);
|
|
324
215
|
}
|
|
@@ -333,7 +224,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
333
224
|
), E(
|
|
334
225
|
e,
|
|
335
226
|
p,
|
|
336
|
-
|
|
227
|
+
h,
|
|
337
228
|
y,
|
|
338
229
|
s(),
|
|
339
230
|
u,
|
|
@@ -344,7 +235,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
344
235
|
function i(e) {
|
|
345
236
|
typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._store.validated = 1);
|
|
346
237
|
}
|
|
347
|
-
var v =
|
|
238
|
+
var v = ie, j = Symbol.for("react.transitional.element"), F = Symbol.for("react.portal"), k = 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"), x = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), q = Symbol.for("react.activity"), C = Symbol.for("react.client.reference"), N = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, t = Object.prototype.hasOwnProperty, T = Array.isArray, f = console.createTask ? console.createTask : function() {
|
|
348
239
|
return null;
|
|
349
240
|
};
|
|
350
241
|
v = {
|
|
@@ -352,12 +243,12 @@ React keys must be passed directly to JSX without using spread:
|
|
|
352
243
|
return e();
|
|
353
244
|
}
|
|
354
245
|
};
|
|
355
|
-
var
|
|
246
|
+
var O, S = {}, J = v["react-stack-bottom-frame"].bind(
|
|
356
247
|
v,
|
|
357
248
|
a
|
|
358
249
|
)(), V = f(l(a)), ee = {};
|
|
359
|
-
Y.Fragment =
|
|
360
|
-
var
|
|
250
|
+
Y.Fragment = k, Y.jsx = function(e, r, u, R, y) {
|
|
251
|
+
var h = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
361
252
|
return g(
|
|
362
253
|
e,
|
|
363
254
|
r,
|
|
@@ -365,11 +256,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
365
256
|
!1,
|
|
366
257
|
R,
|
|
367
258
|
y,
|
|
368
|
-
|
|
369
|
-
|
|
259
|
+
h ? Error("react-stack-top-frame") : J,
|
|
260
|
+
h ? f(l(e)) : V
|
|
370
261
|
);
|
|
371
262
|
}, Y.jsxs = function(e, r, u, R, y) {
|
|
372
|
-
var
|
|
263
|
+
var h = 1e4 > N.recentlyCreatedOwnerStacks++;
|
|
373
264
|
return g(
|
|
374
265
|
e,
|
|
375
266
|
r,
|
|
@@ -377,18 +268,25 @@ React keys must be passed directly to JSX without using spread:
|
|
|
377
268
|
!0,
|
|
378
269
|
R,
|
|
379
270
|
y,
|
|
380
|
-
|
|
381
|
-
|
|
271
|
+
h ? Error("react-stack-top-frame") : J,
|
|
272
|
+
h ? f(l(e)) : V
|
|
382
273
|
);
|
|
383
274
|
};
|
|
384
275
|
}()), Y;
|
|
385
276
|
}
|
|
386
|
-
var
|
|
387
|
-
function
|
|
388
|
-
return
|
|
277
|
+
var ne;
|
|
278
|
+
function be() {
|
|
279
|
+
return ne || (ne = 1, process.env.NODE_ENV === "production" ? z.exports = Ee() : z.exports = me()), z.exports;
|
|
389
280
|
}
|
|
390
|
-
var
|
|
391
|
-
const ce =
|
|
281
|
+
var oe = be();
|
|
282
|
+
const ce = fe({}), Re = () => de(ce), pe = (o, n) => {
|
|
283
|
+
let d = !1;
|
|
284
|
+
return Object.keys(n).forEach((l) => {
|
|
285
|
+
if (!(l in o) || d) return;
|
|
286
|
+
const s = n[l], a = o[l];
|
|
287
|
+
(typeof s == "object" || s !== a) && (d = !0);
|
|
288
|
+
}), d;
|
|
289
|
+
}, ae = (o) => !o || typeof o.checkValidity != "function" || o.checkValidity() ? null : o.validationMessage, _e = ({
|
|
392
290
|
id: o,
|
|
393
291
|
form: n,
|
|
394
292
|
method: d,
|
|
@@ -403,7 +301,7 @@ const ce = ie({}), pe = () => fe(ce), Te = ({
|
|
|
403
301
|
numberFields: b = [],
|
|
404
302
|
className: E,
|
|
405
303
|
...g
|
|
406
|
-
}) => (
|
|
304
|
+
}) => (Q(() => n.actions.registerOnchange(c), [c]), /* @__PURE__ */ oe.jsx(ce.Provider, { value: n, children: /* @__PURE__ */ oe.jsx(
|
|
407
305
|
"form",
|
|
408
306
|
{
|
|
409
307
|
ref: n == null ? void 0 : n.ref,
|
|
@@ -428,20 +326,127 @@ const ce = ie({}), pe = () => fe(ce), Te = ({
|
|
|
428
326
|
...g,
|
|
429
327
|
children: s
|
|
430
328
|
}
|
|
431
|
-
) })),
|
|
432
|
-
const [l, s] =
|
|
329
|
+
) })), ve = ({ name: o, defaultValue: n, render: d = ({ ref: l, name: s, defaultValue: a, value: m, setValue: c }) => null }) => {
|
|
330
|
+
const [l, s] = K(n), a = Re(), m = A(), c = _(
|
|
433
331
|
(b, { shouldDirty: E = !1 } = {}) => {
|
|
434
332
|
a.actions.setFormState((g) => ({ ...g, [o]: b }), { shouldDirty: E }), s(b);
|
|
435
333
|
},
|
|
436
334
|
[s, a.actions.setFormState]
|
|
437
335
|
);
|
|
438
|
-
return
|
|
336
|
+
return Q(() => (a.actions.setFormState((E) => ({ ...E, [o]: n }), { shouldDirty: !1 }), a.subscribe(o, (E, { shouldDirty: g = !0 }) => {
|
|
439
337
|
s(E), a.actions.setFormState((i) => ({ ...i, [o]: E }), { shouldDirty: g }), m.current && typeof m.current.dispatchEvent == "function" && m.current.dispatchEvent(new Event("change"));
|
|
440
338
|
})), []), d({ ref: m, name: o, defaultValue: n, value: l, setValue: c });
|
|
339
|
+
}, ue = () => {
|
|
340
|
+
const [o, n] = K({}), d = se(() => Object.values(o).filter(Boolean).length > 0, [o]), l = _((c, b) => {
|
|
341
|
+
n((E) => E[c] === b ? E : { ...E, [c]: b });
|
|
342
|
+
}, []), s = _((c) => {
|
|
343
|
+
n((b) => ({ ...b, ...c }));
|
|
344
|
+
}, []), a = _((c) => {
|
|
345
|
+
n((b) => b[c] ? { ...b, [c]: "" } : b);
|
|
346
|
+
}, []), m = _(() => {
|
|
347
|
+
n({});
|
|
348
|
+
}, []);
|
|
349
|
+
return { isError: d, errors: o, changeError: l, changeErrors: s, clearError: a, clearErrors: m };
|
|
350
|
+
}, Z = {
|
|
351
|
+
defaultValues: {},
|
|
352
|
+
numberFields: []
|
|
353
|
+
}, Te = (o = Z) => {
|
|
354
|
+
const { defaultValues: n = Z.defaultValues, numberFields: d = Z.numberFields } = o, { changeError: l, errors: s, changeErrors: a, clearError: m, clearErrors: c, isError: b } = ue(), [E, g] = K(!1), i = A({}), v = A(n), j = A({}), F = A(() => {
|
|
355
|
+
}), k = A(), I = _(
|
|
356
|
+
(t, { shouldDirty: T = !0 } = {}) => {
|
|
357
|
+
let f = t;
|
|
358
|
+
typeof t == "function" && (f = t(i.current)), i.current = f;
|
|
359
|
+
let O = E;
|
|
360
|
+
T && (O = pe(i.current, v.current), O !== E && g(O)), F.current(i.current);
|
|
361
|
+
},
|
|
362
|
+
[E]
|
|
363
|
+
), $ = _(() => {
|
|
364
|
+
g(!1), c();
|
|
365
|
+
const t = j.current;
|
|
366
|
+
Object.values(t).forEach((f) => f("")), k.current.reset(), i.current = v.current;
|
|
367
|
+
}, [c]), G = _((t, T) => {
|
|
368
|
+
const f = j.current;
|
|
369
|
+
return f[t] = T, () => f[t] = null;
|
|
370
|
+
}, []), M = _((t) => (F.current = t, () => F.current = () => {
|
|
371
|
+
})), L = _((t) => ae(t.target), []), W = _((t) => t ? i.current[t] : i.current, []), U = _(() => v.current, []), x = _(() => {
|
|
372
|
+
setTimeout(() => k.current.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
373
|
+
}, []), P = _(
|
|
374
|
+
(t) => {
|
|
375
|
+
const T = ae(t.target);
|
|
376
|
+
T ? l(t.target.name, T) : l(t.target.name, null);
|
|
377
|
+
},
|
|
378
|
+
[l]
|
|
379
|
+
), q = _(
|
|
380
|
+
(t, T, { shouldDirty: f = !0 } = {}) => {
|
|
381
|
+
const O = j.current;
|
|
382
|
+
if (typeof t == "string") {
|
|
383
|
+
const S = O[t];
|
|
384
|
+
if (!S)
|
|
385
|
+
throw new Error(`${t} is uncontrolled, please use Controller for it!`);
|
|
386
|
+
S(T, { shouldDirty: f }), x();
|
|
387
|
+
}
|
|
388
|
+
typeof t == "object" && (Object.entries(t).forEach(([S, J]) => {
|
|
389
|
+
const V = O[S];
|
|
390
|
+
if (!V)
|
|
391
|
+
throw new Error(`${S} is uncontrolled, please use Controller for it!`);
|
|
392
|
+
V(J, { shouldDirty: f });
|
|
393
|
+
}), x());
|
|
394
|
+
},
|
|
395
|
+
[x]
|
|
396
|
+
), C = _(() => {
|
|
397
|
+
const t = Object.fromEntries(new FormData(k.current)), T = j.current;
|
|
398
|
+
return Object.keys(T).map((f) => {
|
|
399
|
+
t[f] = i.current[f];
|
|
400
|
+
}), d.forEach((f) => t.hasOwnProperty(f) && (t[f] = +t[f])), t;
|
|
401
|
+
}, []), N = se(
|
|
402
|
+
() => ({
|
|
403
|
+
setValue: q,
|
|
404
|
+
instantChange: x,
|
|
405
|
+
getDefaultValues: U,
|
|
406
|
+
getFormState: W,
|
|
407
|
+
setFormState: I,
|
|
408
|
+
changeError: l,
|
|
409
|
+
changeErrors: a,
|
|
410
|
+
clearError: m,
|
|
411
|
+
clearErrors: c,
|
|
412
|
+
loadFormValues: C,
|
|
413
|
+
checkValidity: P,
|
|
414
|
+
getFieldValidity: L,
|
|
415
|
+
registerOnchange: M,
|
|
416
|
+
reset: $
|
|
417
|
+
}),
|
|
418
|
+
[
|
|
419
|
+
q,
|
|
420
|
+
x,
|
|
421
|
+
U,
|
|
422
|
+
W,
|
|
423
|
+
I,
|
|
424
|
+
l,
|
|
425
|
+
a,
|
|
426
|
+
m,
|
|
427
|
+
C,
|
|
428
|
+
L,
|
|
429
|
+
P,
|
|
430
|
+
M,
|
|
431
|
+
$
|
|
432
|
+
]
|
|
433
|
+
);
|
|
434
|
+
return Q(() => {
|
|
435
|
+
if (k.current) {
|
|
436
|
+
const t = C();
|
|
437
|
+
v.current = { ...t, ...n }, i.current = { ...t, ...n };
|
|
438
|
+
}
|
|
439
|
+
}, []), { ref: k, isDirty: E, isError: b, errors: s, numberFields: d, subscribe: G, actions: N };
|
|
440
|
+
}, he = {
|
|
441
|
+
Form: _e,
|
|
442
|
+
Controller: ve,
|
|
443
|
+
useForm: Te,
|
|
444
|
+
useValidateForm: ue
|
|
441
445
|
};
|
|
442
446
|
export {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
ve as Controller,
|
|
448
|
+
_e as Form,
|
|
449
|
+
he as default,
|
|
450
|
+
Te as useForm,
|
|
451
|
+
ue as useValidateForm
|
|
447
452
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(T,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(T=typeof globalThis<"u"?globalThis:T||self,r(T.Name={},T.React))})(this,function(T,r){"use strict";var I={exports:{}},P={};/**
|
|
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 $;function le(){if($)return P;$=1;var o=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function b(i,c,s){var E=null;if(s!==void 0&&(E=""+s),c.key!==void 0&&(E=""+c.key),"key"in c){s={};for(var u in c)u!=="key"&&(s[u]=c[u])}else s=c;return c=s.ref,{$$typeof:o,type:i,key:E,ref:c!==void 0?c:null,props:s}}return P.Fragment=a,P.jsx=b,P.jsxs=b,P}var A={};/**
|
|
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 ee;function ie(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===V?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case L:return"Profiler";case M:return"StrictMode";case J:return"Suspense";case z:return"SuspenseList";case G: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 x:return"Portal";case W:return(e.displayName||"Context")+".Provider";case Z:return(e._context.displayName||"Context")+".Consumer";case U:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case F:return t=e.displayName||null,t!==null?t:o(e.type)||"Memo";case N:t=e._payload,e=e._init;try{return o(e(t))}catch{}}return null}function a(e){return""+e}function b(e){try{a(e);var t=!1}catch{t=!0}if(t){t=console;var l=t.error,k=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",k),a(e)}}function i(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===N)return"<...>";try{var t=o(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function c(){var e=D.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function E(e){if(n.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function u(e,t){function l(){O||(O=!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)",t))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function R(){var e=o(this.type);return C[e]||(C[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 m(e,t,l,k,y,g,Q,K){return l=g.ref,e={$$typeof:j,type:e,key:t,props:g,_owner:y},(l!==void 0?l:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):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:Q}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function h(e,t,l,k,y,g,Q,K){var p=t.children;if(p!==void 0)if(k)if(v(p)){for(k=0;k<p.length;k++)f(p[k]);Object.freeze&&Object.freeze(p)}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 f(p);if(n.call(t,"key")){p=o(e);var w=Object.keys(t).filter(function(Ee){return Ee!=="key"});k=0<w.length?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}",ue[p+k]||(w=0<w.length?"{"+w.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} />`,k,p,w,p),
|
|
22
|
+
<%s key={someKey} {...props} />`,k,p,w,p),ue[p+k]=!0)}if(p=null,l!==void 0&&(b(l),p=""+l),E(t)&&(b(t.key),p=""+t.key),"key"in t){l={};for(var q in t)q!=="key"&&(l[q]=t[q])}else l=t;return p&&u(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),m(e,p,g,y,c(),l,Q,K)}function f(e){typeof e=="object"&&e!==null&&e.$$typeof===j&&e._store&&(e._store.validated=1)}var _=r,j=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),M=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),Z=Symbol.for("react.consumer"),W=Symbol.for("react.context"),U=Symbol.for("react.forward_ref"),J=Symbol.for("react.suspense"),z=Symbol.for("react.suspense_list"),F=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),V=Symbol.for("react.client.reference"),D=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,n=Object.prototype.hasOwnProperty,v=Array.isArray,d=console.createTask?console.createTask:function(){return null};_={"react-stack-bottom-frame":function(e){return e()}};var O,C={},X=_["react-stack-bottom-frame"].bind(_,s)(),Y=d(i(s)),ue={};A.Fragment=S,A.jsx=function(e,t,l,k,y){var g=1e4>D.recentlyCreatedOwnerStacks++;return h(e,t,l,!1,k,y,g?Error("react-stack-top-frame"):X,g?d(i(e)):Y)},A.jsxs=function(e,t,l,k,y){var g=1e4>D.recentlyCreatedOwnerStacks++;return h(e,t,l,!0,k,y,g?Error("react-stack-top-frame"):X,g?d(i(e)):Y)}}()),A}var te;function fe(){return te||(te=1,process.env.NODE_ENV==="production"?I.exports=le():I.exports=ie()),I.exports}var re=fe();const ne=r.createContext({}),de=()=>r.useContext(ne),be=(o,a)=>{let b=!1;return Object.keys(a).forEach(i=>{if(!(i in o)||b)return;const c=a[i],s=o[i];(typeof c=="object"||c!==s)&&(b=!0)}),b},ae=o=>!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage,oe=({id:o,form:a,method:b,action:i,children:c,onSubmit:s=()=>{},onInput:E=()=>{},onChange:u=()=>{},numberFields:R=[],className:m,...h})=>(r.useEffect(()=>a.actions.registerOnchange(u),[u]),re.jsx(ne.Provider,{value:a,children:re.jsx("form",{ref:a==null?void 0:a.ref,action:i,className:m,onSubmit:f=>{b||f.preventDefault();const _=a.actions.loadFormValues();s(_)},onInput:f=>{if(f.target.tagName==="FORM"){const _=a.actions.loadFormValues();a.actions.setFormState(_)}else E(f)},onChange:()=>{const f=a.actions.loadFormValues();a.actions.setFormState(f)},...h,children:c})})),se=({name:o,defaultValue:a,render:b=({ref:i,name:c,defaultValue:s,value:E,setValue:u})=>null})=>{const[i,c]=r.useState(a),s=de(),E=r.useRef(),u=r.useCallback((R,{shouldDirty:m=!1}={})=>{s.actions.setFormState(h=>({...h,[o]:R}),{shouldDirty:m}),c(R)},[c,s.actions.setFormState]);return r.useEffect(()=>(s.actions.setFormState(m=>({...m,[o]:a}),{shouldDirty:!1}),s.subscribe(o,(m,{shouldDirty:h=!0})=>{c(m),s.actions.setFormState(f=>({...f,[o]:m}),{shouldDirty:h}),E.current&&typeof E.current.dispatchEvent=="function"&&E.current.dispatchEvent(new Event("change"))})),[]),b({ref:E,name:o,defaultValue:a,value:i,setValue:u})},B=()=>{const[o,a]=r.useState({}),b=r.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),i=r.useCallback((u,R)=>{a(m=>m[u]===R?m:{...m,[u]:R})},[]),c=r.useCallback(u=>{a(R=>({...R,...u}))},[]),s=r.useCallback(u=>{a(R=>R[u]?{...R,[u]:""}:R)},[]),E=r.useCallback(()=>{a({})},[]);return{isError:b,errors:o,changeError:i,changeErrors:c,clearError:s,clearErrors:E}},H={defaultValues:{},numberFields:[]},ce=(o=H)=>{const{defaultValues:a=H.defaultValues,numberFields:b=H.numberFields}=o,{changeError:i,errors:c,changeErrors:s,clearError:E,clearErrors:u,isError:R}=B(),[m,h]=r.useState(!1),f=r.useRef({}),_=r.useRef(a),j=r.useRef({}),x=r.useRef(()=>{}),S=r.useRef(),M=r.useCallback((n,{shouldDirty:v=!0}={})=>{let d=n;typeof n=="function"&&(d=n(f.current)),f.current=d;let O=m;v&&(O=be(f.current,_.current),O!==m&&h(O)),x.current(f.current)},[m]),L=r.useCallback(()=>{h(!1),u();const n=j.current;Object.values(n).forEach(d=>d("")),S.current.reset(),f.current=_.current},[u]),Z=r.useCallback((n,v)=>{const d=j.current;return d[n]=v,()=>d[n]=null},[]),W=r.useCallback(n=>(x.current=n,()=>x.current=()=>{})),U=r.useCallback(n=>ae(n.target),[]),J=r.useCallback(n=>n?f.current[n]:f.current,[]),z=r.useCallback(()=>_.current,[]),F=r.useCallback(()=>{setTimeout(()=>S.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),N=r.useCallback(n=>{const v=ae(n.target);v?i(n.target.name,v):i(n.target.name,null)},[i]),G=r.useCallback((n,v,{shouldDirty:d=!0}={})=>{const O=j.current;if(typeof n=="string"){const C=O[n];if(!C)throw new Error(`${n} is uncontrolled, please use Controller for it!`);C(v,{shouldDirty:d}),F()}typeof n=="object"&&(Object.entries(n).forEach(([C,X])=>{const Y=O[C];if(!Y)throw new Error(`${C} is uncontrolled, please use Controller for it!`);Y(X,{shouldDirty:d})}),F())},[F]),V=r.useCallback(()=>{const n=Object.fromEntries(new FormData(S.current)),v=j.current;return Object.keys(v).map(d=>{n[d]=f.current[d]}),b.forEach(d=>n.hasOwnProperty(d)&&(n[d]=+n[d])),n},[]),D=r.useMemo(()=>({setValue:G,instantChange:F,getDefaultValues:z,getFormState:J,setFormState:M,changeError:i,changeErrors:s,clearError:E,clearErrors:u,loadFormValues:V,checkValidity:N,getFieldValidity:U,registerOnchange:W,reset:L}),[G,F,z,J,M,i,s,E,V,U,N,W,L]);return r.useEffect(()=>{if(S.current){const n=V();_.current={...n,...a},f.current={...n,...a}}},[]),{ref:S,isDirty:m,isError:R,errors:c,numberFields:b,subscribe:Z,actions:D}},me={Form:oe,Controller:se,useForm:ce,useValidateForm:B};T.Controller=se,T.Form=oe,T.default=me,T.useForm=ce,T.useValidateForm=B,Object.defineProperties(T,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|