calidation
Advanced tools
Comparing version 1.16.2 to 1.17.0
639
dist/Form.js
@@ -1,454 +0,363 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'react', 'prop-types', 'invariant', './ValidatorsContext', './FormContext', './utilities'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('react'), require('prop-types'), require('invariant'), require('./ValidatorsContext'), require('./FormContext'), require('./utilities')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.react, global.propTypes, global.invariant, global.ValidatorsContext, global.FormContext, global.utilities); | ||
global.Form = mod.exports; | ||
} | ||
})(this, function (exports, _react, _propTypes, _invariant, _ValidatorsContext, _FormContext, _utilities) { | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _react = _interopRequireWildcard(require("react")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var _propTypes = require("prop-types"); | ||
var _slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
var _invariant = _interopRequireDefault(require("invariant")); | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
var _ValidatorsContext = require("./ValidatorsContext"); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
var _FormContext = require("./FormContext"); | ||
return _arr; | ||
} | ||
var _utilities = require("./utilities"); | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
return obj; | ||
} | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
return target; | ||
}; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function _objectWithoutProperties(obj, keys) { | ||
var target = {}; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
} | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
return target; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var _createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _possibleConstructorReturn(self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var propTypes = { | ||
onChange: _propTypes.func, | ||
onReset: _propTypes.func, | ||
onSubmit: _propTypes.func, | ||
onUpdate: _propTypes.func | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var Form = function (_Component) { | ||
_inherits(Form, _Component); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function Form() { | ||
var _ref; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var _temp, _this, _ret; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
_classCallCheck(this, Form); | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Form.__proto__ || Object.getPrototypeOf(Form)).call.apply(_ref, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
_createClass(Form, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
onSubmit = _props.onSubmit, | ||
onUpdate = _props.onUpdate, | ||
rest = _objectWithoutProperties(_props, ['children', 'onSubmit', 'onUpdate']); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var formContext = _extends({}, this.getContext(), { | ||
register: this.registerSubComponent, | ||
unregister: this.unregisterSubComponent | ||
}); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
return _react2.default.createElement( | ||
'form', | ||
_extends({}, rest, { | ||
noValidate: true, | ||
onChange: this.onChange, | ||
onSubmit: this.onSubmit, | ||
onReset: this.onReset | ||
}), | ||
_react2.default.createElement( | ||
_FormContext.FormProvider, | ||
{ value: formContext }, | ||
children | ||
) | ||
); | ||
} | ||
}]); | ||
var propTypes = { | ||
onChange: _propTypes.func, | ||
onReset: _propTypes.func, | ||
onSubmit: _propTypes.func, | ||
onUpdate: _propTypes.func | ||
}; | ||
return Form; | ||
}(_react.Component); | ||
var Form = /*#__PURE__*/function (_Component) { | ||
_inherits(Form, _Component); | ||
Form.defaultProps = { | ||
onChange: function onChange(e) {}, | ||
onReset: function onReset() {}, | ||
onSubmit: function onSubmit(c) {}, | ||
onUpdate: function onUpdate(c) {} | ||
}; | ||
Form.propTypes = _extends({}, propTypes, { | ||
// ValidatorsContext | ||
validators: (0, _propTypes.shape)({}).isRequired | ||
}); | ||
var _super = _createSuper(Form); | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
function Form() { | ||
var _this; | ||
this.state = { | ||
config: {}, | ||
dirty: {}, | ||
errors: {}, | ||
fields: {}, | ||
submitted: false | ||
}; | ||
this.initialValues = {}; | ||
this.transforms = {}; | ||
_classCallCheck(this, Form); | ||
this.getContext = function () { | ||
var _state = _this2.state, | ||
dirty = _state.dirty, | ||
errors = _state.errors, | ||
fields = _state.fields, | ||
submitted = _state.submitted; | ||
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
_args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(_args)); | ||
return { | ||
dirty: dirty, | ||
errors: errors, | ||
fields: fields, | ||
isValid: Object.values(errors).every(function (error) { | ||
return error === null; | ||
}), | ||
resetAll: _this2.onReset, | ||
setError: _this2.setError, | ||
setField: _this2.setField, | ||
submit: _this2.onSubmit, | ||
submitted: submitted | ||
}; | ||
}; | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
config: {}, | ||
dirty: {}, | ||
errors: {}, | ||
fields: {}, | ||
submitted: false | ||
}); | ||
this.onChange = function (e) { | ||
_this2.props.onChange(e); | ||
_defineProperty(_assertThisInitialized(_this), "initialValues", {}); | ||
var _e$target = e.target, | ||
checked = _e$target.checked, | ||
name = _e$target.name, | ||
type = _e$target.type, | ||
value = _e$target.value; | ||
_defineProperty(_assertThisInitialized(_this), "transforms", {}); | ||
_defineProperty(_assertThisInitialized(_this), "getContext", function () { | ||
var _this$state = _this.state, | ||
dirty = _this$state.dirty, | ||
errors = _this$state.errors, | ||
fields = _this$state.fields, | ||
submitted = _this$state.submitted; | ||
return { | ||
dirty: dirty, | ||
errors: errors, | ||
fields: fields, | ||
isValid: Object.values(errors).every(function (error) { | ||
return error === null; | ||
}), | ||
resetAll: _this.onReset, | ||
setError: _this.setError, | ||
setField: _this.setField, | ||
submit: _this.onSubmit, | ||
submitted: submitted | ||
}; | ||
}); | ||
if (e.defaultPrevented || !_this2.state.config[name]) { | ||
return; | ||
} | ||
_defineProperty(_assertThisInitialized(_this), "onChange", function (e) { | ||
_this.props.onChange(e); | ||
var val = type === 'checkbox' ? checked : value; | ||
var _e$target = e.target, | ||
checked = _e$target.checked, | ||
name = _e$target.name, | ||
type = _e$target.type, | ||
value = _e$target.value; | ||
if (typeof _this2.transforms[name] === 'function') { | ||
val = _this2.transforms[name](val); | ||
} | ||
if (e.defaultPrevented || !_this.state.config[name]) { | ||
return; | ||
} | ||
_this2.setField(_defineProperty({}, name, val)); | ||
}; | ||
var val = type === 'checkbox' ? checked : value; | ||
this.onReset = function (e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
if (typeof _this.transforms[name] === 'function') { | ||
val = _this.transforms[name](val); | ||
} | ||
var _state2 = _this2.state, | ||
dirty = _state2.dirty, | ||
errors = _state2.errors, | ||
fields = _state2.fields; | ||
_this.setField(_defineProperty({}, name, val)); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "onReset", function (e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
_this2.setStateInternal({ | ||
dirty: Object.keys(dirty).reduce(function (allDirty, field) { | ||
return _extends({}, allDirty, _defineProperty({}, field, false)); | ||
}, {}), | ||
errors: Object.keys(errors).reduce(function (allErrors, field) { | ||
return _extends({}, allErrors, _defineProperty({}, field, null)); | ||
}, {}), | ||
fields: Object.keys(fields).reduce(function (allFields, field) { | ||
return _extends({}, allFields, _defineProperty({}, field, _this2.initialValues[field])); | ||
}, {}), | ||
submitted: false | ||
}, _this2.props.onReset); | ||
_this.setStateInternal(function (_ref) { | ||
var dirty = _ref.dirty, | ||
errors = _ref.errors, | ||
fields = _ref.fields; | ||
return { | ||
dirty: Object.keys(dirty).reduce(function (allDirty, field) { | ||
return _objectSpread(_objectSpread({}, allDirty), {}, _defineProperty({}, field, false)); | ||
}, {}), | ||
errors: Object.keys(errors).reduce(function (allErrors, field) { | ||
return _objectSpread(_objectSpread({}, allErrors), {}, _defineProperty({}, field, null)); | ||
}, {}), | ||
fields: Object.keys(fields).reduce(function (allFields, field) { | ||
return _objectSpread(_objectSpread({}, allFields), {}, _defineProperty({}, field, _this.initialValues[field])); | ||
}, {}), | ||
submitted: false | ||
}; | ||
}, _this.props.onReset); | ||
}); | ||
this.onSubmit = function (e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
_defineProperty(_assertThisInitialized(_this), "onSubmit", function (e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
_this2.setStateInternal({ submitted: true }, function () { | ||
_this2.props.onSubmit(_this2.getContext()); | ||
}); | ||
}; | ||
_this.setStateInternal({ | ||
submitted: true | ||
}, function () { | ||
_this.props.onSubmit(_this.getContext()); | ||
}); | ||
}); | ||
this.setError = function (diff) { | ||
_this2.setStateInternal({ | ||
errors: _extends({}, _this2.state.errors, diff) | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "setError", function (diff) { | ||
_this.setStateInternal(function (_ref2) { | ||
var errors = _ref2.errors; | ||
return { | ||
errors: _objectSpread(_objectSpread({}, errors), diff) | ||
}; | ||
}); | ||
}); | ||
this.setField = function (diff) { | ||
var _state3 = _this2.state, | ||
config = _state3.config, | ||
dirty = _state3.dirty, | ||
fields = _state3.fields; | ||
_defineProperty(_assertThisInitialized(_this), "setField", function (diff) { | ||
_this.setStateInternal(function (_ref3) { | ||
var config = _ref3.config, | ||
dirty = _ref3.dirty, | ||
fields = _ref3.fields; | ||
var allFields = _extends({}, fields, diff); | ||
var areDirty = _extends({}, dirty, Object.keys(diff).reduce(function (allDirty, field) { | ||
return _extends({}, allDirty, _defineProperty({}, field, dirty[field] || diff[field] !== _this2.initialValues[field])); | ||
}, {})); | ||
var allFields = _objectSpread(_objectSpread({}, fields), diff); | ||
_this2.setStateInternal({ | ||
dirty: areDirty, | ||
errors: _this2.validate(config, allFields, areDirty), | ||
fields: allFields | ||
}); | ||
var areDirty = _objectSpread(_objectSpread({}, dirty), Object.keys(diff).reduce(function (allDirty, field) { | ||
return _objectSpread(_objectSpread({}, allDirty), {}, _defineProperty({}, field, dirty[field] || diff[field] !== _this.initialValues[field])); | ||
}, {})); | ||
return { | ||
dirty: areDirty, | ||
errors: _this.validate(config, allFields, areDirty), | ||
fields: allFields | ||
}; | ||
}); | ||
}); | ||
this.setStateInternal = function (updater) { | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {}; | ||
_defineProperty(_assertThisInitialized(_this), "setStateInternal", function (updater) { | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {}; | ||
_this2.setState(updater, function () { | ||
callback.apply(undefined, arguments); | ||
_this.setState(updater, function () { | ||
callback.apply(void 0, arguments); | ||
_this2.props.onUpdate(_this2.getContext()); | ||
}); | ||
}; | ||
_this.props.onUpdate(_this.getContext()); | ||
}); | ||
}); | ||
this.validate = function (allConfig, allFields, areDirty) { | ||
return Object.entries(allConfig).reduce(function (allErrors, _ref2) { | ||
var _ref3 = _slicedToArray(_ref2, 2), | ||
fieldName = _ref3[0], | ||
fieldValidators = _ref3[1]; | ||
_defineProperty(_assertThisInitialized(_this), "validate", function (allConfig, allFields, areDirty) { | ||
return Object.entries(allConfig).reduce(function (allErrors, _ref4) { | ||
var _ref5 = _slicedToArray(_ref4, 2), | ||
fieldName = _ref5[0], | ||
fieldValidators = _ref5[1]; | ||
return _extends({}, allErrors, _defineProperty({}, fieldName, _this2.validateField(fieldName, fieldValidators, allFields, allErrors, areDirty))); | ||
}, {}); | ||
}; | ||
return _objectSpread(_objectSpread({}, allErrors), {}, _defineProperty({}, fieldName, _this.validateField(fieldName, fieldValidators, allFields, allErrors, areDirty))); | ||
}, {}); | ||
}); | ||
this.validateField = function (fieldName, fieldValidators, allFields, allErrors, areDirty) { | ||
var validators = _this2.props.validators; | ||
_defineProperty(_assertThisInitialized(_this), "validateField", function (fieldName, fieldValidators, allFields, allErrors, areDirty) { | ||
var validators = _this.props.validators; // if field is optional and the value doesn't pass the isRequired validator, skip all validators | ||
if (!fieldValidators.isRequired && validators.isRequired({})(allFields[fieldName]) !== null) { | ||
return null; | ||
} | ||
// if field is optional and the value doesn't pass the isRequired validator, skip all validators | ||
if (!fieldValidators.isRequired && validators.isRequired({})(allFields[fieldName]) !== null) { | ||
return null; | ||
} | ||
return Object.entries(fieldValidators).reduce(function (error, _ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2), | ||
validatorName = _ref7[0], | ||
validatorConfig = _ref7[1]; | ||
return Object.entries(fieldValidators).reduce(function (error, _ref4) { | ||
var _ref5 = _slicedToArray(_ref4, 2), | ||
validatorName = _ref5[0], | ||
validatorConfig = _ref5[1]; | ||
if (error) { | ||
return error; | ||
} | ||
if (error) { | ||
return error; | ||
} | ||
var validator = validators[validatorName]; | ||
(0, _invariant["default"])(validator, "You specified a validator that doesn't exist. You " + "specified ".concat(validatorName, ". Available validators: \n\n") + Object.keys(validators).join(',\n')); | ||
var context = { | ||
fields: allFields, | ||
errors: _objectSpread(_objectSpread({}, _this.state.errors), allErrors), | ||
isDirty: areDirty[fieldName] | ||
}; | ||
var validator = validators[validatorName]; | ||
if (typeof validatorConfig === 'function') { | ||
validatorConfig = validatorConfig(context); | ||
} | ||
(0, _invariant2.default)(validator, "You specified a validator that doesn't exist. You " + ('specified ' + validatorName + '. Available validators: \n\n') + Object.keys(validators).join(',\n')); | ||
if (typeof validatorConfig === 'string') { | ||
validatorConfig = { | ||
message: validatorConfig | ||
}; | ||
} | ||
var context = { | ||
fields: allFields, | ||
errors: _extends({}, _this2.state.errors, allErrors), | ||
isDirty: areDirty[fieldName] | ||
}; | ||
if (typeof validatorConfig.validateIf === 'function' && !validatorConfig.validateIf(context) || typeof validatorConfig.validateIf === 'boolean' && !validatorConfig.validateIf) { | ||
return null; | ||
} | ||
if (typeof validatorConfig === 'function') { | ||
validatorConfig = validatorConfig(context); | ||
} | ||
return validator(validatorConfig, context)(allFields[fieldName]); | ||
}, null); | ||
}); | ||
if (typeof validatorConfig === 'string') { | ||
validatorConfig = { message: validatorConfig }; | ||
} | ||
_defineProperty(_assertThisInitialized(_this), "registerSubComponent", function (subComponentConfig, transforms, initialValues) { | ||
_this.initialValues = _objectSpread(_objectSpread({}, _this.initialValues), initialValues); | ||
_this.transforms = _objectSpread(_objectSpread({}, _this.transforms), transforms); | ||
if (typeof validatorConfig.validateIf === 'function' && !validatorConfig.validateIf(context) || typeof validatorConfig.validateIf === 'boolean' && !validatorConfig.validateIf) { | ||
return null; | ||
} | ||
_this.setStateInternal(function (prevState) { | ||
var config = _objectSpread(_objectSpread({}, prevState.config), subComponentConfig); | ||
return validator(validatorConfig, context)(allFields[fieldName]); | ||
}, null); | ||
var dirty = _objectSpread(_objectSpread({}, prevState.dirty), Object.keys(subComponentConfig).reduce(function (allDirty, field) { | ||
return _objectSpread(_objectSpread({}, allDirty), {}, _defineProperty({}, field, false)); | ||
}, {})); | ||
var fields = _objectSpread(_objectSpread({}, prevState.fields), initialValues); | ||
return { | ||
config: config, | ||
dirty: dirty, | ||
errors: _this.validate(config, fields, dirty), | ||
fields: fields | ||
}; | ||
}); | ||
}); | ||
this.registerSubComponent = function (subComponentConfig, transforms, initialValues) { | ||
_this2.initialValues = _extends({}, _this2.initialValues, initialValues); | ||
_this2.transforms = _extends({}, _this2.transforms, transforms); | ||
_defineProperty(_assertThisInitialized(_this), "unregisterSubComponent", function (subComponentConfig) { | ||
var keys = Object.keys(subComponentConfig); | ||
_this.initialValues = (0, _utilities.removeFrom)(_this.initialValues)(keys); | ||
_this.transforms = (0, _utilities.removeFrom)(_this.transforms)(keys); | ||
_this2.setStateInternal(function (prevState) { | ||
var config = _extends({}, prevState.config, subComponentConfig); | ||
var dirty = _extends({}, prevState.dirty, Object.keys(subComponentConfig).reduce(function (allDirty, field) { | ||
return _extends({}, allDirty, _defineProperty({}, field, false)); | ||
}, {})); | ||
var fields = _extends({}, prevState.fields, initialValues); | ||
return { | ||
config: config, | ||
dirty: dirty, | ||
errors: _this2.validate(config, fields, dirty), | ||
fields: fields | ||
}; | ||
}); | ||
_this.setStateInternal(function (prevState) { | ||
var config = (0, _utilities.removeFrom)(prevState.config)(keys); | ||
var dirty = (0, _utilities.removeFrom)(prevState.dirty)(keys); | ||
var fields = (0, _utilities.removeFrom)(prevState.fields)(keys); | ||
return { | ||
config: config, | ||
dirty: dirty, | ||
errors: _this.validate(config, fields, dirty), | ||
fields: fields | ||
}; | ||
}); | ||
}); | ||
this.unregisterSubComponent = function (subComponentConfig) { | ||
var keys = Object.keys(subComponentConfig); | ||
return _this; | ||
} | ||
_this2.initialValues = (0, _utilities.removeFrom)(_this2.initialValues)(keys); | ||
_this2.transforms = (0, _utilities.removeFrom)(_this2.transforms)(keys); | ||
_createClass(Form, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
onSubmit = _this$props.onSubmit, | ||
onUpdate = _this$props.onUpdate, | ||
rest = _objectWithoutProperties(_this$props, ["children", "onSubmit", "onUpdate"]); | ||
_this2.setStateInternal(function (prevState) { | ||
var config = (0, _utilities.removeFrom)(prevState.config)(keys); | ||
var dirty = (0, _utilities.removeFrom)(prevState.dirty)(keys); | ||
var fields = (0, _utilities.removeFrom)(prevState.fields)(keys); | ||
var formContext = _objectSpread(_objectSpread({}, this.getContext()), {}, { | ||
register: this.registerSubComponent, | ||
unregister: this.unregisterSubComponent | ||
}); | ||
return { | ||
config: config, | ||
dirty: dirty, | ||
errors: _this2.validate(config, fields, dirty), | ||
fields: fields | ||
}; | ||
}); | ||
}; | ||
}; | ||
return /*#__PURE__*/_react["default"].createElement("form", _extends({}, rest, { | ||
noValidate: true, | ||
onChange: this.onChange, | ||
onSubmit: this.onSubmit, | ||
onReset: this.onReset | ||
}), /*#__PURE__*/_react["default"].createElement(_FormContext.FormProvider, { | ||
value: formContext | ||
}, children)); | ||
} | ||
}]); | ||
var FormWithValidatorsContext = (0, _ValidatorsContext.withValidators)(Form); | ||
return Form; | ||
}(_react.Component); | ||
FormWithValidatorsContext.propTypes = propTypes; | ||
_defineProperty(Form, "defaultProps", { | ||
onChange: function onChange(e) {}, | ||
onReset: function onReset() {}, | ||
onSubmit: function onSubmit(c) {}, | ||
onUpdate: function onUpdate(c) {} | ||
}); | ||
exports.default = FormWithValidatorsContext; | ||
}); | ||
_defineProperty(Form, "propTypes", _objectSpread(_objectSpread({}, propTypes), {}, { | ||
// ValidatorsContext | ||
validators: (0, _propTypes.shape)({}).isRequired | ||
})); | ||
var FormWithValidatorsContext = (0, _ValidatorsContext.withValidators)(Form); | ||
FormWithValidatorsContext.propTypes = propTypes; | ||
var _default = FormWithValidatorsContext; | ||
exports["default"] = _default; |
@@ -1,66 +0,39 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'react'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('react')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.react); | ||
global.FormContext = mod.exports; | ||
} | ||
})(this, function (exports, _react) { | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withFormContext = exports.FormConsumer = exports.FormProvider = undefined; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withFormContext = exports.FormConsumer = exports.FormProvider = void 0; | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
return target; | ||
}; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _createContext = (0, _react.createContext)({}), | ||
Consumer = _createContext.Consumer, | ||
Provider = _createContext.Provider; | ||
var _createContext = /*#__PURE__*/(0, _react.createContext)({}), | ||
Consumer = _createContext.Consumer, | ||
Provider = _createContext.Provider; | ||
var FormProvider = exports.FormProvider = Provider; | ||
var FormConsumer = exports.FormConsumer = Consumer; | ||
var FormProvider = Provider; | ||
exports.FormProvider = FormProvider; | ||
var FormConsumer = Consumer; | ||
exports.FormConsumer = FormConsumer; | ||
var withFormContext = exports.withFormContext = function withFormContext(TargetComponent) { | ||
var WithFormContext = function WithFormContext(props) { | ||
return _react2.default.createElement( | ||
Consumer, | ||
null, | ||
function (formContext) { | ||
return _react2.default.createElement(TargetComponent, _extends({}, props, formContext)); | ||
} | ||
); | ||
}; | ||
var targetName = TargetComponent.displayName || TargetComponent.name; | ||
var withFormContext = function withFormContext(TargetComponent) { | ||
var WithFormContext = function WithFormContext(props) { | ||
return /*#__PURE__*/_react["default"].createElement(Consumer, null, function (formContext) { | ||
return /*#__PURE__*/_react["default"].createElement(TargetComponent, _extends({}, props, formContext)); | ||
}); | ||
}; | ||
WithFormContext.displayName = 'withFormContext(' + targetName + ')'; | ||
var targetName = TargetComponent.displayName || TargetComponent.name; | ||
WithFormContext.displayName = "withFormContext(".concat(targetName, ")"); | ||
return WithFormContext; | ||
}; | ||
return WithFormContext; | ||
}; | ||
}); | ||
exports.withFormContext = withFormContext; |
@@ -1,83 +0,42 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'react', './Form', './Validation'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('react'), require('./Form'), require('./Validation')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.react, global.Form, global.Validation); | ||
global.FormValidation = mod.exports; | ||
} | ||
})(this, function (exports, _react, _Form, _Validation) { | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _react2 = _interopRequireDefault(_react); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _Form2 = _interopRequireDefault(_Form); | ||
var _Form = _interopRequireDefault(require("./Form")); | ||
var _Validation2 = _interopRequireDefault(_Validation); | ||
var _Validation = _interopRequireDefault(require("./Validation")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
return target; | ||
}; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _objectWithoutProperties(obj, keys) { | ||
var target = {}; | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
return target; | ||
} | ||
var FormValidation = function FormValidation(props) { | ||
var children = props.children, | ||
config = props.config, | ||
initialValues = props.initialValues, | ||
transforms = props.transforms, | ||
rest = _objectWithoutProperties(props, ["children", "config", "initialValues", "transforms"]); | ||
var FormValidation = function FormValidation(props) { | ||
var children = props.children, | ||
config = props.config, | ||
initialValues = props.initialValues, | ||
transforms = props.transforms, | ||
rest = _objectWithoutProperties(props, ['children', 'config', 'initialValues', 'transforms']); | ||
return /*#__PURE__*/_react["default"].createElement(_Form["default"], rest, /*#__PURE__*/_react["default"].createElement(_Validation["default"], { | ||
config: config, | ||
initialValues: initialValues, | ||
transforms: transforms | ||
}, children)); | ||
}; | ||
return _react2.default.createElement( | ||
_Form2.default, | ||
rest, | ||
_react2.default.createElement( | ||
_Validation2.default, | ||
{ | ||
config: config, | ||
initialValues: initialValues, | ||
transforms: transforms | ||
}, | ||
children | ||
) | ||
); | ||
}; | ||
FormValidation.propTypes = _extends({}, _Form2.default.propTypes, _Validation2.default.propTypes); | ||
exports.default = FormValidation; | ||
}); | ||
FormValidation.propTypes = _objectSpread(_objectSpread({}, _Form["default"].propTypes), _Validation["default"].propTypes); | ||
var _default = FormValidation; | ||
exports["default"] = _default; |
@@ -1,37 +0,39 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', './Form', './Validation', './FormValidation', './ValidatorsContext'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('./Form'), require('./Validation'), require('./FormValidation'), require('./ValidatorsContext')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.Form, global.Validation, global.FormValidation, global.ValidatorsContext); | ||
global.index = mod.exports; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "Form", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Form["default"]; | ||
} | ||
})(this, function (exports, _Form, _Validation, _FormValidation, _ValidatorsContext) { | ||
'use strict'; | ||
}); | ||
Object.defineProperty(exports, "Validation", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Validation["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FormValidation", { | ||
enumerable: true, | ||
get: function get() { | ||
return _FormValidation["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ValidatorsProvider", { | ||
enumerable: true, | ||
get: function get() { | ||
return _ValidatorsContext.ValidatorsProvider; | ||
} | ||
}); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ValidatorsProvider = exports.FormValidation = exports.Validation = exports.Form = undefined; | ||
var _Form = _interopRequireDefault(require("./Form")); | ||
var _Form2 = _interopRequireDefault(_Form); | ||
var _Validation = _interopRequireDefault(require("./Validation")); | ||
var _Validation2 = _interopRequireDefault(_Validation); | ||
var _FormValidation = _interopRequireDefault(require("./FormValidation")); | ||
var _FormValidation2 = _interopRequireDefault(_FormValidation); | ||
var _ValidatorsContext = require("./ValidatorsContext"); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
exports.Form = _Form2.default; | ||
exports.Validation = _Validation2.default; | ||
exports.FormValidation = _FormValidation2.default; | ||
exports.ValidatorsProvider = _ValidatorsContext.ValidatorsProvider; | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
@@ -1,108 +0,50 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports); | ||
global.utilities = mod.exports; | ||
} | ||
})(this, function (exports) { | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.removeFrom = exports.getFirstDefinedValue = void 0; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
return obj; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
return target; | ||
}; | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
var _slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
return _arr; | ||
} | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var getFirstDefinedValue = function getFirstDefinedValue() { | ||
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { | ||
values[_key] = arguments[_key]; | ||
} | ||
var getFirstDefinedValue = exports.getFirstDefinedValue = function getFirstDefinedValue() { | ||
for (var _len = arguments.length, values = Array(_len), _key = 0; _key < _len; _key++) { | ||
values[_key] = arguments[_key]; | ||
} | ||
return values.find(function (value) { | ||
return value !== undefined; | ||
}); | ||
}; | ||
return values.find(function (value) { | ||
return value !== undefined; | ||
}); | ||
}; | ||
exports.getFirstDefinedValue = getFirstDefinedValue; | ||
var removeFrom = exports.removeFrom = function removeFrom(original) { | ||
return function (keysToRemove) { | ||
return Object.entries(original).reduce(function (obj, _ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
var removeFrom = function removeFrom(original) { | ||
return function (keysToRemove) { | ||
return Object.entries(original).reduce(function (obj, _ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
return _extends({}, obj, !keysToRemove.includes(key) ? _defineProperty({}, key, value) : {}); | ||
}, {}); | ||
}; | ||
}; | ||
}); | ||
return _objectSpread(_objectSpread({}, obj), !keysToRemove.includes(key) ? _defineProperty({}, key, value) : {}); | ||
}, {}); | ||
}; | ||
}; | ||
exports.removeFrom = removeFrom; |
@@ -1,221 +0,164 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'react', 'prop-types', './FormContext', './utilities'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('react'), require('prop-types'), require('./FormContext'), require('./utilities')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.react, global.propTypes, global.FormContext, global.utilities); | ||
global.Validation = mod.exports; | ||
} | ||
})(this, function (exports, _react, _propTypes, _FormContext, _utilities) { | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var _react = _interopRequireWildcard(require("react")); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
var _propTypes = require("prop-types"); | ||
return obj; | ||
} | ||
var _FormContext = require("./FormContext"); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var _utilities = require("./utilities"); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
return target; | ||
}; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var _createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
} | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var propTypes = { | ||
children: _propTypes.func.isRequired, | ||
config: (0, _propTypes.shape)({}).isRequired, | ||
initialValues: (0, _propTypes.shape)({}), | ||
transforms: (0, _propTypes.shape)({}) | ||
}; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
var Validation = function (_Component) { | ||
_inherits(Validation, _Component); | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function Validation() { | ||
var _ref; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var _temp, _this, _ret; | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
_classCallCheck(this, Validation); | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Validation.__proto__ || Object.getPrototypeOf(Validation)).call.apply(_ref, [this].concat(args))), _this), _this.state = { | ||
isRegistered: false | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
var propTypes = { | ||
children: _propTypes.func.isRequired, | ||
config: (0, _propTypes.shape)({}).isRequired, | ||
initialValues: (0, _propTypes.shape)({}), | ||
transforms: (0, _propTypes.shape)({}) | ||
}; | ||
_createClass(Validation, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var _props = this.props, | ||
config = _props.config, | ||
initialValues = _props.initialValues, | ||
register = _props.register, | ||
transforms = _props.transforms; | ||
var Validation = /*#__PURE__*/function (_Component) { | ||
_inherits(Validation, _Component); | ||
var _super = _createSuper(Validation); | ||
register(config, transforms, Object.keys(config).reduce(function (allFields, field) { | ||
var value = (0, _utilities.getFirstDefinedValue)(initialValues[field], ''); | ||
function Validation() { | ||
var _this; | ||
if (typeof transforms[field] === 'function') { | ||
value = transforms[field](value); | ||
} | ||
_classCallCheck(this, Validation); | ||
return _extends({}, allFields, _defineProperty({}, field, value)); | ||
}, {})); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
this.setState({ isRegistered: true }); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.props.unregister(this.props.config); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
this.setState({ isRegistered: false }); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _props2 = this.props, | ||
children = _props2.children, | ||
dirty = _props2.dirty, | ||
errors = _props2.errors, | ||
fields = _props2.fields, | ||
isValid = _props2.isValid, | ||
resetAll = _props2.resetAll, | ||
setError = _props2.setError, | ||
setField = _props2.setField, | ||
submit = _props2.submit, | ||
submitted = _props2.submitted; | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
isRegistered: false | ||
}); | ||
var validationContext = { | ||
dirty: dirty, | ||
errors: errors, | ||
fields: fields, | ||
isValid: isValid, | ||
resetAll: resetAll, | ||
setError: setError, | ||
setField: setField, | ||
submit: submit, | ||
submitted: submitted | ||
}; | ||
return _this; | ||
} | ||
return this.state.isRegistered ? children(validationContext) : null; | ||
} | ||
}]); | ||
_createClass(Validation, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _this$props = this.props, | ||
config = _this$props.config, | ||
initialValues = _this$props.initialValues, | ||
register = _this$props.register, | ||
transforms = _this$props.transforms; | ||
register(config, transforms, Object.keys(config).reduce(function (allFields, field) { | ||
var value = (0, _utilities.getFirstDefinedValue)(initialValues[field], ''); | ||
return Validation; | ||
}(_react.Component); | ||
if (typeof transforms[field] === 'function') { | ||
value = transforms[field](value); | ||
} | ||
Validation.defaultProps = { | ||
errors: {}, | ||
fields: {}, | ||
initialValues: {}, | ||
transforms: {} | ||
}; | ||
Validation.propTypes = _extends({}, propTypes, { | ||
// FormContext | ||
dirty: (0, _propTypes.shape)({}).isRequired, | ||
errors: (0, _propTypes.shape)({}).isRequired, | ||
fields: (0, _propTypes.shape)({}).isRequired, | ||
isValid: _propTypes.bool.isRequired, | ||
register: _propTypes.func.isRequired, | ||
resetAll: _propTypes.func.isRequired, | ||
setError: _propTypes.func.isRequired, | ||
setField: _propTypes.func.isRequired, | ||
submit: _propTypes.func.isRequired, | ||
submitted: _propTypes.bool.isRequired, | ||
unregister: _propTypes.func.isRequired | ||
}); | ||
return _objectSpread(_objectSpread({}, allFields), {}, _defineProperty({}, field, value)); | ||
}, {})); | ||
this.setState({ | ||
isRegistered: true | ||
}); | ||
} | ||
}, { | ||
key: "componentWillUnmount", | ||
value: function componentWillUnmount() { | ||
this.props.unregister(this.props.config); | ||
this.setState({ | ||
isRegistered: false | ||
}); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this$props2 = this.props, | ||
children = _this$props2.children, | ||
dirty = _this$props2.dirty, | ||
errors = _this$props2.errors, | ||
fields = _this$props2.fields, | ||
isValid = _this$props2.isValid, | ||
resetAll = _this$props2.resetAll, | ||
setError = _this$props2.setError, | ||
setField = _this$props2.setField, | ||
submit = _this$props2.submit, | ||
submitted = _this$props2.submitted; | ||
var validationContext = { | ||
dirty: dirty, | ||
errors: errors, | ||
fields: fields, | ||
isValid: isValid, | ||
resetAll: resetAll, | ||
setError: setError, | ||
setField: setField, | ||
submit: submit, | ||
submitted: submitted | ||
}; | ||
return this.state.isRegistered ? children(validationContext) : null; | ||
} | ||
}]); | ||
return Validation; | ||
}(_react.Component); | ||
var ValidationWithFormContext = (0, _FormContext.withFormContext)(Validation); | ||
_defineProperty(Validation, "defaultProps", { | ||
errors: {}, | ||
fields: {}, | ||
initialValues: {}, | ||
transforms: {} | ||
}); | ||
ValidationWithFormContext.propTypes = propTypes; | ||
_defineProperty(Validation, "propTypes", _objectSpread(_objectSpread({}, propTypes), {}, { | ||
// FormContext | ||
dirty: (0, _propTypes.shape)({}).isRequired, | ||
errors: (0, _propTypes.shape)({}).isRequired, | ||
fields: (0, _propTypes.shape)({}).isRequired, | ||
isValid: _propTypes.bool.isRequired, | ||
register: _propTypes.func.isRequired, | ||
resetAll: _propTypes.func.isRequired, | ||
setError: _propTypes.func.isRequired, | ||
setField: _propTypes.func.isRequired, | ||
submit: _propTypes.func.isRequired, | ||
submitted: _propTypes.bool.isRequired, | ||
unregister: _propTypes.func.isRequired | ||
})); | ||
exports.default = ValidationWithFormContext; | ||
}); | ||
var ValidationWithFormContext = (0, _FormContext.withFormContext)(Validation); | ||
ValidationWithFormContext.propTypes = propTypes; | ||
var _default = ValidationWithFormContext; | ||
exports["default"] = _default; |
@@ -1,172 +0,132 @@ | ||
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(['exports', 'react', 'prop-types', 'calidators'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require('react'), require('prop-types'), require('calidators')); | ||
} else { | ||
var mod = { | ||
exports: {} | ||
}; | ||
factory(mod.exports, global.react, global.propTypes, global.calidators); | ||
global.ValidatorsContext = mod.exports; | ||
} | ||
})(this, function (exports, _react, _propTypes, _calidators) { | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withValidators = exports.ValidatorsConsumer = exports.ValidatorsProvider = undefined; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withValidators = exports.ValidatorsConsumer = exports.ValidatorsProvider = void 0; | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var _propTypes = require("prop-types"); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
var _calidators = require("calidators"); | ||
return target; | ||
}; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var _createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _possibleConstructorReturn(self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var defaultValidators = { | ||
isBlacklisted: _calidators.isBlacklisted, | ||
isEmail: _calidators.isEmail, | ||
isEqual: _calidators.isEqual, | ||
isGreaterThan: _calidators.isGreaterThan, | ||
isLessThan: _calidators.isLessThan, | ||
isRequired: _calidators.isRequired, | ||
isNumber: _calidators.isNumber, | ||
isRegexMatch: _calidators.isRegexMatch, | ||
isWhitelisted: _calidators.isWhitelisted, | ||
isMinLength: _calidators.isMinLength, | ||
isMaxLength: _calidators.isMaxLength, | ||
isExactLength: _calidators.isExactLength | ||
}; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var _createContext = (0, _react.createContext)({}), | ||
Provider = _createContext.Provider, | ||
Consumer = _createContext.Consumer; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var ValidatorsProvider = exports.ValidatorsProvider = function (_Component) { | ||
_inherits(ValidatorsProvider, _Component); | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function ValidatorsProvider() { | ||
var _ref; | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var _temp, _this, _ret; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
_classCallCheck(this, ValidatorsProvider); | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ValidatorsProvider.__proto__ || Object.getPrototypeOf(ValidatorsProvider)).call.apply(_ref, [this].concat(args))), _this), _this.state = _extends({}, _this.props.validators), _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
_createClass(ValidatorsProvider, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement( | ||
Provider, | ||
{ value: this.state }, | ||
this.props.children | ||
); | ||
} | ||
}], [{ | ||
key: 'getDerivedStateFromProps', | ||
value: function getDerivedStateFromProps(nextProps) { | ||
return nextProps.validators || null; | ||
} | ||
}]); | ||
var defaultValidators = { | ||
isBlacklisted: _calidators.isBlacklisted, | ||
isEmail: _calidators.isEmail, | ||
isEqual: _calidators.isEqual, | ||
isGreaterThan: _calidators.isGreaterThan, | ||
isLessThan: _calidators.isLessThan, | ||
isRequired: _calidators.isRequired, | ||
isNumber: _calidators.isNumber, | ||
isRegexMatch: _calidators.isRegexMatch, | ||
isWhitelisted: _calidators.isWhitelisted, | ||
isMinLength: _calidators.isMinLength, | ||
isMaxLength: _calidators.isMaxLength, | ||
isExactLength: _calidators.isExactLength | ||
}; | ||
return ValidatorsProvider; | ||
}(_react.Component); | ||
var _createContext = /*#__PURE__*/(0, _react.createContext)({}), | ||
Provider = _createContext.Provider, | ||
Consumer = _createContext.Consumer; | ||
ValidatorsProvider.defaultProps = { | ||
validators: {} | ||
}; | ||
ValidatorsProvider.propTypes = { | ||
validators: (0, _propTypes.shape)({}) | ||
}; | ||
var ValidatorsConsumer = exports.ValidatorsConsumer = Consumer; | ||
var ValidatorsProvider = /*#__PURE__*/function (_Component) { | ||
_inherits(ValidatorsProvider, _Component); | ||
var withValidators = exports.withValidators = function withValidators(TargetComponent) { | ||
var WithValidators = function WithValidators(props) { | ||
return _react2.default.createElement( | ||
Consumer, | ||
null, | ||
function (validators) { | ||
return _react2.default.createElement(TargetComponent, _extends({}, props, { | ||
validators: _extends({}, defaultValidators, validators) | ||
})); | ||
} | ||
); | ||
}; | ||
var targetName = TargetComponent.displayName || TargetComponent.name; | ||
var _super = _createSuper(ValidatorsProvider); | ||
WithValidators.displayName = 'withValidators(' + targetName + ')'; | ||
function ValidatorsProvider() { | ||
var _this; | ||
return WithValidators; | ||
}; | ||
}); | ||
_classCallCheck(this, ValidatorsProvider); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "state", _objectSpread({}, _this.props.validators)); | ||
return _this; | ||
} | ||
_createClass(ValidatorsProvider, [{ | ||
key: "render", | ||
value: function render() { | ||
return /*#__PURE__*/_react["default"].createElement(Provider, { | ||
value: this.state | ||
}, this.props.children); | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps) { | ||
return nextProps.validators || null; | ||
} | ||
}]); | ||
return ValidatorsProvider; | ||
}(_react.Component); | ||
exports.ValidatorsProvider = ValidatorsProvider; | ||
_defineProperty(ValidatorsProvider, "defaultProps", { | ||
validators: {} | ||
}); | ||
_defineProperty(ValidatorsProvider, "propTypes", { | ||
validators: (0, _propTypes.shape)({}) | ||
}); | ||
var ValidatorsConsumer = Consumer; | ||
exports.ValidatorsConsumer = ValidatorsConsumer; | ||
var withValidators = function withValidators(TargetComponent) { | ||
var WithValidators = function WithValidators(props) { | ||
return /*#__PURE__*/_react["default"].createElement(Consumer, null, function (validators) { | ||
return /*#__PURE__*/_react["default"].createElement(TargetComponent, _extends({}, props, { | ||
validators: _objectSpread(_objectSpread({}, defaultValidators), validators) | ||
})); | ||
}); | ||
}; | ||
var targetName = TargetComponent.displayName || TargetComponent.name; | ||
WithValidators.displayName = "withValidators(".concat(targetName, ")"); | ||
return WithValidators; | ||
}; | ||
exports.withValidators = withValidators; |
{ | ||
"name": "calidation", | ||
"version": "1.16.2", | ||
"version": "1.17.0", | ||
"description": "A red hot validation library for React", | ||
@@ -21,4 +21,4 @@ "main": "dist/index.js", | ||
"commit": "git-cz", | ||
"test": "jest", | ||
"test:watch": "jest --watch --coverage", | ||
"test": "jest src", | ||
"test:watch": "jest --watch --coverage src", | ||
"test:coverage": "jest --coverage", | ||
@@ -29,18 +29,17 @@ "semantic-release": "semantic-release", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-es2015-modules-umd": "^6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1", | ||
"@babel/cli": "^7.13.0", | ||
"@babel/core": "^7.13.8", | ||
"@babel/plugin-proposal-class-properties": "^7.13.0", | ||
"@babel/preset-env": "^7.13.8", | ||
"@babel/preset-react": "^7.12.13", | ||
"@testing-library/react": "^11.2.5", | ||
"commitizen": "^2.9.6", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"dom-testing-library": "^1.1.0", | ||
"husky": "^0.14.3", | ||
"jest": "^22.4.3", | ||
"jest": "^26.6.3", | ||
"prettier": "^1.11.1", | ||
"pretty-quick": "^1.4.1", | ||
"react": "^16.3.1", | ||
"react-dom": "^16.3.1", | ||
"react-testing-library": "^6.0.0", | ||
"react": "17", | ||
"react-dom": "17", | ||
"regenerator-runtime": "^0.13.7", | ||
"rimraf": "^2.6.2", | ||
@@ -51,4 +50,4 @@ "semantic-release": "^15.1.5", | ||
"peerDependencies": { | ||
"react": "^16.3.1", | ||
"react-dom": "^16.3.1" | ||
"react": "^16.3.1 || 17.x", | ||
"react-dom": "^16.3.1 || 17.x" | ||
}, | ||
@@ -55,0 +54,0 @@ "files": [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
91421
18
11
1363
1