react-mui-form-validator 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tsconfig.json CHANGED
@@ -1,27 +1,26 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es6",
4
- "lib": [
5
- "dom",
6
- "dom.iterable",
7
- "esnext"
8
- ],
9
- "allowJs": true,
10
- "skipLibCheck": true,
3
+ "module": "commonjs",
4
+ "target": "es2022",
5
+
6
+ "strict": true,
11
7
  "esModuleInterop": true,
12
- "allowSyntheticDefaultImports": true,
13
- "strict": false,
8
+ "skipLibCheck": true,
14
9
  "forceConsistentCasingInFileNames": true,
10
+
11
+ "lib": ["es2022", "dom", "dom.iterable", "esnext"],
12
+ "allowJs": true,
13
+ "allowSyntheticDefaultImports": true,
15
14
  "noFallthroughCasesInSwitch": true,
16
- "module": "esnext",
15
+
16
+ "outDir": "dist",
17
+ "declaration": true,
17
18
  "moduleResolution": "node",
18
19
  "resolveJsonModule": true,
19
20
  "isolatedModules": true,
20
21
  "noEmit": true,
21
- "jsx": "react-jsx",
22
- "baseUrl": "src"
22
+ "jsx": "react"
23
23
  },
24
- "include": [
25
- "src"
26
- ]
27
- }
24
+
25
+ "include": ["src/**/*"]
26
+ }
package/.eslintrc.js DELETED
@@ -1,29 +0,0 @@
1
- module.exports = {
2
- env: {
3
- browser: true,
4
- es2021: true,
5
- },
6
- extends: 'airbnb',
7
- overrides: [
8
- {
9
- env: {
10
- node: true,
11
- },
12
- files: [
13
- '.eslintrc.{js,cjs}',
14
- ],
15
- parserOptions: {
16
- sourceType: 'script',
17
- },
18
- },
19
- ],
20
- parserOptions: {
21
- ecmaVersion: 'latest',
22
- sourceType: 'module',
23
- },
24
- rules: {
25
- },
26
- compilerOptions: {
27
- "module": "esnext"
28
- }
29
- };
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
10
- var _ValidatorComponent2 = _interopRequireDefault(require("utils/ui/validator/ValidatorComponent"));
11
- var _excluded = ["error", "errorMessages", "validators", "requiredError", "helperText", "validatorListener", "withRequiredValidator", "containerProps"];
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
- function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
14
- 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; }
15
- 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; }
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
- 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, _toPropertyKey(descriptor.key), descriptor); } }
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
- 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); }; }
24
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
- 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; } }
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
- var TextValidator = /*#__PURE__*/function (_ValidatorComponent) {
29
- _inherits(TextValidator, _ValidatorComponent);
30
- var _super = _createSuper(TextValidator);
31
- function TextValidator() {
32
- _classCallCheck(this, TextValidator);
33
- return _super.apply(this, arguments);
34
- }
35
- _createClass(TextValidator, [{
36
- key: "renderValidatorComponent",
37
- value: function renderValidatorComponent() {
38
- var _this$props = this.props,
39
- error = _this$props.error,
40
- errorMessages = _this$props.errorMessages,
41
- validators = _this$props.validators,
42
- requiredError = _this$props.requiredError,
43
- helperText = _this$props.helperText,
44
- validatorListener = _this$props.validatorListener,
45
- withRequiredValidator = _this$props.withRequiredValidator,
46
- containerProps = _this$props.containerProps,
47
- rest = _objectWithoutProperties(_this$props, _excluded);
48
- var isValid = this.state.isValid;
49
- return /*#__PURE__*/_react["default"].createElement(_TextField["default"], _extends({}, rest, {
50
- error: !isValid || error,
51
- helperText: !isValid && this.getErrorMessage() || helperText
52
- }));
53
- }
54
- }]);
55
- return TextValidator;
56
- }(_ValidatorComponent2["default"]);
57
- exports["default"] = TextValidator;
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
10
- var _index = require("utils/ui/validator/index");
11
- var _excluded = ["error", "errorMessages", "validators", "requiredError", "helperText", "validatorListener", "withRequiredValidator", "containerProps"];
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
- function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
14
- 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; }
15
- 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; }
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
- 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, _toPropertyKey(descriptor.key), descriptor); } }
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
- 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); }; }
24
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
- 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; } }
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
- var SelectValidator = /*#__PURE__*/function (_ValidatorComponent) {
29
- _inherits(SelectValidator, _ValidatorComponent);
30
- var _super = _createSuper(SelectValidator);
31
- function SelectValidator() {
32
- _classCallCheck(this, SelectValidator);
33
- return _super.apply(this, arguments);
34
- }
35
- _createClass(SelectValidator, [{
36
- key: "renderValidatorComponent",
37
- value: function renderValidatorComponent() {
38
- var _this$props = this.props,
39
- error = _this$props.error,
40
- errorMessages = _this$props.errorMessages,
41
- validators = _this$props.validators,
42
- requiredError = _this$props.requiredError,
43
- helperText = _this$props.helperText,
44
- validatorListener = _this$props.validatorListener,
45
- withRequiredValidator = _this$props.withRequiredValidator,
46
- containerProps = _this$props.containerProps,
47
- rest = _objectWithoutProperties(_this$props, _excluded);
48
- var isValid = this.state.isValid;
49
- return /*#__PURE__*/_react["default"].createElement(_TextField["default"], _extends({}, rest, {
50
- select: true,
51
- error: !isValid || error,
52
- helperText: !isValid && this.getErrorMessage() || helperText
53
- }));
54
- }
55
- }]);
56
- return SelectValidator;
57
- }(_index.ValidatorComponent);
58
- exports["default"] = SelectValidator;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _implementation = _interopRequireDefault(require("./implementation"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- // @flow
11
- var _default = _react["default"].createContext || _implementation["default"];
12
- exports["default"] = _default;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.debounce = void 0;
7
- var debounce = function debounce(func, wait, immediate) {
8
- var timeout;
9
- function cancel() {
10
- if (timeout !== undefined) {
11
- clearTimeout(timeout);
12
- }
13
- }
14
- var debounced = function debounced() {
15
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
- args[_key] = arguments[_key];
17
- }
18
- var context = this;
19
- var later = function delayed() {
20
- timeout = null;
21
- if (!immediate) {
22
- func.apply(context, args);
23
- }
24
- };
25
- var callNow = immediate && !timeout;
26
- clearTimeout(timeout);
27
- timeout = setTimeout(later, wait);
28
- if (callNow) {
29
- func.apply(context, args);
30
- }
31
- };
32
- debounced.cancel = cancel;
33
- return debounced;
34
- };
35
- exports.debounce = debounce;
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- var isExisty = function isExisty(value) {
4
- return value !== null && value !== undefined;
5
- };
6
- var _isEmpty = function isEmpty(value) {
7
- if (value instanceof Array) {
8
- return value.length === 0;
9
- }
10
- return value === '' || !isExisty(value);
11
- };
12
- var isEmptyTrimed = function isEmptyTrimed(value) {
13
- if (typeof value === 'string') {
14
- return value.trim() === '';
15
- }
16
- return true;
17
- };
18
- var validations = {
19
- matchRegexp: function matchRegexp(value, regexp) {
20
- var validationRegexp = regexp instanceof RegExp ? regexp : new RegExp(regexp);
21
- return _isEmpty(value) || validationRegexp.test(value);
22
- },
23
- // eslint-disable-next-line
24
- isEmail: function isEmail(value) {
25
- return validations.matchRegexp(value, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i);
26
- },
27
- isEmpty: function isEmpty(value) {
28
- return _isEmpty(value);
29
- },
30
- required: function required(value) {
31
- return !_isEmpty(value);
32
- },
33
- trim: function trim(value) {
34
- return !isEmptyTrimed(value);
35
- },
36
- isNumber: function isNumber(value) {
37
- return validations.matchRegexp(value, /^-?[0-9]\d*(\d+)?$/i);
38
- },
39
- isFloat: function isFloat(value) {
40
- return validations.matchRegexp(value, /^(?:-?[1-9]\d*|-?0)?(?:\.\d+)?$/i);
41
- },
42
- isPositive: function isPositive(value) {
43
- if (isExisty(value)) {
44
- return (validations.isNumber(value) || validations.isFloat(value)) && value >= 0;
45
- }
46
- return true;
47
- },
48
- maxNumber: function maxNumber(value, max) {
49
- return _isEmpty(value) || parseInt(value, 10) <= parseInt(max, 10);
50
- },
51
- minNumber: function minNumber(value, min) {
52
- return _isEmpty(value) || parseInt(value, 10) >= parseInt(min, 10);
53
- },
54
- maxFloat: function maxFloat(value, max) {
55
- return _isEmpty(value) || parseFloat(value) <= parseFloat(max);
56
- },
57
- minFloat: function minFloat(value, min) {
58
- return _isEmpty(value) || parseFloat(value) >= parseFloat(min);
59
- },
60
- isString: function isString(value) {
61
- return _isEmpty(value) || typeof value === 'string' || value instanceof String;
62
- },
63
- minStringLength: function minStringLength(value, length) {
64
- return validations.isString(value) && value.length >= length;
65
- },
66
- maxStringLength: function maxStringLength(value, length) {
67
- return validations.isString(value) && value.length <= length;
68
- },
69
- // eslint-disable-next-line no-undef
70
- isFile: function isFile(value) {
71
- return _isEmpty(value) || value instanceof File;
72
- },
73
- maxFileSize: function maxFileSize(value, max) {
74
- return _isEmpty(value) || validations.isFile(value) && value.size <= parseInt(max, 10);
75
- },
76
- allowedExtensions: function allowedExtensions(value, fileTypes) {
77
- return _isEmpty(value) || validations.isFile(value) && fileTypes.split(',').indexOf(value.type) !== -1;
78
- }
79
- };
80
- module.exports = validations;
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _promisePolyfill = _interopRequireDefault(require("promise-polyfill"));
10
- var _reactLifecyclesCompat = require("react-lifecycles-compat");
11
- var _ValidatorForm = _interopRequireWildcard(require("./ValidatorForm"));
12
- var _utils = require("../utils/utils");
13
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
- 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, _toPropertyKey(descriptor.key), descriptor); } }
19
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
21
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
- 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); }; }
23
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
24
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
- 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; } }
26
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
29
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-enable */
30
- var ValidatorComponent = /*#__PURE__*/function (_React$Component) {
31
- _inherits(ValidatorComponent, _React$Component);
32
- var _super = _createSuper(ValidatorComponent);
33
- function ValidatorComponent() {
34
- var _this;
35
- _classCallCheck(this, ValidatorComponent);
36
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37
- args[_key] = arguments[_key];
38
- }
39
- _this = _super.call.apply(_super, [this].concat(args));
40
- _defineProperty(_assertThisInitialized(_this), "state", {
41
- isValid: true,
42
- value: _this.props.value,
43
- errorMessages: _this.props.errorMessages,
44
- validators: _this.props.validators
45
- });
46
- _defineProperty(_assertThisInitialized(_this), "getErrorMessage", function () {
47
- var errorMessages = _this.state.errorMessages;
48
- var type = _typeof(errorMessages);
49
- if (type === 'string') {
50
- return errorMessages;
51
- } else if (type === 'object') {
52
- if (_this.invalid.length > 0) {
53
- return errorMessages[_this.invalid[0]];
54
- }
55
- }
56
- // eslint-disable-next-line
57
- console.log('unknown errorMessages type', errorMessages);
58
- return true;
59
- });
60
- _defineProperty(_assertThisInitialized(_this), "instantValidate", true);
61
- _defineProperty(_assertThisInitialized(_this), "invalid", []);
62
- _defineProperty(_assertThisInitialized(_this), "configure", function () {
63
- _this.form.attachToForm(_assertThisInitialized(_this));
64
- _this.instantValidate = _this.form.instantValidate;
65
- _this.debounceTime = _this.form.debounceTime;
66
- _this.validateDebounced = (0, _utils.debounce)(_this.validate, _this.debounceTime);
67
- });
68
- _defineProperty(_assertThisInitialized(_this), "validate", function (value) {
69
- var includeRequired = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
70
- var dryRun = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
71
- var validations = _promisePolyfill["default"].all(_this.state.validators.map(function (validator) {
72
- return _ValidatorForm["default"].getValidator(validator, value, includeRequired);
73
- }));
74
- return validations.then(function (results) {
75
- _this.invalid = [];
76
- var valid = true;
77
- results.forEach(function (result, key) {
78
- if (!result) {
79
- valid = false;
80
- _this.invalid.push(key);
81
- }
82
- });
83
- if (!dryRun) {
84
- _this.setState({
85
- isValid: valid
86
- }, function () {
87
- _this.props.validatorListener(_this.state.isValid);
88
- });
89
- }
90
- return valid;
91
- });
92
- });
93
- _defineProperty(_assertThisInitialized(_this), "isValid", function () {
94
- return _this.state.isValid;
95
- });
96
- _defineProperty(_assertThisInitialized(_this), "makeInvalid", function () {
97
- _this.setState({
98
- isValid: false
99
- });
100
- });
101
- _defineProperty(_assertThisInitialized(_this), "makeValid", function () {
102
- _this.setState({
103
- isValid: true
104
- });
105
- });
106
- _defineProperty(_assertThisInitialized(_this), "renderComponent", function (form) {
107
- if (!_this.form) {
108
- _this.form = form;
109
- }
110
- return _this.renderValidatorComponent();
111
- });
112
- return _this;
113
- }
114
- _createClass(ValidatorComponent, [{
115
- key: "componentDidMount",
116
- value: function componentDidMount() {
117
- this.configure();
118
- }
119
- }, {
120
- key: "shouldComponentUpdate",
121
- value: function shouldComponentUpdate(nextProps, nextState) {
122
- return this.state !== nextState || this.props !== nextProps;
123
- }
124
- }, {
125
- key: "componentDidUpdate",
126
- value: function componentDidUpdate(prevProps, prevState) {
127
- if (this.instantValidate && this.props.value !== prevState.value) {
128
- this.validateDebounced(this.props.value, this.props.withRequiredValidator);
129
- }
130
- }
131
- }, {
132
- key: "componentWillUnmount",
133
- value: function componentWillUnmount() {
134
- this.form.detachFromForm(this);
135
- this.validateDebounced.cancel();
136
- }
137
- }, {
138
- key: "render",
139
- value: function render() {
140
- var _this2 = this;
141
- return /*#__PURE__*/_react["default"].createElement(_ValidatorForm.FormContext.Consumer, null, function (_ref) {
142
- var form = _ref.form;
143
- return /*#__PURE__*/_react["default"].createElement("div", _this2.props.containerProps, _this2.renderComponent(form));
144
- });
145
- }
146
- }], [{
147
- key: "getDerivedStateFromProps",
148
- value: function getDerivedStateFromProps(nextProps, prevState) {
149
- if (nextProps.validators && nextProps.errorMessages && (prevState.validators !== nextProps.validators || prevState.errorMessages !== nextProps.errorMessages)) {
150
- return {
151
- value: nextProps.value,
152
- validators: nextProps.validators,
153
- errorMessages: nextProps.errorMessages
154
- };
155
- }
156
- return {
157
- value: nextProps.value
158
- };
159
- }
160
- }]);
161
- return ValidatorComponent;
162
- }(_react["default"].Component);
163
- ValidatorComponent.propTypes = {
164
- errorMessages: _propTypes["default"].oneOfType([_propTypes["default"].array, _propTypes["default"].string]),
165
- validators: _propTypes["default"].array,
166
- value: _propTypes["default"].any,
167
- validatorListener: _propTypes["default"].func,
168
- withRequiredValidator: _propTypes["default"].bool,
169
- containerProps: _propTypes["default"].object
170
- };
171
- ValidatorComponent.defaultProps = {
172
- errorMessages: 'error',
173
- validators: [],
174
- validatorListener: function validatorListener() {}
175
- };
176
- (0, _reactLifecyclesCompat.polyfill)(ValidatorComponent);
177
- var _default = ValidatorComponent;
178
- exports["default"] = _default;