react-simple-formkit 1.0.1 → 1.0.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.
- package/README.md +250 -5
- package/dist/react-simple-formkit.js +4 -4
- package/dist/react-simple-formkit.mjs +231 -216
- package/dist/react-simple-formkit.umd.js +4 -4
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -1,24 +1,269 @@
|
|
|
1
|
-
# React
|
|
1
|
+
# React Simple FormKit
|
|
2
2
|
|
|
3
3
|
Support form handling simply. Simple, fast and productive.
|
|
4
4
|
|
|
5
|
+
# Peer dependencies
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
"peerDependencies": {
|
|
9
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
10
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
11
|
+
},
|
|
12
|
+
```
|
|
13
|
+
|
|
5
14
|
# Quick start
|
|
6
15
|
|
|
7
16
|
```
|
|
8
|
-
import { Form, useForm } form 'react-
|
|
17
|
+
import { Form, useForm } form 'react-simple-formkit'
|
|
9
18
|
|
|
10
19
|
const form = useForm();
|
|
11
|
-
const { isDirty } = form;
|
|
20
|
+
const { isDirty, actions } = form;
|
|
12
21
|
|
|
13
22
|
const handleSubmit = (data) => {
|
|
14
|
-
|
|
23
|
+
alert(JSON.stringify(data));
|
|
15
24
|
};
|
|
16
25
|
|
|
17
26
|
return (
|
|
18
27
|
<Form form={form} onSubmit={handleSubmit}>
|
|
19
28
|
<input required name="email" />
|
|
20
29
|
<input required name="password" type="password" />
|
|
21
|
-
<button type="
|
|
30
|
+
<button type="button" disabled={!isDirty} onClick={() => actions.reset()}>
|
|
31
|
+
Reset
|
|
32
|
+
</button>
|
|
33
|
+
<button type="submit" disabled={!isDirty}>
|
|
34
|
+
Submit
|
|
35
|
+
</button>
|
|
36
|
+
</Form>
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# More kits
|
|
41
|
+
|
|
42
|
+
## number fields
|
|
43
|
+
|
|
44
|
+
- By default form, values are string at all. So, adding numberFields will catch the number value in on submit
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
const form = useForm( {numberFields: ['number'] } );
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Form form={form}>
|
|
51
|
+
<input name="number" placeholder=This is number field" />
|
|
52
|
+
<button type="submit" disabled={!isDirty || isError}>
|
|
53
|
+
Submit
|
|
54
|
+
</button>
|
|
55
|
+
</Form>
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## JS Built-in validate on blur
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
const form = useForm();
|
|
63
|
+
const { isDirty, isError, errors, actions } = form;
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Form form={form}>
|
|
67
|
+
<input required name="email" placeholder="email" type="email" onBlur={actions.checkValidity} />
|
|
68
|
+
{errors.email && <span>{errors.email}</span>}
|
|
69
|
+
|
|
70
|
+
<button type="submit" disabled={!isDirty || isError}>
|
|
71
|
+
Submit
|
|
72
|
+
</button>
|
|
73
|
+
</Form>
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Double validate on blur
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
const form = useForm();
|
|
81
|
+
const { isDirty, isError, errors, actions } = form;
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Form form={form}>
|
|
85
|
+
<input
|
|
86
|
+
required
|
|
87
|
+
name="number"
|
|
88
|
+
onBlur={(e) => {
|
|
89
|
+
let error = null;
|
|
90
|
+
error = actions.getFieldValidity(e);
|
|
91
|
+
|
|
92
|
+
if (error) {
|
|
93
|
+
actions.changeError("number", error);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const value = Number(e.target.value || 0);
|
|
98
|
+
if (value >= 10) error = "Number must be less than 10";
|
|
99
|
+
actions.changeError("number", error);
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
{errors.number && <span className="error-message">{errors.number}</span>}
|
|
103
|
+
|
|
104
|
+
<button type="submit" disabled={!isDirty || isError}>
|
|
105
|
+
Submit
|
|
106
|
+
</button>
|
|
22
107
|
</Form>
|
|
23
108
|
);
|
|
24
109
|
```
|
|
110
|
+
|
|
111
|
+
## Validate by other field
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
const form = useForm();
|
|
115
|
+
const { isDirty, isError, errors, actions } = form;
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Form form={form}>
|
|
119
|
+
<input required name="number" onBlur={actions.checkValidity} />
|
|
120
|
+
{errors.number && <span className="error-message">{errors.number}</span>}
|
|
121
|
+
|
|
122
|
+
<input
|
|
123
|
+
required
|
|
124
|
+
name="number2"
|
|
125
|
+
onBlur={(e) => {
|
|
126
|
+
let error = null;
|
|
127
|
+
error = actions.getFieldValidity(e);
|
|
128
|
+
|
|
129
|
+
if (error) {
|
|
130
|
+
actions.changeError("number2", error);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const value = Number(e.target.value || 0);
|
|
135
|
+
const formState = actions.getFormState();
|
|
136
|
+
const number = Number(formState.number || 0);
|
|
137
|
+
|
|
138
|
+
if (value >= number) error = "Number 2 must be less than number 1";
|
|
139
|
+
actions.changeError("number2", error);
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
{errors.number2 && <span className="error-message">{errors.number2}</span>}
|
|
143
|
+
<button type="submit" disabled={!isDirty || isError}>
|
|
144
|
+
Submit
|
|
145
|
+
</button>
|
|
146
|
+
</Form>
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
# Support for third party library
|
|
151
|
+
|
|
152
|
+
## Catch value instantly
|
|
153
|
+
|
|
154
|
+
- Some input types like DatePicker, Select just change by click and don't dispatch input actions
|
|
155
|
+
- You also catch this on submit, but cannot use for actions.getFormState() for validate and isDirty update
|
|
156
|
+
- Just put the actions.instantChange where these components onchange
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
const form = useForm();
|
|
160
|
+
const { isDirty, actions } = form;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<Form form={form}>
|
|
164
|
+
<Select name="select" onChange={actions.instantChange}>
|
|
165
|
+
<MenuItem value={10}>Ten</MenuItem>
|
|
166
|
+
<MenuItem value={20}>Twenty</MenuItem>
|
|
167
|
+
<MenuItem value={30}>Thirty</MenuItem>
|
|
168
|
+
</Select>
|
|
169
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
170
|
+
<DatePicker name="date" onChange={actions.instantChange} />
|
|
171
|
+
</LocalizationProvider>
|
|
172
|
+
<button type="button" onClick={() => alert(JSON.stringify(actions.getFormState()))}>
|
|
173
|
+
Get value
|
|
174
|
+
</button>
|
|
175
|
+
<button type="submit" disabled={!isDirty}>
|
|
176
|
+
Submit
|
|
177
|
+
</button>
|
|
178
|
+
</Form>
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## More control with Controller
|
|
183
|
+
|
|
184
|
+
- Control custom values like object and array
|
|
185
|
+
- Make field assignable by actions.setValue
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
import { Controller, Form, useForm } from "react-simple-formkit";
|
|
189
|
+
|
|
190
|
+
const form = useForm({ numberFields: ["number1", "number2"] });
|
|
191
|
+
const { isDirty, actions } = form;
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Form form={form}>
|
|
195
|
+
{/* Custom value as array */}
|
|
196
|
+
<Controller
|
|
197
|
+
name="multipleSelect"
|
|
198
|
+
defaultValue={[]}
|
|
199
|
+
render={({ ref, value, setValue, name }) => (
|
|
200
|
+
<Select
|
|
201
|
+
multiple
|
|
202
|
+
ref={ref}
|
|
203
|
+
name={name}
|
|
204
|
+
labelId="demo-multiple-name-label"
|
|
205
|
+
id="demo-multiple-name"
|
|
206
|
+
value={value}
|
|
207
|
+
onChange={(e) => {
|
|
208
|
+
const value = e.target.value;
|
|
209
|
+
// On autofill we get a stringified value.
|
|
210
|
+
setValue(typeof value === "string" ? value.split(",") : value);
|
|
211
|
+
// instantChange by select
|
|
212
|
+
actions.instantChange();
|
|
213
|
+
}}
|
|
214
|
+
input={<OutlinedInput label="Name" />}
|
|
215
|
+
>
|
|
216
|
+
<MenuItem value={10}>Ten</MenuItem>
|
|
217
|
+
<MenuItem value={20}>Twenty</MenuItem>
|
|
218
|
+
<MenuItem value={30}>Thirty</MenuItem>
|
|
219
|
+
</Select>
|
|
220
|
+
)}
|
|
221
|
+
/>
|
|
222
|
+
{/* actions.setValue (target field of actions.setValue must use controller)*/}
|
|
223
|
+
<input
|
|
224
|
+
name="number1"
|
|
225
|
+
placeholder="number 1"
|
|
226
|
+
onBlur={(e) => {
|
|
227
|
+
const number1 = Number(e.target.value || 0);
|
|
228
|
+
const number2 = actions.getFormState().number2 || 0;
|
|
229
|
+
actions.setValue("sum", number1 + number2);
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
<input
|
|
233
|
+
name="number2"
|
|
234
|
+
placeholder="number 2"
|
|
235
|
+
onBlur={(e) => {
|
|
236
|
+
const number2 = Number(e.target.value || 0);
|
|
237
|
+
const number1 = actions.getFormState().number1 || 0;
|
|
238
|
+
actions.setValue("sum", number1 + number2);
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
241
|
+
<Controller
|
|
242
|
+
name="sum"
|
|
243
|
+
render={({ ref, value, setValue, name }) => (
|
|
244
|
+
<input
|
|
245
|
+
ref={ref}
|
|
246
|
+
value={value}
|
|
247
|
+
onChange={(e) => setValue(e.target.value)}
|
|
248
|
+
name={name}
|
|
249
|
+
placeholder="sum(number1, number2)"
|
|
250
|
+
/>
|
|
251
|
+
)}
|
|
252
|
+
/>
|
|
253
|
+
<button type="button" onClick={() => alert(JSON.stringify(actions.getFormState()))}>
|
|
254
|
+
Get value
|
|
255
|
+
</button>
|
|
256
|
+
<button type="submit" disabled={!isDirty}>
|
|
257
|
+
Submit
|
|
258
|
+
</button>
|
|
259
|
+
</Form>
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
# Examples
|
|
264
|
+
|
|
265
|
+
- https://codesandbox.io/p/sandbox/react-simple-formkit-examples-rhmhjj
|
|
266
|
+
|
|
267
|
+
# Contact
|
|
268
|
+
|
|
269
|
+
For any ideas or issues, please get in touch with me at anhhuy2000@gmail.com
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),se=(a,n)=>{let d=!1;return Object.keys(n).forEach(l=>{if(!(l in a)||d)return;const c=n[l],s=a[l];(typeof c=="object"||c!==s)&&(d=!0)}),d},Q=a=>!a||typeof a.checkValidity!="function"||a.checkValidity()?null:a.validationMessage,ne=()=>{const[a,n]=o.useState({}),d=o.useMemo(()=>Object.values(a).filter(Boolean).length>0,[a]),l=o.useCallback((i,R)=>{n(m=>m[i]===R?m:{...m,[i]:R})},[]),c=o.useCallback(i=>{n(R=>({...R,...i}))},[]),s=o.useCallback(i=>{n(R=>R[i]?{...R,[i]:""}:R)},[]),b=o.useCallback(()=>{n({})},[]);return{isError:d,errors:a,changeError:l,changeErrors:c,clearError:s,clearErrors:b}},X={defaultValues:{},numberFields:[]},ce=(a=X)=>{const{defaultValues:n=X.defaultValues,numberFields:d=X.numberFields}=a,{changeError:l,errors:c,changeErrors:s,clearError:b,clearErrors:i,isError:R}=ne(),[m,T]=o.useState(!1),E=o.useRef({}),k=o.useRef(n),O=o.useRef({}),C=o.useRef(),F=o.useCallback((t,{shouldDirty:_=!0}={})=>{let f=t;if(typeof t=="function"&&(f=t(E.current)),E.current=f,_){const j=se(E.current,k.current);j!==m&&T(j)}},[m]),V=o.useCallback(()=>{T(!1),i();const t=O.current;Object.values(t).forEach(f=>f("")),C.current.reset(),E.current=k.current},[i]),U=o.useCallback((t,_)=>{const f=O.current;return f[t]=_,()=>f[t]=null},[]),D=o.useCallback(t=>Q(t.target),[]),Y=o.useCallback(t=>t?E.current[t]:E.current,[]),I=o.useCallback(()=>k.current,[]),y=o.useCallback(()=>{setTimeout(()=>C.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),$=o.useCallback(t=>{const _=Q(t.target);_?l(t.target.name,_):l(t.target.name,null)},[l]),M=o.useCallback((t,_,{shouldDirty:f=!0}={})=>{const j=O.current;if(typeof t=="string"){const S=j[t];if(!S)throw new Error(`${t} is uncontrolled, please use Controller for it!`);S(_,{shouldDirty:f}),y()}typeof t=="object"&&(Object.entries(t).forEach(([S,L])=>{const x=j[S];if(!x)throw new Error(`${S} is uncontrolled, please use Controller for it!`);x(L,{shouldDirty:f})}),y())},[y]),w=o.useCallback(()=>{const t=Object.fromEntries(new FormData(C.current)),_=O.current;return Object.keys(_).map(f=>{t[f]=E.current[f]}),d.forEach(f=>t.hasOwnProperty(f)&&(t[f]=+t[f])),t},[]),q=o.useMemo(()=>({setValue:M,instantChange:y,getDefaultValues:I,getFormState:Y,setFormState:F,changeError:l,changeErrors:s,clearError:b,clearErrors:i,loadFormValues:w,checkValidity:$,getFieldValidity:D,reset:V}),[M,y,I,Y,F,l,s,b,w,D,$,V]);return o.useEffect(()=>{if(C.current){const t=w();k.current={...t,...n},E.current={...t,...n}}},[]),{ref:C,isDirty:m,isError:R,errors:c,numberFields:d,subscribe:U,actions:q}};var W={exports:{}},A={};/**
|
|
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 K;function ue(){if(K)return A;K=1;var a=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function d(l,c,s){var b=null;if(s!==void 0&&(b=""+s),c.key!==void 0&&(b=""+c.key),"key"in c){s={};for(var i in c)i!=="key"&&(s[i]=c[i])}else s=c;return c=s.ref,{$$typeof:a,type:l,key:b,ref:c!==void 0?c:null,props:s}}return A.Fragment=n,A.jsx=d,A.jsxs=d,A}var N={};/**
|
|
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 le(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function a(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===t?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case F:return"Fragment";case U:return"Profiler";case V:return"StrictMode";case y:return"Suspense";case $:return"SuspenseList";case q: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 C:return"Portal";case Y:return(e.displayName||"Context")+".Provider";case D:return(e._context.displayName||"Context")+".Consumer";case I:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case M:return r=e.displayName||null,r!==null?r:a(e.type)||"Memo";case w:r=e._payload,e=e._init;try{return a(e(r))}catch{}}return null}function n(e){return""+e}function d(e){try{n(e);var r=!1}catch{r=!0}if(r){r=console;var u=r.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),n(e)}}function l(e){if(e===F)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===w)return"<...>";try{var r=a(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function c(){var e=_.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function b(e){if(f.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function i(e,r){function u(){L||(L=!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))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function R(){var e=a(this.type);return x[e]||(x[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,r,u,p,g,h,J,z){return u=h.ref,e={$$typeof:O,type:e,key:r,props:h,_owner:g},(u!==void 0?u: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:J}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:z}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function T(e,r,u,p,g,h,J,z){var v=r.children;if(v!==void 0)if(p)if(j(v)){for(p=0;p<v.length;p++)E(v[p]);Object.freeze&&Object.freeze(v)}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 E(v);if(f.call(r,"key")){v=a(e);var P=Object.keys(r).filter(function(ae){return ae!=="key"});p=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",Z[v+p]||(P=0<P.length?"{"+P.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,
|
|
22
|
+
<%s key={someKey} {...props} />`,p,v,P,v),Z[v+p]=!0)}if(v=null,u!==void 0&&(d(u),v=""+u),b(r)&&(d(r.key),v=""+r.key),"key"in r){u={};for(var G in r)G!=="key"&&(u[G]=r[G])}else u=r;return v&&i(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),m(e,v,h,g,c(),u,J,z)}function E(e){typeof e=="object"&&e!==null&&e.$$typeof===O&&e._store&&(e._store.validated=1)}var k=o,O=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),F=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),U=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),Y=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),y=Symbol.for("react.suspense"),$=Symbol.for("react.suspense_list"),M=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),t=Symbol.for("react.client.reference"),_=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,f=Object.prototype.hasOwnProperty,j=Array.isArray,S=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var L,x={},B=k["react-stack-bottom-frame"].bind(k,s)(),H=S(l(s)),Z={};N.Fragment=F,N.jsx=function(e,r,u,p,g){var h=1e4>_.recentlyCreatedOwnerStacks++;return T(e,r,u,!1,p,g,h?Error("react-stack-top-frame"):B,h?S(l(e)):H)},N.jsxs=function(e,r,u,p,g){var h=1e4>_.recentlyCreatedOwnerStacks++;return T(e,r,u,!0,p,g,h?Error("react-stack-top-frame"):B,h?S(l(e)):H)}}()),N}var re;function ie(){return re||(re=1,process.env.NODE_ENV==="production"?W.exports=ue():W.exports=le()),W.exports}var te=ie();const oe=o.createContext({}),fe=()=>o.useContext(oe),de=({id:a,form:n,method:d,action:l,children:c,onSubmit:s=()=>{},onInput:b=()=>{},onChange:i=()=>{},numberFields:R=[],className:m,...T})=>te.jsx(oe.Provider,{value:n,children:te.jsx("form",{ref:n==null?void 0:n.ref,action:l,className:m,onSubmit:E=>{E.preventDefault();const k=n.actions.loadFormValues();s(k)},onInput:E=>{b(E);const k=n.actions.loadFormValues();n.actions.setFormState(k)},onChange:E=>{const k=n.actions.loadFormValues();n.actions.setFormState(k),i(k)},...T,children:c})}),be=({name:a,defaultValue:n,render:d=({ref:l,name:c,defaultValue:s,value:b,setValue:i})=>null})=>{const[l,c]=o.useState(n),s=fe(),b=o.useRef(),i=o.useCallback((R,{shouldDirty:m=!1}={})=>{s.actions.setFormState(T=>({...T,[a]:R}),{shouldDirty:m}),c(R)},[c,s.actions.setFormState]);return o.useEffect(()=>(s.actions.setFormState(m=>({...m,[a]:n}),{shouldDirty:!1}),s.subscribe(a,(m,{shouldDirty:T=!0})=>{c(m),s.actions.setFormState(E=>({...E,[a]:m}),{shouldDirty:T}),b.current&&typeof b.current.dispatchEvent=="function"&&b.current.dispatchEvent(new Event("change"))})),[]),d({ref:b,name:a,defaultValue:n,value:l,setValue:i})};exports.Controller=be;exports.Form=de;exports.useForm=ce;exports.useValidateForm=ne;
|
|
@@ -1,101 +1,111 @@
|
|
|
1
|
-
import le, { useState as
|
|
2
|
-
const
|
|
1
|
+
import le, { useState as H, useMemo as ae, useCallback as T, useRef as V, useEffect as se, createContext as ie, useContext as fe } from "react";
|
|
2
|
+
const de = (o, n) => {
|
|
3
3
|
let f = !1;
|
|
4
|
-
return Object.keys(n).forEach((
|
|
5
|
-
if (!(
|
|
6
|
-
const s = n[
|
|
7
|
-
typeof s == "object"
|
|
4
|
+
return Object.keys(n).forEach((u) => {
|
|
5
|
+
if (!(u in o) || f) return;
|
|
6
|
+
const s = n[u], a = o[u];
|
|
7
|
+
(typeof s == "object" || s !== a) && (f = !0);
|
|
8
8
|
}), f;
|
|
9
|
-
},
|
|
10
|
-
const [
|
|
11
|
-
n((
|
|
12
|
-
}, []), s =
|
|
13
|
-
n((
|
|
14
|
-
}, []),
|
|
15
|
-
n((
|
|
16
|
-
}, []), d =
|
|
9
|
+
}, ee = (o) => !o || typeof o.checkValidity != "function" || o.checkValidity() ? null : o.validationMessage, Ee = () => {
|
|
10
|
+
const [o, n] = H({}), f = ae(() => Object.values(o).filter(Boolean).length > 0, [o]), u = T((l, b) => {
|
|
11
|
+
n((E) => E[l] === b ? E : { ...E, [l]: b });
|
|
12
|
+
}, []), s = T((l) => {
|
|
13
|
+
n((b) => ({ ...b, ...l }));
|
|
14
|
+
}, []), a = T((l) => {
|
|
15
|
+
n((b) => b[l] ? { ...b, [l]: "" } : b);
|
|
16
|
+
}, []), d = T(() => {
|
|
17
17
|
n({});
|
|
18
18
|
}, []);
|
|
19
|
-
return { isError: f, errors:
|
|
20
|
-
},
|
|
19
|
+
return { isError: f, errors: o, changeError: u, changeErrors: s, clearError: a, clearErrors: d };
|
|
20
|
+
}, B = {
|
|
21
21
|
defaultValues: {},
|
|
22
22
|
numberFields: []
|
|
23
|
-
},
|
|
24
|
-
const { defaultValues: n =
|
|
25
|
-
(t, { shouldDirty:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
}, ve = (o = B) => {
|
|
24
|
+
const { defaultValues: n = B.defaultValues, numberFields: f = B.numberFields } = o, { changeError: u, errors: s, changeErrors: a, clearError: d, clearErrors: l, isError: b } = Ee(), [E, h] = H(!1), m = V({}), R = V(n), O = V({}), y = V(), x = T(
|
|
25
|
+
(t, { shouldDirty: v = !0 } = {}) => {
|
|
26
|
+
let i = t;
|
|
27
|
+
if (typeof t == "function" && (i = t(m.current)), m.current = i, v) {
|
|
28
|
+
const w = de(m.current, R.current);
|
|
29
|
+
w !== E && h(w);
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
|
-
[
|
|
32
|
-
),
|
|
33
|
-
|
|
34
|
-
const t =
|
|
35
|
-
Object.values(t).forEach((
|
|
36
|
-
}, [
|
|
37
|
-
|
|
38
|
-
[]
|
|
39
|
-
),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
[E]
|
|
33
|
+
), D = T(() => {
|
|
34
|
+
h(!1), l();
|
|
35
|
+
const t = O.current;
|
|
36
|
+
Object.values(t).forEach((i) => i("")), y.current.reset(), m.current = R.current;
|
|
37
|
+
}, [l]), q = T((t, v) => {
|
|
38
|
+
const i = O.current;
|
|
39
|
+
return i[t] = v, () => i[t] = null;
|
|
40
|
+
}, []), Y = T((t) => ee(t.target), []), I = T((t) => t ? m.current[t] : m.current, []), $ = T(() => R.current, []), j = T(() => {
|
|
41
|
+
setTimeout(() => y.current.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
42
|
+
}, []), M = T(
|
|
43
|
+
(t) => {
|
|
44
|
+
const v = ee(t.target);
|
|
45
|
+
v ? u(t.target.name, v) : u(t.target.name, null);
|
|
46
|
+
},
|
|
47
|
+
[u]
|
|
48
|
+
), L = T(
|
|
49
|
+
(t, v, { shouldDirty: i = !0 } = {}) => {
|
|
50
|
+
const w = O.current;
|
|
45
51
|
if (typeof t == "string") {
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
52
|
+
const S = w[t];
|
|
53
|
+
if (!S)
|
|
48
54
|
throw new Error(`${t} is uncontrolled, please use Controller for it!`);
|
|
49
|
-
|
|
55
|
+
S(v, { shouldDirty: i }), j();
|
|
50
56
|
}
|
|
51
|
-
typeof t == "object" && (Object.entries(t).forEach(([
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
throw new Error(`${
|
|
55
|
-
|
|
56
|
-
}),
|
|
57
|
+
typeof t == "object" && (Object.entries(t).forEach(([S, W]) => {
|
|
58
|
+
const F = w[S];
|
|
59
|
+
if (!F)
|
|
60
|
+
throw new Error(`${S} is uncontrolled, please use Controller for it!`);
|
|
61
|
+
F(W, { shouldDirty: i });
|
|
62
|
+
}), j());
|
|
57
63
|
},
|
|
58
|
-
[
|
|
59
|
-
), A =
|
|
60
|
-
const t = Object.fromEntries(new FormData(
|
|
61
|
-
return Object.keys(
|
|
62
|
-
t[
|
|
63
|
-
}), f.forEach((
|
|
64
|
-
}, []),
|
|
64
|
+
[j]
|
|
65
|
+
), A = T(() => {
|
|
66
|
+
const t = Object.fromEntries(new FormData(y.current)), v = O.current;
|
|
67
|
+
return Object.keys(v).map((i) => {
|
|
68
|
+
t[i] = m.current[i];
|
|
69
|
+
}), f.forEach((i) => t.hasOwnProperty(i) && (t[i] = +t[i])), t;
|
|
70
|
+
}, []), J = ae(
|
|
65
71
|
() => ({
|
|
66
|
-
setValue:
|
|
67
|
-
instantChange:
|
|
68
|
-
getDefaultValues:
|
|
69
|
-
getFormState:
|
|
70
|
-
setFormState:
|
|
71
|
-
changeError:
|
|
72
|
-
changeErrors:
|
|
72
|
+
setValue: L,
|
|
73
|
+
instantChange: j,
|
|
74
|
+
getDefaultValues: $,
|
|
75
|
+
getFormState: I,
|
|
76
|
+
setFormState: x,
|
|
77
|
+
changeError: u,
|
|
78
|
+
changeErrors: a,
|
|
73
79
|
clearError: d,
|
|
74
|
-
clearErrors:
|
|
80
|
+
clearErrors: l,
|
|
75
81
|
loadFormValues: A,
|
|
76
|
-
|
|
82
|
+
checkValidity: M,
|
|
83
|
+
getFieldValidity: Y,
|
|
84
|
+
reset: D
|
|
77
85
|
}),
|
|
78
86
|
[
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
L,
|
|
88
|
+
j,
|
|
89
|
+
$,
|
|
90
|
+
I,
|
|
91
|
+
x,
|
|
92
|
+
u,
|
|
93
|
+
a,
|
|
86
94
|
d,
|
|
87
95
|
A,
|
|
88
|
-
|
|
96
|
+
Y,
|
|
97
|
+
M,
|
|
98
|
+
D
|
|
89
99
|
]
|
|
90
100
|
);
|
|
91
101
|
return se(() => {
|
|
92
|
-
if (
|
|
102
|
+
if (y.current) {
|
|
93
103
|
const t = A();
|
|
94
|
-
|
|
104
|
+
R.current = { ...t, ...n }, m.current = { ...t, ...n };
|
|
95
105
|
}
|
|
96
|
-
}, []), { ref:
|
|
106
|
+
}, []), { ref: y, isDirty: E, isError: b, errors: s, numberFields: f, subscribe: q, actions: J };
|
|
97
107
|
};
|
|
98
|
-
var
|
|
108
|
+
var U = { exports: {} }, C = {};
|
|
99
109
|
/**
|
|
100
110
|
* @license React
|
|
101
111
|
* react-jsx-runtime.production.js
|
|
@@ -105,29 +115,29 @@ var L = { exports: {} }, P = {};
|
|
|
105
115
|
* This source code is licensed under the MIT license found in the
|
|
106
116
|
* LICENSE file in the root directory of this source tree.
|
|
107
117
|
*/
|
|
108
|
-
var
|
|
109
|
-
function
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
var
|
|
113
|
-
function f(
|
|
118
|
+
var re;
|
|
119
|
+
function me() {
|
|
120
|
+
if (re) return C;
|
|
121
|
+
re = 1;
|
|
122
|
+
var o = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
123
|
+
function f(u, s, a) {
|
|
114
124
|
var d = null;
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
for (var
|
|
118
|
-
|
|
119
|
-
} else
|
|
120
|
-
return s =
|
|
121
|
-
$$typeof:
|
|
122
|
-
type:
|
|
125
|
+
if (a !== void 0 && (d = "" + a), s.key !== void 0 && (d = "" + s.key), "key" in s) {
|
|
126
|
+
a = {};
|
|
127
|
+
for (var l in s)
|
|
128
|
+
l !== "key" && (a[l] = s[l]);
|
|
129
|
+
} else a = s;
|
|
130
|
+
return s = a.ref, {
|
|
131
|
+
$$typeof: o,
|
|
132
|
+
type: u,
|
|
123
133
|
key: d,
|
|
124
134
|
ref: s !== void 0 ? s : null,
|
|
125
|
-
props:
|
|
135
|
+
props: a
|
|
126
136
|
};
|
|
127
137
|
}
|
|
128
|
-
return
|
|
138
|
+
return C.Fragment = n, C.jsx = f, C.jsxs = f, C;
|
|
129
139
|
}
|
|
130
|
-
var
|
|
140
|
+
var N = {};
|
|
131
141
|
/**
|
|
132
142
|
* @license React
|
|
133
143
|
* react-jsx-runtime.development.js
|
|
@@ -137,47 +147,47 @@ var F = {};
|
|
|
137
147
|
* This source code is licensed under the MIT license found in the
|
|
138
148
|
* LICENSE file in the root directory of this source tree.
|
|
139
149
|
*/
|
|
140
|
-
var
|
|
141
|
-
function
|
|
142
|
-
return
|
|
143
|
-
function
|
|
150
|
+
var te;
|
|
151
|
+
function be() {
|
|
152
|
+
return te || (te = 1, process.env.NODE_ENV !== "production" && function() {
|
|
153
|
+
function o(e) {
|
|
144
154
|
if (e == null) return null;
|
|
145
155
|
if (typeof e == "function")
|
|
146
|
-
return e.$$typeof ===
|
|
156
|
+
return e.$$typeof === t ? null : e.displayName || e.name || null;
|
|
147
157
|
if (typeof e == "string") return e;
|
|
148
158
|
switch (e) {
|
|
149
|
-
case
|
|
159
|
+
case x:
|
|
150
160
|
return "Fragment";
|
|
151
|
-
case
|
|
161
|
+
case q:
|
|
152
162
|
return "Profiler";
|
|
153
|
-
case
|
|
163
|
+
case D:
|
|
154
164
|
return "StrictMode";
|
|
155
|
-
case
|
|
165
|
+
case j:
|
|
156
166
|
return "Suspense";
|
|
157
|
-
case
|
|
167
|
+
case M:
|
|
158
168
|
return "SuspenseList";
|
|
159
|
-
case
|
|
169
|
+
case J:
|
|
160
170
|
return "Activity";
|
|
161
171
|
}
|
|
162
172
|
if (typeof e == "object")
|
|
163
173
|
switch (typeof e.tag == "number" && console.error(
|
|
164
174
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
165
175
|
), e.$$typeof) {
|
|
166
|
-
case
|
|
176
|
+
case y:
|
|
167
177
|
return "Portal";
|
|
168
|
-
case
|
|
178
|
+
case I:
|
|
169
179
|
return (e.displayName || "Context") + ".Provider";
|
|
170
180
|
case Y:
|
|
171
181
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
172
|
-
case
|
|
182
|
+
case $:
|
|
173
183
|
var r = e.render;
|
|
174
184
|
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
175
|
-
case
|
|
176
|
-
return r = e.displayName || null, r !== null ? r :
|
|
177
|
-
case
|
|
185
|
+
case L:
|
|
186
|
+
return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
|
|
187
|
+
case A:
|
|
178
188
|
r = e._payload, e = e._init;
|
|
179
189
|
try {
|
|
180
|
-
return
|
|
190
|
+
return o(e(r));
|
|
181
191
|
} catch {
|
|
182
192
|
}
|
|
183
193
|
}
|
|
@@ -195,42 +205,42 @@ function me() {
|
|
|
195
205
|
}
|
|
196
206
|
if (r) {
|
|
197
207
|
r = console;
|
|
198
|
-
var c = r.error,
|
|
208
|
+
var c = r.error, p = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
199
209
|
return c.call(
|
|
200
210
|
r,
|
|
201
211
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
202
|
-
|
|
212
|
+
p
|
|
203
213
|
), n(e);
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
|
-
function
|
|
207
|
-
if (e ===
|
|
208
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
216
|
+
function u(e) {
|
|
217
|
+
if (e === x) return "<>";
|
|
218
|
+
if (typeof e == "object" && e !== null && e.$$typeof === A)
|
|
209
219
|
return "<...>";
|
|
210
220
|
try {
|
|
211
|
-
var r =
|
|
221
|
+
var r = o(e);
|
|
212
222
|
return r ? "<" + r + ">" : "<...>";
|
|
213
223
|
} catch {
|
|
214
224
|
return "<...>";
|
|
215
225
|
}
|
|
216
226
|
}
|
|
217
227
|
function s() {
|
|
218
|
-
var e =
|
|
228
|
+
var e = v.A;
|
|
219
229
|
return e === null ? null : e.getOwner();
|
|
220
230
|
}
|
|
221
|
-
function
|
|
231
|
+
function a() {
|
|
222
232
|
return Error("react-stack-top-frame");
|
|
223
233
|
}
|
|
224
234
|
function d(e) {
|
|
225
|
-
if (
|
|
235
|
+
if (i.call(e, "key")) {
|
|
226
236
|
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
227
237
|
if (r && r.isReactWarning) return !1;
|
|
228
238
|
}
|
|
229
239
|
return e.key !== void 0;
|
|
230
240
|
}
|
|
231
|
-
function
|
|
241
|
+
function l(e, r) {
|
|
232
242
|
function c() {
|
|
233
|
-
|
|
243
|
+
W || (W = !0, console.error(
|
|
234
244
|
"%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)",
|
|
235
245
|
r
|
|
236
246
|
));
|
|
@@ -240,22 +250,22 @@ function me() {
|
|
|
240
250
|
configurable: !0
|
|
241
251
|
});
|
|
242
252
|
}
|
|
243
|
-
function
|
|
244
|
-
var e =
|
|
245
|
-
return
|
|
253
|
+
function b() {
|
|
254
|
+
var e = o(this.type);
|
|
255
|
+
return F[e] || (F[e] = !0, console.error(
|
|
246
256
|
"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."
|
|
247
257
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
248
258
|
}
|
|
249
|
-
function
|
|
250
|
-
return c =
|
|
251
|
-
$$typeof:
|
|
259
|
+
function E(e, r, c, p, g, k, z, G) {
|
|
260
|
+
return c = k.ref, e = {
|
|
261
|
+
$$typeof: O,
|
|
252
262
|
type: e,
|
|
253
263
|
key: r,
|
|
254
|
-
props:
|
|
255
|
-
_owner:
|
|
264
|
+
props: k,
|
|
265
|
+
_owner: g
|
|
256
266
|
}, (c !== void 0 ? c : null) !== null ? Object.defineProperty(e, "ref", {
|
|
257
267
|
enumerable: !1,
|
|
258
|
-
get:
|
|
268
|
+
get: b
|
|
259
269
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
260
270
|
configurable: !1,
|
|
261
271
|
enumerable: !1,
|
|
@@ -270,158 +280,163 @@ function me() {
|
|
|
270
280
|
configurable: !1,
|
|
271
281
|
enumerable: !1,
|
|
272
282
|
writable: !0,
|
|
273
|
-
value:
|
|
283
|
+
value: z
|
|
274
284
|
}), Object.defineProperty(e, "_debugTask", {
|
|
275
285
|
configurable: !1,
|
|
276
286
|
enumerable: !1,
|
|
277
287
|
writable: !0,
|
|
278
|
-
value:
|
|
288
|
+
value: G
|
|
279
289
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
280
290
|
}
|
|
281
|
-
function
|
|
282
|
-
var
|
|
283
|
-
if (
|
|
284
|
-
if (
|
|
285
|
-
if (
|
|
286
|
-
for (
|
|
287
|
-
_
|
|
288
|
-
Object.freeze && Object.freeze(
|
|
291
|
+
function h(e, r, c, p, g, k, z, G) {
|
|
292
|
+
var _ = r.children;
|
|
293
|
+
if (_ !== void 0)
|
|
294
|
+
if (p)
|
|
295
|
+
if (w(_)) {
|
|
296
|
+
for (p = 0; p < _.length; p++)
|
|
297
|
+
m(_[p]);
|
|
298
|
+
Object.freeze && Object.freeze(_);
|
|
289
299
|
} else
|
|
290
300
|
console.error(
|
|
291
301
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
292
302
|
);
|
|
293
|
-
else _
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
var
|
|
303
|
+
else m(_);
|
|
304
|
+
if (i.call(r, "key")) {
|
|
305
|
+
_ = o(e);
|
|
306
|
+
var P = Object.keys(r).filter(function(ue) {
|
|
297
307
|
return ue !== "key";
|
|
298
308
|
});
|
|
299
|
-
|
|
309
|
+
p = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", K[_ + p] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
300
310
|
`A props object containing a "key" prop is being spread into JSX:
|
|
301
311
|
let props = %s;
|
|
302
312
|
<%s {...props} />
|
|
303
313
|
React keys must be passed directly to JSX without using spread:
|
|
304
314
|
let props = %s;
|
|
305
315
|
<%s key={someKey} {...props} />`,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
), K[
|
|
316
|
+
p,
|
|
317
|
+
_,
|
|
318
|
+
P,
|
|
319
|
+
_
|
|
320
|
+
), K[_ + p] = !0);
|
|
311
321
|
}
|
|
312
|
-
if (
|
|
322
|
+
if (_ = null, c !== void 0 && (f(c), _ = "" + c), d(r) && (f(r.key), _ = "" + r.key), "key" in r) {
|
|
313
323
|
c = {};
|
|
314
|
-
for (var
|
|
315
|
-
|
|
324
|
+
for (var X in r)
|
|
325
|
+
X !== "key" && (c[X] = r[X]);
|
|
316
326
|
} else c = r;
|
|
317
|
-
return
|
|
327
|
+
return _ && l(
|
|
318
328
|
c,
|
|
319
329
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
320
|
-
),
|
|
330
|
+
), E(
|
|
321
331
|
e,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
332
|
+
_,
|
|
333
|
+
k,
|
|
334
|
+
g,
|
|
325
335
|
s(),
|
|
326
336
|
c,
|
|
327
|
-
|
|
328
|
-
|
|
337
|
+
z,
|
|
338
|
+
G
|
|
329
339
|
);
|
|
330
340
|
}
|
|
331
|
-
function
|
|
332
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
341
|
+
function m(e) {
|
|
342
|
+
typeof e == "object" && e !== null && e.$$typeof === O && e._store && (e._store.validated = 1);
|
|
333
343
|
}
|
|
334
|
-
var
|
|
344
|
+
var R = le, O = Symbol.for("react.transitional.element"), y = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), D = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), Y = Symbol.for("react.consumer"), I = Symbol.for("react.context"), $ = Symbol.for("react.forward_ref"), j = Symbol.for("react.suspense"), M = Symbol.for("react.suspense_list"), L = Symbol.for("react.memo"), A = Symbol.for("react.lazy"), J = Symbol.for("react.activity"), t = Symbol.for("react.client.reference"), v = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, i = Object.prototype.hasOwnProperty, w = Array.isArray, S = console.createTask ? console.createTask : function() {
|
|
335
345
|
return null;
|
|
336
346
|
};
|
|
337
|
-
|
|
347
|
+
R = {
|
|
338
348
|
"react-stack-bottom-frame": function(e) {
|
|
339
349
|
return e();
|
|
340
350
|
}
|
|
341
351
|
};
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
)(), Q =
|
|
346
|
-
|
|
347
|
-
var
|
|
348
|
-
return
|
|
352
|
+
var W, F = {}, Z = R["react-stack-bottom-frame"].bind(
|
|
353
|
+
R,
|
|
354
|
+
a
|
|
355
|
+
)(), Q = S(u(a)), K = {};
|
|
356
|
+
N.Fragment = x, N.jsx = function(e, r, c, p, g) {
|
|
357
|
+
var k = 1e4 > v.recentlyCreatedOwnerStacks++;
|
|
358
|
+
return h(
|
|
349
359
|
e,
|
|
350
360
|
r,
|
|
351
361
|
c,
|
|
352
362
|
!1,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
363
|
+
p,
|
|
364
|
+
g,
|
|
365
|
+
k ? Error("react-stack-top-frame") : Z,
|
|
366
|
+
k ? S(u(e)) : Q
|
|
357
367
|
);
|
|
358
|
-
},
|
|
359
|
-
var
|
|
360
|
-
return
|
|
368
|
+
}, N.jsxs = function(e, r, c, p, g) {
|
|
369
|
+
var k = 1e4 > v.recentlyCreatedOwnerStacks++;
|
|
370
|
+
return h(
|
|
361
371
|
e,
|
|
362
372
|
r,
|
|
363
373
|
c,
|
|
364
374
|
!0,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
375
|
+
p,
|
|
376
|
+
g,
|
|
377
|
+
k ? Error("react-stack-top-frame") : Z,
|
|
378
|
+
k ? S(u(e)) : Q
|
|
369
379
|
);
|
|
370
380
|
};
|
|
371
|
-
}()),
|
|
381
|
+
}()), N;
|
|
372
382
|
}
|
|
373
|
-
var
|
|
374
|
-
function
|
|
375
|
-
return
|
|
383
|
+
var ne;
|
|
384
|
+
function Re() {
|
|
385
|
+
return ne || (ne = 1, process.env.NODE_ENV === "production" ? U.exports = me() : U.exports = be()), U.exports;
|
|
376
386
|
}
|
|
377
|
-
var
|
|
378
|
-
const ce = ie({}),
|
|
379
|
-
id:
|
|
387
|
+
var oe = Re();
|
|
388
|
+
const ce = ie({}), pe = () => fe(ce), Te = ({
|
|
389
|
+
id: o,
|
|
380
390
|
form: n,
|
|
381
391
|
method: f,
|
|
382
|
-
action:
|
|
392
|
+
action: u,
|
|
383
393
|
children: s,
|
|
384
|
-
onSubmit:
|
|
394
|
+
onSubmit: a = () => {
|
|
385
395
|
},
|
|
386
396
|
onInput: d = () => {
|
|
387
397
|
},
|
|
388
|
-
onChange:
|
|
398
|
+
onChange: l = () => {
|
|
389
399
|
},
|
|
390
|
-
numberFields:
|
|
391
|
-
className:
|
|
392
|
-
...
|
|
393
|
-
}) => /* @__PURE__ */
|
|
400
|
+
numberFields: b = [],
|
|
401
|
+
className: E,
|
|
402
|
+
...h
|
|
403
|
+
}) => /* @__PURE__ */ oe.jsx(ce.Provider, { value: n, children: /* @__PURE__ */ oe.jsx(
|
|
394
404
|
"form",
|
|
395
405
|
{
|
|
396
406
|
ref: n == null ? void 0 : n.ref,
|
|
397
|
-
action:
|
|
398
|
-
className:
|
|
399
|
-
onSubmit: (
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
407
|
+
action: u,
|
|
408
|
+
className: E,
|
|
409
|
+
onSubmit: (m) => {
|
|
410
|
+
m.preventDefault();
|
|
411
|
+
const R = n.actions.loadFormValues();
|
|
412
|
+
a(R);
|
|
413
|
+
},
|
|
414
|
+
onInput: (m) => {
|
|
415
|
+
d(m);
|
|
416
|
+
const R = n.actions.loadFormValues();
|
|
417
|
+
n.actions.setFormState(R);
|
|
403
418
|
},
|
|
404
|
-
onChange: (
|
|
405
|
-
const
|
|
406
|
-
n.actions.setFormState(
|
|
419
|
+
onChange: (m) => {
|
|
420
|
+
const R = n.actions.loadFormValues();
|
|
421
|
+
n.actions.setFormState(R), l(R);
|
|
407
422
|
},
|
|
408
|
-
...
|
|
423
|
+
...h,
|
|
409
424
|
children: s
|
|
410
425
|
}
|
|
411
|
-
) }),
|
|
412
|
-
const [
|
|
413
|
-
(E) => {
|
|
414
|
-
|
|
426
|
+
) }), he = ({ name: o, defaultValue: n, render: f = ({ ref: u, name: s, defaultValue: a, value: d, setValue: l }) => null }) => {
|
|
427
|
+
const [u, s] = H(n), a = pe(), d = V(), l = T(
|
|
428
|
+
(b, { shouldDirty: E = !1 } = {}) => {
|
|
429
|
+
a.actions.setFormState((h) => ({ ...h, [o]: b }), { shouldDirty: E }), s(b);
|
|
415
430
|
},
|
|
416
|
-
[s,
|
|
431
|
+
[s, a.actions.setFormState]
|
|
417
432
|
);
|
|
418
|
-
return se(() => (
|
|
419
|
-
s(
|
|
420
|
-
})), []), f({ ref: d, name:
|
|
433
|
+
return se(() => (a.actions.setFormState((E) => ({ ...E, [o]: n }), { shouldDirty: !1 }), a.subscribe(o, (E, { shouldDirty: h = !0 }) => {
|
|
434
|
+
s(E), a.actions.setFormState((m) => ({ ...m, [o]: E }), { shouldDirty: h }), d.current && typeof d.current.dispatchEvent == "function" && d.current.dispatchEvent(new Event("change"));
|
|
435
|
+
})), []), f({ ref: d, name: o, defaultValue: n, value: u, setValue: l });
|
|
421
436
|
};
|
|
422
437
|
export {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
438
|
+
he as Controller,
|
|
439
|
+
Te as Form,
|
|
440
|
+
ve as useForm,
|
|
441
|
+
Ee as useValidateForm
|
|
427
442
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(h=typeof globalThis<"u"?globalThis:h||self,r(h.Name={},h.React))})(this,function(h,r){"use strict";const se=(a,o)=>{let d=!1;return Object.keys(o).forEach(u=>{if(!(u in a)||d)return;const c=o[u],s=a[u];(typeof c=="object"||c!==s)&&(d=!0)}),d},Q=a=>!a||typeof a.checkValidity!="function"||a.checkValidity()?null:a.validationMessage,K=()=>{const[a,o]=r.useState({}),d=r.useMemo(()=>Object.values(a).filter(Boolean).length>0,[a]),u=r.useCallback((i,R)=>{o(m=>m[i]===R?m:{...m,[i]:R})},[]),c=r.useCallback(i=>{o(R=>({...R,...i}))},[]),s=r.useCallback(i=>{o(R=>R[i]?{...R,[i]:""}:R)},[]),b=r.useCallback(()=>{o({})},[]);return{isError:d,errors:a,changeError:u,changeErrors:c,clearError:s,clearErrors:b}},z={defaultValues:{},numberFields:[]},ce=(a=z)=>{const{defaultValues:o=z.defaultValues,numberFields:d=z.numberFields}=a,{changeError:u,errors:c,changeErrors:s,clearError:b,clearErrors:i,isError:R}=K(),[m,_]=r.useState(!1),E=r.useRef({}),k=r.useRef(o),O=r.useRef({}),C=r.useRef(),w=r.useCallback((n,{shouldDirty:T=!0}={})=>{let f=n;if(typeof n=="function"&&(f=n(E.current)),E.current=f,T){const F=se(E.current,k.current);F!==m&&_(F)}},[m]),Y=r.useCallback(()=>{_(!1),i();const n=O.current;Object.values(n).forEach(f=>f("")),C.current.reset(),E.current=k.current},[i]),G=r.useCallback((n,T)=>{const f=O.current;return f[n]=T,()=>f[n]=null},[]),I=r.useCallback(n=>Q(n.target),[]),M=r.useCallback(n=>n?E.current[n]:E.current,[]),L=r.useCallback(()=>k.current,[]),j=r.useCallback(()=>{setTimeout(()=>C.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),W=r.useCallback(n=>{const T=Q(n.target);T?u(n.target.name,T):u(n.target.name,null)},[u]),U=r.useCallback((n,T,{shouldDirty:f=!0}={})=>{const F=O.current;if(typeof n=="string"){const g=F[n];if(!g)throw new Error(`${n} is uncontrolled, please use Controller for it!`);g(T,{shouldDirty:f}),j()}typeof n=="object"&&(Object.entries(n).forEach(([g,J])=>{const V=F[g];if(!V)throw new Error(`${g} is uncontrolled, please use Controller for it!`);V(J,{shouldDirty:f})}),j())},[j]),P=r.useCallback(()=>{const n=Object.fromEntries(new FormData(C.current)),T=O.current;return Object.keys(T).map(f=>{n[f]=E.current[f]}),d.forEach(f=>n.hasOwnProperty(f)&&(n[f]=+n[f])),n},[]),X=r.useMemo(()=>({setValue:U,instantChange:j,getDefaultValues:L,getFormState:M,setFormState:w,changeError:u,changeErrors:s,clearError:b,clearErrors:i,loadFormValues:P,checkValidity:W,getFieldValidity:I,reset:Y}),[U,j,L,M,w,u,s,b,P,I,W,Y]);return r.useEffect(()=>{if(C.current){const n=P();k.current={...n,...o},E.current={...n,...o}}},[]),{ref:C,isDirty:m,isError:R,errors:c,numberFields:d,subscribe:G,actions:X}};var D={exports:{}},x={};/**
|
|
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 q;function le(){if(q)return x;q=1;var a=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function d(u,c,s){var b=null;if(s!==void 0&&(b=""+s),c.key!==void 0&&(b=""+c.key),"key"in c){s={};for(var i in c)i!=="key"&&(s[i]=c[i])}else s=c;return c=s.ref,{$$typeof:a,type:u,key:b,ref:c!==void 0?c:null,props:s}}return x.Fragment=o,x.jsx=d,x.jsxs=d,x}var N={};/**
|
|
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 $;function ue(){return $||($=1,process.env.NODE_ENV!=="production"&&function(){function a(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===n?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case w:return"Fragment";case G:return"Profiler";case Y:return"StrictMode";case j:return"Suspense";case W:return"SuspenseList";case X: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 C:return"Portal";case M:return(e.displayName||"Context")+".Provider";case I:return(e._context.displayName||"Context")+".Consumer";case L:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case U:return t=e.displayName||null,t!==null?t:a(e.type)||"Memo";case P:t=e._payload,e=e._init;try{return a(e(t))}catch{}}return null}function o(e){return""+e}function d(e){try{o(e);var t=!1}catch{t=!0}if(t){t=console;var l=t.error,p=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.",p),o(e)}}function u(e){if(e===w)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===P)return"<...>";try{var t=a(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function c(){var e=T.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function b(e){if(f.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function i(e,t){function l(){J||(J=!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=a(this.type);return V[e]||(V[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,p,y,S,B,H){return l=S.ref,e={$$typeof:O,type:e,key:t,props:S,_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:B}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:H}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function _(e,t,l,p,y,S,B,H){var v=t.children;if(v!==void 0)if(p)if(F(v)){for(p=0;p<v.length;p++)E(v[p]);Object.freeze&&Object.freeze(v)}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 E(v);if(f.call(t,"key")){v=a(e);var A=Object.keys(t).filter(function(me){return me!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",ae[v+p]||(A=0<A.length?"{"+A.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} />`,
|
|
22
|
+
<%s key={someKey} {...props} />`,p,v,A,v),ae[v+p]=!0)}if(v=null,l!==void 0&&(d(l),v=""+l),b(t)&&(d(t.key),v=""+t.key),"key"in t){l={};for(var Z in t)Z!=="key"&&(l[Z]=t[Z])}else l=t;return v&&i(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),m(e,v,S,y,c(),l,B,H)}function E(e){typeof e=="object"&&e!==null&&e.$$typeof===O&&e._store&&(e._store.validated=1)}var k=r,O=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),Y=Symbol.for("react.strict_mode"),G=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),U=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),n=Symbol.for("react.client.reference"),T=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,f=Object.prototype.hasOwnProperty,F=Array.isArray,g=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var J,V={},ne=k["react-stack-bottom-frame"].bind(k,s)(),oe=g(u(s)),ae={};N.Fragment=w,N.jsx=function(e,t,l,p,y){var S=1e4>T.recentlyCreatedOwnerStacks++;return _(e,t,l,!1,p,y,S?Error("react-stack-top-frame"):ne,S?g(u(e)):oe)},N.jsxs=function(e,t,l,p,y){var S=1e4>T.recentlyCreatedOwnerStacks++;return _(e,t,l,!0,p,y,S?Error("react-stack-top-frame"):ne,S?g(u(e)):oe)}}()),N}var ee;function ie(){return ee||(ee=1,process.env.NODE_ENV==="production"?D.exports=le():D.exports=ue()),D.exports}var te=ie();const re=r.createContext({}),fe=()=>r.useContext(re),de=({id:a,form:o,method:d,action:u,children:c,onSubmit:s=()=>{},onInput:b=()=>{},onChange:i=()=>{},numberFields:R=[],className:m,..._})=>te.jsx(re.Provider,{value:o,children:te.jsx("form",{ref:o==null?void 0:o.ref,action:u,className:m,onSubmit:E=>{E.preventDefault();const k=o.actions.loadFormValues();s(k)},onInput:E=>{b(E);const k=o.actions.loadFormValues();o.actions.setFormState(k)},onChange:E=>{const k=o.actions.loadFormValues();o.actions.setFormState(k),i(k)},..._,children:c})}),be=({name:a,defaultValue:o,render:d=({ref:u,name:c,defaultValue:s,value:b,setValue:i})=>null})=>{const[u,c]=r.useState(o),s=fe(),b=r.useRef(),i=r.useCallback((R,{shouldDirty:m=!1}={})=>{s.actions.setFormState(_=>({..._,[a]:R}),{shouldDirty:m}),c(R)},[c,s.actions.setFormState]);return r.useEffect(()=>(s.actions.setFormState(m=>({...m,[a]:o}),{shouldDirty:!1}),s.subscribe(a,(m,{shouldDirty:_=!0})=>{c(m),s.actions.setFormState(E=>({...E,[a]:m}),{shouldDirty:_}),b.current&&typeof b.current.dispatchEvent=="function"&&b.current.dispatchEvent(new Event("change"))})),[]),d({ref:b,name:a,defaultValue:o,value:u,setValue:i})};h.Controller=be,h.Form=de,h.useForm=ce,h.useValidateForm=K,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-simple-formkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react formkit",
|
|
6
6
|
"react ez formkit",
|
|
@@ -31,9 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@emotion/react": "^11.14.0",
|
|
35
|
+
"@emotion/styled": "^11.14.0",
|
|
36
|
+
"@mui/material": "^7.1.0",
|
|
37
|
+
"@mui/x-date-pickers": "^8.3.0",
|
|
34
38
|
"@vitejs/plugin-react": "^4.4.1",
|
|
39
|
+
"dayjs": "^1.11.13",
|
|
35
40
|
"react": "^19.1.0",
|
|
36
41
|
"react-dom": "^19.1.0",
|
|
42
|
+
"react-simple-formkit": "^1.0.1",
|
|
37
43
|
"vite": "^6.0.7"
|
|
38
44
|
},
|
|
39
45
|
"peerDependencies": {
|