recoil-form
Advanced tools
Comparing version 0.0.3 to 0.0.4
import * as React from 'react'; | ||
import { PolymorphicComponentProps } from 'utils/types'; | ||
import { PolymorphicComponentProps } from '../utils/types'; | ||
declare const ErrorMessage: <C extends React.ElementType<any> = "small">(props: { | ||
@@ -4,0 +4,0 @@ as?: C | undefined; |
@@ -482,3 +482,3 @@ 'use strict'; | ||
{ | ||
throw new Error('`input` of type `radio` is not supported yet!'); | ||
throw new Error('`input` of type `select` is not supported yet!'); | ||
}; | ||
@@ -485,0 +485,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("recoil"),r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)t.indexOf(r=u[n])>=0||(o[r]=e[r]);return o}var a=r.createContext("");function i(){var e=r.useContext(a);if(!e)throw new Error("useFormKey is used outside of Form context");return e}var c=Symbol("FIELD_INITIAL_VAlUE"),l=t.atomFamily({key:"$recoil-form/$field/$value/$initial",default:void 0}),s=t.atomFamily({key:"$recoil-form/field/$value/$current",default:c}),f=t.selectorFamily({key:"$recoil-form/$field/$value",get:function(e){var t=l(e),r=s(e);return function(e){var n=e.get,o=n(r);return o===c?n(t):o}},set:function(e){var t=s(e);return function(e,r){var n=e.set;(0,e.get)(t)!==r&&n(t,r)}}}),m=t.atomFamily({key:"$recoil-form/$field/$refCounter",default:0}),v=t.atomFamily({key:"$recoil-form/$field/$touched",default:!1}),d=t.atomFamily({key:"$recoil-form/$field/$error/$internal",default:null}),h=t.selectorFamily({key:"$recoil-form/$field/$error",get:function(e){var t=d(e);return function(e){return(0,e.get)(t)}},set:function(e){var t=d(e);return function(e,r){var n=e.set;(0,e.get)(t)!==r&&n(t,r)}}});function y(e,t){return e+"/"+t}var g=t.atomFamily({key:"$recoil-form/$form/$state",default:"ready"}),p=t.atomFamily({key:"$recoil-form/$form/$fields",default:{}}),b=t.selectorFamily({key:"$recoil-form/$form/$values",get:function(e){return function(t){var r=t.get,n=r(p(e));return Object.fromEntries(Object.entries(n).map((function(e){return[e[1],r(f(e[0]))]})))}},set:function(e){return function(t,r){var n=t.get,o=t.set;Object.entries(r).forEach((function(t){var r=t[1],u=y(e,t[0]),a=f(u);n(a)!==r&&o(a,r)}))}}}),k=t.selectorFamily({key:"$recoil-form/$form/$errors",get:function(e){return function(t){var r=t.get,n=r(p(e));return Object.fromEntries(Object.entries(n).map((function(e){return[e[1],r(h(e[0]))]})))}},set:function(e){return function(t,r){var n=t.get,o=t.set;Object.entries(r).forEach((function(t){var r=t[1],u=y(e,t[0]),a=h(u);n(a)!==r&&o(a,r)}))}}}),E=function(e){var r=i(),u=y(r,e),a=t.useSetRecoilState(m(u)),c=t.useSetRecoilState(p(r));return n.useEffect((function(){return c((function(t){var r;return o(o({},t),{},((r={})[u]=e,r))})),a((function(e){return e+1})),function(){a((function(e){return e-1}))}}),[e,u,c,a]),y(r,e)};function C(e){var r=E(e),n=h(r);return t.useRecoilValue(n)}function $(e,n,o){var u=E(e),a=f(u),i=t.useRecoilValue(a),c=t.useSetRecoilState(l(u));return r.useEffect((function(){o&&void 0!==n&&n!==i&&c(n)}),[]),i}function F(e){var r=E(e),n=h(r);return t.useSetRecoilState(n)}function j(e){var r=E(e);return t.useSetRecoilState(f(r))}function S(e,r,o){var u=E(e),a=$(e,r,o),i=j(e),c=F(e),l=t.useSetRecoilState(v(u));return[{name:e,value:a,onBlur:n.useCallback((function(){l(!0)}),[l]),onChange:i},{},{setValue:i,setTouched:l,setError:c}]}var O=function(e){var t=e.name,n=e.defaultValue,o=e.onChange,a=e.onBlur,i=u(e,["name","defaultValue","onChange","onBlur"]),c=S(t,n,!0)[0],l=c.onChange,s=c.onBlur,f=u(c,["onChange","onBlur"]),m=r.useCallback((function(e){o&&o(e),l(e.target.value)}),[l,o]),v=r.useCallback((function(e){a&&a(e),s()}),[s,a]);return r.createElement("input",Object.assign({},i,f,{value:void 0===f.value?"":f.value,onChange:m,onBlur:v}))},x=function(e){var t=e.name,n=e.value,o=e.defaultChecked,a=void 0!==o&&o,i=e.onChange,c=e.onBlur,l=u(e,["name","value","defaultChecked","onChange","onBlur"]),s=S(t,a?n:void 0,!0)[0],f=s.onChange,m=s.onBlur,v=u(s,["onChange","onBlur"]),d=r.useCallback((function(e){i&&i(e),e.target.checked&&f(n),m()}),[f,m,i,n]),h=r.useCallback((function(e){c&&c(e),m()}),[m,c]);return r.createElement("input",Object.assign({},l,v,{type:"radio",value:JSON.stringify(n),checked:v.value===n,onChange:d,onBlur:h}))},R=function(){throw new Error("`input` of type `file` is not supported yet!")},V=function(e){var t=e.name,n=e.value,o=void 0===n||n,a=e.uncheckedValue,i=void 0===a?void 0:a,c=e.defaultChecked,l=void 0!==c&&c,s=e.onChange,f=e.onBlur,m=u(e,["name","value","uncheckedValue","defaultChecked","onChange","onBlur"]),v=S(t,l?o:i,l)[0],d=v.onChange,h=v.onBlur,y=u(v,["onChange","onBlur"]),g=r.useCallback((function(e){s&&s(e),d(e.target.checked?o:i)}),[d,s,o,i]),p=r.useCallback((function(e){f&&f(e),h()}),[h,f]);return r.createElement("input",Object.assign({},m,y,{type:"checkbox",value:void 0,checked:y.value===o,onChange:g,onBlur:p}))},B=function(){throw new Error("`input` of type `radio` is not supported yet!")},w=function(e){return void 0===e||"input"===e},P=function(e,t){return w(t)&&"checkbox"===e.type},A=function(e,t){return w(t)&&"radio"===e.type},M=0;function I(e){return e.reduce((function(e,t,r,n){return r%2==0&&e.push(n.slice(r,r+2)),e}),[])}exports.ErrorMessage=function(e){var n=e.as,o=void 0===n?"small":n,a=e.name,i=u(e,["as","name"]),c=C(a);return function(e){var r=E(e),n=v(r);return t.useRecoilValue(n)}(a)&&c?r.createElement(o,i,r.createElement(r.Fragment,null,c)):null},exports.Field=function(e){var t,n=e.as,o=void 0===n?"input":n,a=e.fallback,i=void 0===a?null:a,c=u(e,["as","fallback"]);return t=function(e,t){return e&&"select"===t}(c,o)?r.createElement(B,Object.assign({},c)):P(c,o)?r.createElement(V,Object.assign({},c)):A(c,o)?r.createElement(x,Object.assign({},c)):function(e,t){return w(t)&&"file"===e.type}(c,o)?r.createElement(R,Object.assign({},c)):function(e,t){return w(t)&&!P(e,t)&&!A(e,t)}(c,o)?r.createElement(O,Object.assign({},c)):r.createElement(o,c),r.createElement(r.Suspense,{fallback:i},t)},exports.FieldArray=function(){throw new Error("Sorry, `FieldArray` component is not implemented yet!")},exports.Form=function(e){var n=e.initialValues,o=void 0===n?{}:n,i=e.onSubmit,c=u(e,["initialValues","onSubmit"]),s=r.useMemo((function(){return""+ ++M}),[]),m=t.useSetRecoilState(b(s)),d=t.useSetRecoilState(k(s)),E=r.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=1===t.length?t[0]:Object.fromEntries(I(t));m(n)}),[m]),C=r.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=1===t.length?t[0]:Object.fromEntries(I(t));d(n)}),[d]),$=t.useRecoilCallback((function(e){var t=e.set;return function(){try{return Object.entries(o).forEach((function(e){var r=e[1],n=y(s,e[0]);t(l(n),r)})),Promise.resolve()}catch(e){return Promise.reject(e)}}}),[s]),F=t.useRecoilCallback((function(e){var t=e.snapshot,r=e.reset;return function(){try{return Promise.resolve(t.getPromise(p(s))).then((function(e){Object.keys(e).forEach((function(e){r(f(e)),r(v(e)),r(h(e))}))}))}catch(e){return Promise.reject(e)}}}),[s]),j=r.useMemo((function(){return{setErrors:C,setValues:E,resetForm:F}}),[C,E,F]),S=t.useRecoilCallback((function(e){var t=e.snapshot,r=e.set;return function(){try{return void 0===i?Promise.resolve():(r(g(s),"submitting"),Promise.resolve(t.getPromise(p(s))).then((function(e){return Object.keys(e).forEach((function(e){var t=v(e);r(t,!0)})),Promise.resolve(t.getPromise(b(s))).then((function(e){return Promise.resolve(i(e,j)).then((function(){r(g(s),"ready")}))}))})))}catch(e){return Promise.reject(e)}}}),[j,s,i]),O=r.useCallback((function(e){e.preventDefault(),S()}),[S]),x=r.useCallback((function(e){e.preventDefault(),F()}),[F]);return r.useEffect((function(){$()}),[$]),r.createElement(a.Provider,{value:s},r.createElement("form",Object.assign({},c,{onSubmit:O,onReset:x})))},exports.useErrorMessage=C,exports.useField=S,exports.useFieldArray=function(){throw new Error("Sorry, `useFieldArray` hook is not implemented yet!")},exports.useFieldError=C,exports.useFieldValue=$,exports.useForm=function(){throw new Error("Sorry, `useForm` hook is not implemented yet!")},exports.useFormState=function(){var e=i();return t.useRecoilValue(g(e))},exports.useFormValues=function(){var e=i();return t.useRecoilValue(b(e))},exports.useSetFieldError=F,exports.useSetFieldValue=j; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("recoil"),r=require("react"),n=(e=r)&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)t.indexOf(r=u[n])>=0||(o[r]=e[r]);return o}var a=r.createContext("");function i(){var e=r.useContext(a);if(!e)throw new Error("useFormKey is used outside of Form context");return e}var c=Symbol("FIELD_INITIAL_VAlUE"),l=t.atomFamily({key:"$recoil-form/$field/$value/$initial",default:void 0}),s=t.atomFamily({key:"$recoil-form/field/$value/$current",default:c}),f=t.selectorFamily({key:"$recoil-form/$field/$value",get:function(e){var t=l(e),r=s(e);return function(e){var n=e.get,o=n(r);return o===c?n(t):o}},set:function(e){var t=s(e);return function(e,r){var n=e.set;(0,e.get)(t)!==r&&n(t,r)}}}),m=t.atomFamily({key:"$recoil-form/$field/$refCounter",default:0}),v=t.atomFamily({key:"$recoil-form/$field/$touched",default:!1}),d=t.atomFamily({key:"$recoil-form/$field/$error/$internal",default:null}),h=t.selectorFamily({key:"$recoil-form/$field/$error",get:function(e){var t=d(e);return function(e){return(0,e.get)(t)}},set:function(e){var t=d(e);return function(e,r){var n=e.set;(0,e.get)(t)!==r&&n(t,r)}}});function y(e,t){return e+"/"+t}var g=t.atomFamily({key:"$recoil-form/$form/$state",default:"ready"}),p=t.atomFamily({key:"$recoil-form/$form/$fields",default:{}}),b=t.selectorFamily({key:"$recoil-form/$form/$values",get:function(e){return function(t){var r=t.get,n=r(p(e));return Object.fromEntries(Object.entries(n).map((function(e){return[e[1],r(f(e[0]))]})))}},set:function(e){return function(t,r){var n=t.get,o=t.set;Object.entries(r).forEach((function(t){var r=t[1],u=y(e,t[0]),a=f(u);n(a)!==r&&o(a,r)}))}}}),k=t.selectorFamily({key:"$recoil-form/$form/$errors",get:function(e){return function(t){var r=t.get,n=r(p(e));return Object.fromEntries(Object.entries(n).map((function(e){return[e[1],r(h(e[0]))]})))}},set:function(e){return function(t,r){var n=t.get,o=t.set;Object.entries(r).forEach((function(t){var r=t[1],u=y(e,t[0]),a=h(u);n(a)!==r&&o(a,r)}))}}}),E=function(e){var r=i(),u=y(r,e),a=t.useSetRecoilState(m(u)),c=t.useSetRecoilState(p(r));return n.useEffect((function(){return c((function(t){var r;return o(o({},t),{},((r={})[u]=e,r))})),a((function(e){return e+1})),function(){a((function(e){return e-1}))}}),[e,u,c,a]),y(r,e)};function C(e){var r=E(e),n=h(r);return t.useRecoilValue(n)}function $(e,n,o){var u=E(e),a=f(u),i=t.useRecoilValue(a),c=t.useSetRecoilState(l(u));return r.useEffect((function(){o&&void 0!==n&&n!==i&&c(n)}),[]),i}function F(e){var r=E(e),n=h(r);return t.useSetRecoilState(n)}function j(e){var r=E(e);return t.useSetRecoilState(f(r))}function S(e,r,o){var u=E(e),a=$(e,r,o),i=j(e),c=F(e),l=t.useSetRecoilState(v(u));return[{name:e,value:a,onBlur:n.useCallback((function(){l(!0)}),[l]),onChange:i},{},{setValue:i,setTouched:l,setError:c}]}var O=function(e){var t=e.name,n=e.defaultValue,o=e.onChange,a=e.onBlur,i=u(e,["name","defaultValue","onChange","onBlur"]),c=S(t,n,!0)[0],l=c.onChange,s=c.onBlur,f=u(c,["onChange","onBlur"]),m=r.useCallback((function(e){o&&o(e),l(e.target.value)}),[l,o]),v=r.useCallback((function(e){a&&a(e),s()}),[s,a]);return r.createElement("input",Object.assign({},i,f,{value:void 0===f.value?"":f.value,onChange:m,onBlur:v}))},x=function(e){var t=e.name,n=e.value,o=e.defaultChecked,a=void 0!==o&&o,i=e.onChange,c=e.onBlur,l=u(e,["name","value","defaultChecked","onChange","onBlur"]),s=S(t,a?n:void 0,!0)[0],f=s.onChange,m=s.onBlur,v=u(s,["onChange","onBlur"]),d=r.useCallback((function(e){i&&i(e),e.target.checked&&f(n),m()}),[f,m,i,n]),h=r.useCallback((function(e){c&&c(e),m()}),[m,c]);return r.createElement("input",Object.assign({},l,v,{type:"radio",value:JSON.stringify(n),checked:v.value===n,onChange:d,onBlur:h}))},R=function(){throw new Error("`input` of type `file` is not supported yet!")},V=function(e){var t=e.name,n=e.value,o=void 0===n||n,a=e.uncheckedValue,i=void 0===a?void 0:a,c=e.defaultChecked,l=void 0!==c&&c,s=e.onChange,f=e.onBlur,m=u(e,["name","value","uncheckedValue","defaultChecked","onChange","onBlur"]),v=S(t,l?o:i,l)[0],d=v.onChange,h=v.onBlur,y=u(v,["onChange","onBlur"]),g=r.useCallback((function(e){s&&s(e),d(e.target.checked?o:i)}),[d,s,o,i]),p=r.useCallback((function(e){f&&f(e),h()}),[h,f]);return r.createElement("input",Object.assign({},m,y,{type:"checkbox",value:void 0,checked:y.value===o,onChange:g,onBlur:p}))},B=function(){throw new Error("`input` of type `select` is not supported yet!")},w=function(e){return void 0===e||"input"===e},P=function(e,t){return w(t)&&"checkbox"===e.type},A=function(e,t){return w(t)&&"radio"===e.type},M=0;function I(e){return e.reduce((function(e,t,r,n){return r%2==0&&e.push(n.slice(r,r+2)),e}),[])}exports.ErrorMessage=function(e){var n=e.as,o=void 0===n?"small":n,a=e.name,i=u(e,["as","name"]),c=C(a);return function(e){var r=E(e),n=v(r);return t.useRecoilValue(n)}(a)&&c?r.createElement(o,i,r.createElement(r.Fragment,null,c)):null},exports.Field=function(e){var t,n=e.as,o=void 0===n?"input":n,a=e.fallback,i=void 0===a?null:a,c=u(e,["as","fallback"]);return t=function(e,t){return e&&"select"===t}(c,o)?r.createElement(B,Object.assign({},c)):P(c,o)?r.createElement(V,Object.assign({},c)):A(c,o)?r.createElement(x,Object.assign({},c)):function(e,t){return w(t)&&"file"===e.type}(c,o)?r.createElement(R,Object.assign({},c)):function(e,t){return w(t)&&!P(e,t)&&!A(e,t)}(c,o)?r.createElement(O,Object.assign({},c)):r.createElement(o,c),r.createElement(r.Suspense,{fallback:i},t)},exports.FieldArray=function(){throw new Error("Sorry, `FieldArray` component is not implemented yet!")},exports.Form=function(e){var n=e.initialValues,o=void 0===n?{}:n,i=e.onSubmit,c=u(e,["initialValues","onSubmit"]),s=r.useMemo((function(){return""+ ++M}),[]),m=t.useSetRecoilState(b(s)),d=t.useSetRecoilState(k(s)),E=r.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=1===t.length?t[0]:Object.fromEntries(I(t));m(n)}),[m]),C=r.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=1===t.length?t[0]:Object.fromEntries(I(t));d(n)}),[d]),$=t.useRecoilCallback((function(e){var t=e.set;return function(){try{return Object.entries(o).forEach((function(e){var r=e[1],n=y(s,e[0]);t(l(n),r)})),Promise.resolve()}catch(e){return Promise.reject(e)}}}),[s]),F=t.useRecoilCallback((function(e){var t=e.snapshot,r=e.reset;return function(){try{return Promise.resolve(t.getPromise(p(s))).then((function(e){Object.keys(e).forEach((function(e){r(f(e)),r(v(e)),r(h(e))}))}))}catch(e){return Promise.reject(e)}}}),[s]),j=r.useMemo((function(){return{setErrors:C,setValues:E,resetForm:F}}),[C,E,F]),S=t.useRecoilCallback((function(e){var t=e.snapshot,r=e.set;return function(){try{return void 0===i?Promise.resolve():(r(g(s),"submitting"),Promise.resolve(t.getPromise(p(s))).then((function(e){return Object.keys(e).forEach((function(e){var t=v(e);r(t,!0)})),Promise.resolve(t.getPromise(b(s))).then((function(e){return Promise.resolve(i(e,j)).then((function(){r(g(s),"ready")}))}))})))}catch(e){return Promise.reject(e)}}}),[j,s,i]),O=r.useCallback((function(e){e.preventDefault(),S()}),[S]),x=r.useCallback((function(e){e.preventDefault(),F()}),[F]);return r.useEffect((function(){$()}),[$]),r.createElement(a.Provider,{value:s},r.createElement("form",Object.assign({},c,{onSubmit:O,onReset:x})))},exports.useErrorMessage=C,exports.useField=S,exports.useFieldArray=function(){throw new Error("Sorry, `useFieldArray` hook is not implemented yet!")},exports.useFieldError=C,exports.useFieldValue=$,exports.useForm=function(){throw new Error("Sorry, `useForm` hook is not implemented yet!")},exports.useFormState=function(){var e=i();return t.useRecoilValue(g(e))},exports.useFormValues=function(){var e=i();return t.useRecoilValue(b(e))},exports.useSetFieldError=F,exports.useSetFieldValue=j; | ||
//# sourceMappingURL=recoil-form.cjs.production.min.js.map |
@@ -475,3 +475,3 @@ import { selectorFamily, atomFamily, useSetRecoilState, useRecoilValue, useRecoilCallback } from 'recoil'; | ||
{ | ||
throw new Error('`input` of type `radio` is not supported yet!'); | ||
throw new Error('`input` of type `select` is not supported yet!'); | ||
}; | ||
@@ -478,0 +478,0 @@ |
{ | ||
"name": "recoil-form", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Blazing fast React forms build on top of Recoil", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234570