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