react-simple-formkit 1.1.14 → 1.1.15
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
|
@@ -27,7 +27,7 @@ return (
|
|
|
27
27
|
<Form form={form} onSubmit={handleSubmit}>
|
|
28
28
|
<input required name="email" />
|
|
29
29
|
<input required name="password" type="password" />
|
|
30
|
-
<button type="
|
|
30
|
+
<button type="reset" disabled={!isDirty}>
|
|
31
31
|
Reset
|
|
32
32
|
</button>
|
|
33
33
|
<button type="submit" disabled={!isDirty}>
|
|
@@ -177,7 +177,8 @@ return (
|
|
|
177
177
|
|
|
178
178
|
## Default values
|
|
179
179
|
|
|
180
|
-
-
|
|
180
|
+
- Just put defaultValue in input field, this library will load it when mounted and store to compare isDirty
|
|
181
|
+
- You can also use actions.getDefaultValues() to check what is stored
|
|
181
182
|
|
|
182
183
|
```
|
|
183
184
|
const [loading, setLoading] = useState(false);
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,v,_,A,_),V[_+v]=!0)}if(_=null,i!==void 0&&(f(i),_=""+i),m(n)&&(f(n.key),_=""+n.key),"key"in n){i={};for(var H in n)H!=="key"&&(i[H]=n[H])}else i=n;return _&&l(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,_,h,O,c(),i,X,B)}function u(e){typeof e=="object"&&e!==null&&e.$$typeof===j&&e._store&&(e._store.validated=1)}var k=a,j=Symbol.for("react.transitional.element"),P=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),N=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,t=Object.prototype.hasOwnProperty,p=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var S,y={},C=k["react-stack-bottom-frame"].bind(k,s)(),J=d(b(s)),V={};Y.Fragment=g,Y.jsx=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!1,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)},Y.jsxs=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!0,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)}}()),Y}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=oe():z.exports=se()),z.exports}var ee=ce();const te=a.createContext({}),ue=()=>a.useContext(te),le=({id:o,form:r,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:l=()=>{},numberFields:E=[],className:R,...T})=>(a.useEffect(()=>r.actions.registerOnchange(l),[l]),ee.jsx(te.Provider,{value:r,children:ee.jsx("form",{ref:r==null?void 0:r.ref,action:b,className:R,onSubmit:u=>{f||u.preventDefault();const k=r.actions.loadFormValues();s(k)},onInput:u=>{if(u.target.tagName==="FORM"){const k=r.actions.loadFormValues();r.actions.setFormState(k)}else m(u)},onChange:()=>{const u=r.actions.loadFormValues();r.actions.setFormState(u)},onReset:u=>{r&&(u.preventDefault(),r.actions.reset())},...T,children:c},r==null?void 0:r.lastReloadedAt)})),ie=({name:o,defaultValue:r,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:l})=>null})=>{const[b,c]=a.useState(r),s=ue(),m=a.useRef(),l=a.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(T=>({...T,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return a.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:r}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:T=!0,shouldOnChange:u=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:T,shouldOnChange:u}),m.current&&typeof m.current.dispatchEvent=="function"&&u&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:r,value:b,setValue:l})},fe=(o,r)=>{let f=!1;return Object.keys(r).forEach(b=>{if(!(b in o)||f)return;const c=r[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},re=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ne=()=>{const[o,r]=a.useState({}),f=a.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=a.useCallback((l,E)=>{r(R=>R[l]===E?R:{...R,[l]:E})},[]),c=a.useCallback(l=>{r(E=>({...E,...l}))},[]),s=a.useCallback(l=>{r(E=>E[l]?{...E,[l]:""}:E)},[]),m=a.useCallback(()=>{r({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,r]=a.useState(),f=a.useCallback(()=>r(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:r,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ne(),[l,E]=a.useState(!1),[R,T]=de(),u=a.useRef({}),k=a.useRef({}),j=a.useRef({}),P=a.useRef(()=>{}),g=a.useRef(),I=a.useCallback((t,{shouldDirty:p=!0,shouldOnChange:d=!0}={})=>{let S=t;typeof t=="function"&&(S=t(u.current)),u.current=S;let y=l;p&&(y=fe(u.current,k.current),y!==l&&E(y)),d&&P.current(u.current)},[l]),$=a.useCallback(()=>{E(!1),s();const t=j.current;Object.keys(t).forEach(p=>{const d=t[p];d(k.current[p],{shouldDirty:!1,shouldOnChange:!1})}),g.current&&g.current.reset(),T()},[s]),G=a.useCallback((t,p)=>{const d=j.current;return d[t]=p,()=>{delete d[t],delete u.current[t],delete k.current[t]}},[]),M=a.useCallback(t=>(P.current=t,()=>P.current=()=>{})),L=a.useCallback(t=>re(t.target),[]),W=a.useCallback(t=>t?u.current[t]:u.current,[]),U=a.useCallback(()=>k.current,[]),w=a.useCallback(()=>{setTimeout(()=>g.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),x=a.useCallback(t=>{const p=re(t.target);p?r(t.target.name,p):r(t.target.name,null)},[r]),q=a.useCallback((t,p,{shouldDirty:d=!0,shouldOnChange:S=!0}={})=>{const y=j.current;switch(typeof t){case"string":{const C=y[t];if(!C)throw new Error(`${t} is uncontrolled, please use Controller for it!`);C(p,{shouldDirty:d,shouldOnChange:S}),S&&w()}break;case"object":Object.entries(t).forEach(([C,J])=>{const V=y[C];if(!V)throw new Error(`${C} is uncontrolled, please use Controller for it!`);V(J,{shouldDirty:d,shouldOnChange:S})}),S&&w();default:return}},[w]),F=a.useCallback(()=>{const t=Object.fromEntries(new FormData(g.current)),p=j.current;return Object.keys(p).map(d=>{t[d]=u.current[d]}),o.forEach(d=>t.hasOwnProperty(d)&&(t[d]=+t[d])),t},[]),N=a.useMemo(()=>({setValue:q,instantChange:w,getDefaultValues:U,getFormState:W,setFormState:I,changeError:r,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:F,checkValidity:x,getFieldValidity:L,registerOnchange:M,reload:T,reset:$}),[q,w,U,W,I,r,b,c,F,L,x,M,T,$]);return a.useEffect(()=>{if(g.current){const t=F();
|
|
22
|
+
<%s key={someKey} {...props} />`,v,_,A,_),V[_+v]=!0)}if(_=null,i!==void 0&&(f(i),_=""+i),m(n)&&(f(n.key),_=""+n.key),"key"in n){i={};for(var H in n)H!=="key"&&(i[H]=n[H])}else i=n;return _&&l(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,_,h,O,c(),i,X,B)}function u(e){typeof e=="object"&&e!==null&&e.$$typeof===j&&e._store&&(e._store.validated=1)}var k=a,j=Symbol.for("react.transitional.element"),P=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),M=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),U=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),N=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,t=Object.prototype.hasOwnProperty,p=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var S,y={},C=k["react-stack-bottom-frame"].bind(k,s)(),J=d(b(s)),V={};Y.Fragment=g,Y.jsx=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!1,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)},Y.jsxs=function(e,n,i,v,O){var h=1e4>N.recentlyCreatedOwnerStacks++;return T(e,n,i,!0,v,O,h?Error("react-stack-top-frame"):C,h?d(b(e)):J)}}()),Y}var K;function ce(){return K||(K=1,process.env.NODE_ENV==="production"?z.exports=oe():z.exports=se()),z.exports}var ee=ce();const te=a.createContext({}),ue=()=>a.useContext(te),le=({id:o,form:r,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:l=()=>{},numberFields:E=[],className:R,...T})=>(a.useEffect(()=>r.actions.registerOnchange(l),[l]),ee.jsx(te.Provider,{value:r,children:ee.jsx("form",{ref:r==null?void 0:r.ref,action:b,className:R,onSubmit:u=>{f||u.preventDefault();const k=r.actions.loadFormValues();s(k)},onInput:u=>{if(u.target.tagName==="FORM"){const k=r.actions.loadFormValues();r.actions.setFormState(k)}else m(u)},onChange:()=>{const u=r.actions.loadFormValues();r.actions.setFormState(u)},onReset:u=>{r&&(u.preventDefault(),r.actions.reset())},...T,children:c},r==null?void 0:r.lastReloadedAt)})),ie=({name:o,defaultValue:r,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:l})=>null})=>{const[b,c]=a.useState(r),s=ue(),m=a.useRef(),l=a.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(T=>({...T,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return a.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:r}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:T=!0,shouldOnChange:u=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:T,shouldOnChange:u}),m.current&&typeof m.current.dispatchEvent=="function"&&u&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:r,value:b,setValue:l})},fe=(o,r)=>{let f=!1;return Object.keys(r).forEach(b=>{if(!(b in o)||f)return;const c=r[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},re=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ne=()=>{const[o,r]=a.useState({}),f=a.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=a.useCallback((l,E)=>{r(R=>R[l]===E?R:{...R,[l]:E})},[]),c=a.useCallback(l=>{r(E=>({...E,...l}))},[]),s=a.useCallback(l=>{r(E=>E[l]?{...E,[l]:""}:E)},[]),m=a.useCallback(()=>{r({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,r]=a.useState(),f=a.useCallback(()=>r(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:r,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ne(),[l,E]=a.useState(!1),[R,T]=de(),u=a.useRef({}),k=a.useRef({}),j=a.useRef({}),P=a.useRef(()=>{}),g=a.useRef(),I=a.useCallback((t,{shouldDirty:p=!0,shouldOnChange:d=!0}={})=>{let S=t;typeof t=="function"&&(S=t(u.current)),u.current=S;let y=l;p&&(y=fe(u.current,k.current),y!==l&&E(y)),d&&P.current(u.current)},[l]),$=a.useCallback(()=>{E(!1),s();const t=j.current;Object.keys(t).forEach(p=>{const d=t[p];d(k.current[p],{shouldDirty:!1,shouldOnChange:!1})}),g.current&&g.current.reset(),T()},[s]),G=a.useCallback((t,p)=>{const d=j.current;return d[t]=p,()=>{delete d[t],delete u.current[t],delete k.current[t]}},[]),M=a.useCallback(t=>(P.current=t,()=>P.current=()=>{})),L=a.useCallback(t=>re(t.target),[]),W=a.useCallback(t=>t?u.current[t]:u.current,[]),U=a.useCallback(()=>k.current,[]),w=a.useCallback(()=>{setTimeout(()=>g.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),x=a.useCallback(t=>{const p=re(t.target);p?r(t.target.name,p):r(t.target.name,null)},[r]),q=a.useCallback((t,p,{shouldDirty:d=!0,shouldOnChange:S=!0}={})=>{const y=j.current;switch(typeof t){case"string":{const C=y[t];if(!C)throw new Error(`${t} is uncontrolled, please use Controller for it!`);C(p,{shouldDirty:d,shouldOnChange:S}),S&&w()}break;case"object":Object.entries(t).forEach(([C,J])=>{const V=y[C];if(!V)throw new Error(`${C} is uncontrolled, please use Controller for it!`);V(J,{shouldDirty:d,shouldOnChange:S})}),S&&w();default:return}},[w]),F=a.useCallback(()=>{const t=Object.fromEntries(new FormData(g.current)),p=j.current;return Object.keys(p).map(d=>{t[d]=u.current[d]}),o.forEach(d=>t.hasOwnProperty(d)&&(t[d]=+t[d])),t},[]),N=a.useMemo(()=>({setValue:q,instantChange:w,getDefaultValues:U,getFormState:W,setFormState:I,changeError:r,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:F,checkValidity:x,getFieldValidity:L,registerOnchange:M,reload:T,reset:$}),[q,w,U,W,I,r,b,c,F,L,x,M,T,$]);return a.useEffect(()=>{if(g.current){const t=F();k.current=t,u.current=t}return()=>{k.current={},u.current={},E(!1),s()}},[R]),{ref:g,lastReloadedAt:R,isDirty:l,isError:m,errors:f,numberFields:o,subscribe:G,actions:N}};exports.Controller=ie;exports.Form=le;exports.useForm=Ee;exports.useValidateForm=ne;
|
|
@@ -452,7 +452,7 @@ const se = le({}), be = () => ie(se), Te = ({
|
|
|
452
452
|
return K(() => {
|
|
453
453
|
if (h.current) {
|
|
454
454
|
const t = N();
|
|
455
|
-
|
|
455
|
+
R.current = t, c.current = t;
|
|
456
456
|
}
|
|
457
457
|
return () => {
|
|
458
458
|
R.current = {}, c.current = {}, E(!1), a();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(g,
|
|
1
|
+
(function(g,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(g=typeof globalThis<"u"?globalThis:g||self,r(g.Name={},g.React))})(this,function(g,r){"use strict";var M={exports:{}},F={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -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 $;function se(){return $||($=1,process.env.NODE_ENV!=="production"&&function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===D?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case W:return"Profiler";case L:return"StrictMode";case z:return"Suspense";case G: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 N:return"Portal";case U:return(e.displayName||"Context")+".Provider";case H:return(e._context.displayName||"Context")+".Consumer";case J:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case A:return a=e.displayName||null,a!==null?a:o(e.type)||"Memo";case V:a=e._payload,e=e._init;try{return o(e(a))}catch{}}return null}function t(e){return""+e}function f(e){try{t(e);var a=!1}catch{a=!0}if(a){a=console;var i=a.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),t(e)}}function b(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===V)return"<...>";try{var a=o(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function c(){var e=Y.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function m(e){if(
|
|
17
|
+
*/var $;function se(){return $||($=1,process.env.NODE_ENV!=="production"&&function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===D?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case W:return"Profiler";case L:return"StrictMode";case z:return"Suspense";case G: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 N:return"Portal";case U:return(e.displayName||"Context")+".Provider";case H:return(e._context.displayName||"Context")+".Consumer";case J:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case A:return a=e.displayName||null,a!==null?a:o(e.type)||"Memo";case V:a=e._payload,e=e._init;try{return o(e(a))}catch{}}return null}function t(e){return""+e}function f(e){try{t(e);var a=!1}catch{a=!0}if(a){a=console;var i=a.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),t(e)}}function b(e){if(e===S)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===V)return"<...>";try{var a=o(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function c(){var e=Y.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function m(e){if(n.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function u(e,a){function i(){h||(h=!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)",a))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function E(){var e=o(this.type);return C[e]||(C[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function R(e,a,i,p,j,y,Z,Q){return i=y.ref,e={$$typeof:w,type:e,key:a,props:y,_owner:j},(i!==void 0?i: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:Z}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function _(e,a,i,p,j,y,Z,Q){var v=a.children;if(v!==void 0)if(p)if(T(v)){for(p=0;p<v.length;p++)l(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 l(v);if(n.call(a,"key")){v=o(e);var P=Object.keys(a).filter(function(me){return me!=="key"});p=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",I[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} />`,p,v,P,v),I[v+p]=!0)}if(v=null,i!==void 0&&(f(i),v=""+i),m(a)&&(f(a.key),v=""+a.key),"key"in a){i={};for(var K in a)K!=="key"&&(i[K]=a[K])}else i=a;return v&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,v,y,j,c(),i,Z,Q)}function l(e){typeof e=="object"&&e!==null&&e.$$typeof===w&&e._store&&(e._store.validated=1)}var k=
|
|
22
|
+
<%s key={someKey} {...props} />`,p,v,P,v),I[v+p]=!0)}if(v=null,i!==void 0&&(f(i),v=""+i),m(a)&&(f(a.key),v=""+a.key),"key"in a){i={};for(var K in a)K!=="key"&&(i[K]=a[K])}else i=a;return v&&u(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,v,y,j,c(),i,Z,Q)}function l(e){typeof e=="object"&&e!==null&&e.$$typeof===w&&e._store&&(e._store.validated=1)}var k=r,w=Symbol.for("react.transitional.element"),N=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),L=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),H=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),z=Symbol.for("react.suspense"),G=Symbol.for("react.suspense_list"),A=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),X=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),Y=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,n=Object.prototype.hasOwnProperty,T=Array.isArray,d=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(e){return e()}};var h,C={},O=k["react-stack-bottom-frame"].bind(k,s)(),B=d(b(s)),I={};x.Fragment=S,x.jsx=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!1,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)},x.jsxs=function(e,a,i,p,j){var y=1e4>Y.recentlyCreatedOwnerStacks++;return _(e,a,i,!0,p,j,y?Error("react-stack-top-frame"):O,y?d(b(e)):B)}}()),x}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?M.exports=oe():M.exports=se()),M.exports}var te=ce();const re=r.createContext({}),le=()=>r.useContext(re),ue=({id:o,form:t,method:f,action:b,children:c,onSubmit:s=()=>{},onInput:m=()=>{},onChange:u=()=>{},numberFields:E=[],className:R,..._})=>(r.useEffect(()=>t.actions.registerOnchange(u),[u]),te.jsx(re.Provider,{value:t,children:te.jsx("form",{ref:t==null?void 0:t.ref,action:b,className:R,onSubmit:l=>{f||l.preventDefault();const k=t.actions.loadFormValues();s(k)},onInput:l=>{if(l.target.tagName==="FORM"){const k=t.actions.loadFormValues();t.actions.setFormState(k)}else m(l)},onChange:()=>{const l=t.actions.loadFormValues();t.actions.setFormState(l)},onReset:l=>{t&&(l.preventDefault(),t.actions.reset())},..._,children:c},t==null?void 0:t.lastReloadedAt)})),ie=({name:o,defaultValue:t,render:f=({ref:b,name:c,defaultValue:s,value:m,setValue:u})=>null})=>{const[b,c]=r.useState(t),s=le(),m=r.useRef(),u=r.useCallback((E,{shouldDirty:R=!1}={})=>{s.actions.setFormState(_=>({..._,[o]:E}),{shouldDirty:R}),c(E)},[c,s.actions.setFormState]);return r.useEffect(()=>(s.actions.setFormState(R=>({...R,[o]:t}),{shouldDirty:!1}),s.subscribe(o,(R,{shouldDirty:_=!0,shouldOnChange:l=!0}={})=>{c(R),s.actions.setFormState(k=>({...k,[o]:R}),{shouldDirty:_,shouldOnChange:l}),m.current&&typeof m.current.dispatchEvent=="function"&&l&&m.current.dispatchEvent(new Event("change"))})),[]),f({ref:m,name:o,defaultValue:t,value:b,setValue:u})},fe=(o,t)=>{let f=!1;return Object.keys(t).forEach(b=>{if(!(b in o)||f)return;const c=t[b],s=o[b];(typeof c=="object"||c!==s)&&(f=!0)}),f},ne=o=>(typeof o.setCustomValidity=="function"&&o.setCustomValidity(""),!o||typeof o.checkValidity!="function"||o.checkValidity()?null:o.validationMessage),ae=()=>{const[o,t]=r.useState({}),f=r.useMemo(()=>Object.values(o).filter(Boolean).length>0,[o]),b=r.useCallback((u,E)=>{t(R=>R[u]===E?R:{...R,[u]:E})},[]),c=r.useCallback(u=>{t(E=>({...E,...u}))},[]),s=r.useCallback(u=>{t(E=>E[u]?{...E,[u]:""}:E)},[]),m=r.useCallback(()=>{t({})},[]);return{isError:f,errors:o,changeError:b,changeErrors:c,clearError:s,clearErrors:m}},de=()=>{const[o,t]=r.useState(),f=r.useCallback(()=>t(new Date().toString()),[]);return[o,f]},be=[],Ee=({numberFields:o=be}={})=>{const{changeError:t,errors:f,changeErrors:b,clearError:c,clearErrors:s,isError:m}=ae(),[u,E]=r.useState(!1),[R,_]=de(),l=r.useRef({}),k=r.useRef({}),w=r.useRef({}),N=r.useRef(()=>{}),S=r.useRef(),L=r.useCallback((n,{shouldDirty:T=!0,shouldOnChange:d=!0}={})=>{let h=n;typeof n=="function"&&(h=n(l.current)),l.current=h;let C=u;T&&(C=fe(l.current,k.current),C!==u&&E(C)),d&&N.current(l.current)},[u]),W=r.useCallback(()=>{E(!1),s();const n=w.current;Object.keys(n).forEach(T=>{const d=n[T];d(k.current[T],{shouldDirty:!1,shouldOnChange:!1})}),S.current&&S.current.reset(),_()},[s]),H=r.useCallback((n,T)=>{const d=w.current;return d[n]=T,()=>{delete d[n],delete l.current[n],delete k.current[n]}},[]),U=r.useCallback(n=>(N.current=n,()=>N.current=()=>{})),J=r.useCallback(n=>ne(n.target),[]),z=r.useCallback(n=>n?l.current[n]:l.current,[]),G=r.useCallback(()=>k.current,[]),A=r.useCallback(()=>{setTimeout(()=>S.current.dispatchEvent(new Event("input",{bubbles:!0})))},[]),V=r.useCallback(n=>{const T=ne(n.target);T?t(n.target.name,T):t(n.target.name,null)},[t]),X=r.useCallback((n,T,{shouldDirty:d=!0,shouldOnChange:h=!0}={})=>{const C=w.current;switch(typeof n){case"string":{const O=C[n];if(!O)throw new Error(`${n} is uncontrolled, please use Controller for it!`);O(T,{shouldDirty:d,shouldOnChange:h}),h&&A()}break;case"object":Object.entries(n).forEach(([O,B])=>{const I=C[O];if(!I)throw new Error(`${O} is uncontrolled, please use Controller for it!`);I(B,{shouldDirty:d,shouldOnChange:h})}),h&&A();default:return}},[A]),D=r.useCallback(()=>{const n=Object.fromEntries(new FormData(S.current)),T=w.current;return Object.keys(T).map(d=>{n[d]=l.current[d]}),o.forEach(d=>n.hasOwnProperty(d)&&(n[d]=+n[d])),n},[]),Y=r.useMemo(()=>({setValue:X,instantChange:A,getDefaultValues:G,getFormState:z,setFormState:L,changeError:t,changeErrors:b,clearError:c,clearErrors:s,loadFormValues:D,checkValidity:V,getFieldValidity:J,registerOnchange:U,reload:_,reset:W}),[X,A,G,z,L,t,b,c,D,J,V,U,_,W]);return r.useEffect(()=>{if(S.current){const n=D();k.current=n,l.current=n}return()=>{k.current={},l.current={},E(!1),s()}},[R]),{ref:S,lastReloadedAt:R,isDirty:u,isError:m,errors:f,numberFields:o,subscribe:H,actions:Y}};g.Controller=ie,g.Form=ue,g.useForm=Ee,g.useValidateForm=ae,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|