@coreyward/validated-form
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=2)}([function(e,r){e.exports=require("prop-types")},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";t.r(r);var n=t(1),o=t.n(n),i=t(0),u=t.n(i);function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(t.push(u.value),!r||t.length!==r);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function f(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function c(e){var r=function(e,r){if("object"!==a(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"===a(r)?r:String(r)}function d(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){y(e,r,t[r])})}return e}function s(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e,r){return(b=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function y(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var m=o.a.createContext(),h=function(e){function r(){var e,t,n,o;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r);for(var i=arguments.length,u=new Array(i),s=0;s<i;s++)u[s]=arguments[s];return n=this,o=(e=p(r)).call.apply(e,[this].concat(u)),t=!o||"object"!==a(o)&&"function"!=typeof o?v(n):o,y(v(t),"state",{fields:{},submitted:!1}),y(v(t),"fields",function(){return Object.entries(t.state.fields)}),y(v(t),"addField",function(e){var r=e.name,n=e.defaultValue,o=void 0===n?"":n,i=e.validator;return t.setState(function(e){return{fields:d({},e.fields,y({},r,{value:o,error:null,validator:i}))}})}),y(v(t),"removeField",function(e){t.setState(function(r){var t=r.fields;t[e];return{fields:f(t,[e].map(c))}})}),y(v(t),"validateField",function(e,r){var n=t.state.fields[e].validator;if(!n)return!0;var o=l(n(r),2),i=o[0],u=o[1];return i?t.clearError(e):t.addError(e,u),i}),y(v(t),"validateAll",function(){return t.fields().reduce(function(e,r){var n=l(r,2),o=n[0],i=n[1];return t.validateField(o,i.value)&&e},!0)}),y(v(t),"addError",function(e,r){t.setState(function(t){return{fields:d({},t.fields,y({},e,d({},t.fields[e],{error:r})))}})}),y(v(t),"hasError",function(e){return!!t.state.fields[e].error}),y(v(t),"clearError",function(e){t.setState(function(r){return{fields:d({},r.fields,y({},e,d({},r.fields[e],{error:null})))}})}),y(v(t),"clearErrors",function(){return t.setState(function(e){return{fields:Object.entries(e.fields).reduce(function(e,r){var t=l(r,2),n=t[0],o=t[1];return e[n]=d({},o,{error:null}),e},{})}})}),y(v(t),"handleSubmit",function(e){if(!t.validateAll())return e.preventDefault(),!1;t.props.onSubmit&&(e.preventDefault(),t.setState({submitted:!!t.props.onSubmit({event:e,fields:t.state.fields,addError:t.addError,hasError:t.hasError,setField:t.setField})}))}),y(v(t),"setField",function(e,r){t.setState(function(t){return{fields:d({},t.fields,y({},e,d({},t.fields[e],{value:r})))}})}),y(v(t),"handleInputChange",function(e){var r=e.target,n=r.name,o=r.value;t.setField(n,o),t.hasError(n)&&t.validateField(n,o)}),y(v(t),"handleInputBlur",function(e){var r=e.target,n=r.name,o=r.value,i=t.props.validateEmpty;(void 0===i||i||o)&&t.validateField(n,o)}),y(v(t),"renderSuccess",function(){return t.props.renderSuccess||null}),t}var t,n,i;return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&b(e,r)}(r,o.a.Component),t=r,(n=[{key:"render",value:function(){if(this.state.submitted)return this.renderSuccess();var e=this.props.children,r={handleSubmit:this.handleSubmit,handleInputChange:this.handleInputChange,handleInputBlur:this.handleInputBlur,hasError:this.hasError,addError:this.addError,setField:this.setField,addField:this.addField,removeField:this.removeField,clearError:this.clearError,fields:this.state.fields};return o.a.createElement(m.Provider,{value:r},o.a.createElement("form",{method:"POST",onSubmit:this.handleSubmit,noValidate:!0},"function"==typeof e?e(r):e))}}])&&s(t.prototype,n),i&&s(t,i),r}();h.propTypes={onSubmit:u.a.func,renderSuccess:u.a.node,validateEmpty:u.a.bool,children:u.a.oneOfType([u.a.node,u.a.func]).isRequired};function O(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var g=function(e){var r=e.name,t=e.defaultValue,o=e.required,i=e.transformValue,u=e.validator,a=(O(e,["name","defaultValue","required","transformValue","validator"]),Object(n.useContext)(m)),l=a.handleInputChange,f=a.handleInputBlur,c=a.addField,d=a.removeField,s=a.fields[r],p=void 0===s?{}:s;return Object(n.useEffect)(function(){return c({name:r,defaultValue:t,validator:o?function(e){return function(e,r){return e.length>0?r?r(e):[!0]:[!1,"Required"]}(e,u)}:u}),function(){d(r)}},[c,d,r,u,o,t]),{errorMessage:p.error,onChange:l,onBlur:f,value:i?i(p.value||""):p.value,name:r,required:o}};g.propTypes={name:u.a.string.isRequired,defaultValue:u.a.string,required:u.a.bool,transformValue:u.a.func,validator:u.a.func};var S=g,j=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,E=function(e){return""===e||j.test(e)?[!0]:[!1,"Please provide a valid email address"]};t.d(r,"default",function(){return h}),t.d(r,"useFormField",function(){return S}),t.d(r,"validateEmail",function(){return E})}]); | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t){e.exports=require("prop-types")},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";r.r(t);var n=r(1),o=r.n(n),i=r(0),u=r.n(i);function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function f(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function c(e){var t=function(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===a(t)?t:String(t)}function d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){y(e,t,r[t])})}return e}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var m=o.a.createContext(),h=function(e){function t(){var e,r,n,o;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var i=arguments.length,u=new Array(i),s=0;s<i;s++)u[s]=arguments[s];return n=this,o=(e=p(t)).call.apply(e,[this].concat(u)),r=!o||"object"!==a(o)&&"function"!=typeof o?v(n):o,y(v(r),"state",{fields:{},submitted:!1}),y(v(r),"fields",function(){return Object.entries(r.state.fields)}),y(v(r),"addField",function(e){var t=e.name,n=e.defaultValue,o=void 0===n?"":n,i=e.validator;return r.setState(function(e){return{fields:d({},e.fields,y({},t,{value:o,error:null,validator:i}))}})}),y(v(r),"removeField",function(e){r.setState(function(t){var r=t.fields;r[e];return{fields:f(r,[e].map(c))}})}),y(v(r),"validateField",function(e,t){var n=r.state.fields[e].validator;if(!n)return!0;var o=l(n(t),2),i=o[0],u=o[1];return i?r.clearError(e):r.addError(e,u),i}),y(v(r),"validateAll",function(){return r.fields().reduce(function(e,t){var n=l(t,2),o=n[0],i=n[1];return r.validateField(o,i.value)&&e},!0)}),y(v(r),"addError",function(e,t){r.setState(function(r){return{fields:d({},r.fields,y({},e,d({},r.fields[e],{error:t})))}})}),y(v(r),"hasError",function(e){return!!r.state.fields[e].error}),y(v(r),"clearError",function(e){r.setState(function(t){return{fields:d({},t.fields,y({},e,d({},t.fields[e],{error:null})))}})}),y(v(r),"clearErrors",function(){return r.setState(function(e){return{fields:Object.entries(e.fields).reduce(function(e,t){var r=l(t,2),n=r[0],o=r[1];return e[n]=d({},o,{error:null}),e},{})}})}),y(v(r),"handleSubmit",function(e){if(!r.validateAll())return e.preventDefault(),!1;r.props.onSubmit&&(e.preventDefault(),Promise.resolve(r.props.onSubmit({event:e,fields:r.state.fields,addError:r.addError,hasError:r.hasError,setField:r.setField})).then(function(e){r.setState({submitted:e})}))}),y(v(r),"setField",function(e,t){r.setState(function(r){return{fields:d({},r.fields,y({},e,d({},r.fields[e],{value:t})))}})}),y(v(r),"handleInputChange",function(e){var t=e.target,n=t.name,o=t.value;r.setField(n,o),r.hasError(n)&&r.validateField(n,o)}),y(v(r),"handleInputBlur",function(e){var t=e.target,n=t.name,o=t.value,i=r.props.validateEmpty;(void 0===i||i||o)&&r.validateField(n,o)}),y(v(r),"renderSuccess",function(){return r.props.renderSuccess||null}),r}var r,n,i;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(t,o.a.Component),r=t,(n=[{key:"render",value:function(){if(this.state.submitted)return this.renderSuccess();var e=this.props.children,t={handleSubmit:this.handleSubmit,handleInputChange:this.handleInputChange,handleInputBlur:this.handleInputBlur,hasError:this.hasError,addError:this.addError,clearError:this.clearError,validateField:this.validateField,setField:this.setField,addField:this.addField,removeField:this.removeField,fields:this.state.fields};return o.a.createElement(m.Provider,{value:t},o.a.createElement("form",{method:"POST",onSubmit:this.handleSubmit,noValidate:!0},"function"==typeof e?e(t):e))}}])&&s(r.prototype,n),i&&s(r,i),t}();h.propTypes={onSubmit:u.a.func,renderSuccess:u.a.node,validateEmpty:u.a.bool,children:u.a.oneOfType([u.a.node,u.a.func]).isRequired};function O(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var g=function(e){var t=e.name,r=e.defaultValue,o=e.required,i=e.validator,u=(O(e,["name","defaultValue","required","validator"]),Object(n.useContext)(m)),a=u.handleInputChange,l=u.handleInputBlur,f=u.addField,c=u.removeField,d=u.fields[t],s=void 0===d?{}:d;return Object(n.useEffect)(function(){return f({name:t,defaultValue:r,validator:o?function(e){return function(e,t){return e.length>0?t?t(e):[!0]:[!1,"Required"]}(e,i)}:i}),function(){c(t)}},[f,c,t,i,o,r]),{errorMessage:s.error,onChange:a,onBlur:l,value:s.value}};g.propTypes={name:u.a.string.isRequired,defaultValue:u.a.string,required:u.a.bool,validator:u.a.func};var S=g,j=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,E=function(e){return""===e||j.test(e)?[!0]:[!1,"Please provide a valid email address"]};r.d(t,"default",function(){return h}),r.d(t,"FormContext",function(){return m}),r.d(t,"useFormField",function(){return S}),r.d(t,"validateEmail",function(){return E})}]); |
{ | ||
"name": "@coreyward/validated-form", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "React component handling form validation, submission, and success message logic.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
9196