react-mui-form-validator 1.0.5 → 1.0.6
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/.eslintrc.js +29 -0
- package/Readme.md +12 -23
- package/lib/components/MuiTextField.js +27 -52
- package/lib/components/{MuiCheckbox.js → MuiTextSelect.js} +34 -82
- package/lib/core/context/index.js +12 -0
- package/lib/core/utils/utils.js +35 -0
- package/lib/core/validator/ValidationRules.js +80 -0
- package/lib/core/validator/ValidatorComponent.js +178 -0
- package/lib/core/validator/ValidatorForm.js +214 -0
- package/lib/index.js +11 -0
- package/package.json +21 -18
- package/tsconfig.json +27 -0
- package/.eslintrc +0 -67
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
};
|
package/Readme.md
CHANGED
|
@@ -15,23 +15,12 @@ Some rules can accept extra parameter, example:
|
|
|
15
15
|
|
|
16
16
|
TextField
|
|
17
17
|
```javascript
|
|
18
|
-
<
|
|
18
|
+
<TextFieldValidator
|
|
19
19
|
{...someProps}
|
|
20
20
|
validators={["minNumber:0", "maxNumber:255", "matchRegexp:^[0-9]$"]}
|
|
21
21
|
/>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Checkbox
|
|
25
|
-
```javascript
|
|
26
|
-
<MuiCheckbox
|
|
27
|
-
{...someProps}
|
|
28
|
-
validators={["required"]}
|
|
29
|
-
errorMessages={["this checkbox is required"]}
|
|
30
|
-
checked={value}
|
|
31
|
-
value={value}
|
|
32
|
-
/>
|
|
33
|
-
```
|
|
34
|
-
|
|
35
24
|
### Usage Example
|
|
36
25
|
|
|
37
26
|
You can pass any props of field components, but note that `errorText` prop will be replaced when validation errors occurred.
|
|
@@ -40,7 +29,7 @@ Your component must [provide a theme](http://www.material-ui.com/#/get-started/u
|
|
|
40
29
|
```javascript
|
|
41
30
|
import React from "react";
|
|
42
31
|
import Button from "@mui/material/Button";
|
|
43
|
-
import {
|
|
32
|
+
import { FormValidator, TextFieldValidator } from "react-mui-form-validator";
|
|
44
33
|
|
|
45
34
|
class MyForm extends React.Component {
|
|
46
35
|
state = {
|
|
@@ -59,11 +48,11 @@ class MyForm extends React.Component {
|
|
|
59
48
|
render() {
|
|
60
49
|
const { email } = this.state;
|
|
61
50
|
return (
|
|
62
|
-
<
|
|
51
|
+
<FormValidator
|
|
63
52
|
onSubmit={this.handleSubmit}
|
|
64
53
|
onError={(errors) => console.log(errors)}
|
|
65
54
|
>
|
|
66
|
-
<
|
|
55
|
+
<TextFieldValidator
|
|
67
56
|
label="Email"
|
|
68
57
|
onChange={this.handleChange}
|
|
69
58
|
name="email"
|
|
@@ -72,7 +61,7 @@ class MyForm extends React.Component {
|
|
|
72
61
|
errorMessages={["this field is required", "email is not valid"]}
|
|
73
62
|
/>
|
|
74
63
|
<Button type="submit">Submit</Button>
|
|
75
|
-
</
|
|
64
|
+
</FormValidator>
|
|
76
65
|
);
|
|
77
66
|
}
|
|
78
67
|
}
|
|
@@ -84,7 +73,7 @@ You can add your custom rules:
|
|
|
84
73
|
|
|
85
74
|
import React from 'react';
|
|
86
75
|
import Button from '@mui/material/Button';
|
|
87
|
-
import {
|
|
76
|
+
import { FormValidator, TextFieldValidator} from 'react-mui-form-validator';
|
|
88
77
|
|
|
89
78
|
class ResetPasswordForm extends React.Component {
|
|
90
79
|
|
|
@@ -97,7 +86,7 @@ class ResetPasswordForm extends React.Component {
|
|
|
97
86
|
|
|
98
87
|
componentDidMount() {
|
|
99
88
|
// custom rule will have name 'isPasswordMatch'
|
|
100
|
-
|
|
89
|
+
FormValidator.addValidationRule('isPasswordMatch', (value) => {
|
|
101
90
|
if (value !== this.state.user.password) {
|
|
102
91
|
return false;
|
|
103
92
|
}
|
|
@@ -107,7 +96,7 @@ class ResetPasswordForm extends React.Component {
|
|
|
107
96
|
|
|
108
97
|
componentWillUnmount() {
|
|
109
98
|
// remove rule when it is not needed
|
|
110
|
-
|
|
99
|
+
FormValidator.removeValidationRule('isPasswordMatch');
|
|
111
100
|
}
|
|
112
101
|
|
|
113
102
|
handleChange = (event) => {
|
|
@@ -124,10 +113,10 @@ class ResetPasswordForm extends React.Component {
|
|
|
124
113
|
const { user } = this.state;
|
|
125
114
|
|
|
126
115
|
return (
|
|
127
|
-
<
|
|
116
|
+
<FormValidator
|
|
128
117
|
onSubmit={this.handleSubmit}
|
|
129
118
|
>
|
|
130
|
-
<
|
|
119
|
+
<TextFieldValidator
|
|
131
120
|
label="Password"
|
|
132
121
|
onChange={this.handleChange}
|
|
133
122
|
name="password"
|
|
@@ -136,7 +125,7 @@ class ResetPasswordForm extends React.Component {
|
|
|
136
125
|
errorMessages={['this field is required']}
|
|
137
126
|
value={user.password}
|
|
138
127
|
/>
|
|
139
|
-
<
|
|
128
|
+
<TextFieldValidator
|
|
140
129
|
label="Repeat password"
|
|
141
130
|
onChange={this.handleChange}
|
|
142
131
|
name="repeatPassword"
|
|
@@ -146,7 +135,7 @@ class ResetPasswordForm extends React.Component {
|
|
|
146
135
|
value={user.repeatPassword}
|
|
147
136
|
/>
|
|
148
137
|
<Button type="submit">Submit</Button>
|
|
149
|
-
</
|
|
138
|
+
</FormValidator>
|
|
150
139
|
);
|
|
151
140
|
}
|
|
152
141
|
|
|
@@ -1,73 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
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
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
|
|
13
|
-
|
|
14
|
-
var _MuiComponent2 = _interopRequireDefault(require("../core/MuiComponent"));
|
|
15
|
-
|
|
10
|
+
var _ValidatorComponent2 = _interopRequireDefault(require("utils/ui/validator/ValidatorComponent"));
|
|
16
11
|
var _excluded = ["error", "errorMessages", "validators", "requiredError", "helperText", "validatorListener", "withRequiredValidator", "containerProps"];
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
-
|
|
20
|
-
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); }
|
|
21
|
-
|
|
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); }
|
|
22
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; }
|
|
23
|
-
|
|
24
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; }
|
|
25
|
-
|
|
26
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
|
-
|
|
28
|
-
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); } }
|
|
29
|
-
|
|
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); } }
|
|
30
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; }
|
|
31
|
-
|
|
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); }
|
|
32
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); }
|
|
33
|
-
|
|
34
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
-
|
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
36
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); }; }
|
|
37
|
-
|
|
38
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); }
|
|
39
|
-
|
|
40
25
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
-
|
|
42
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; } }
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var _super = _createSuper(MuiTextField);
|
|
50
|
-
|
|
51
|
-
function MuiTextField() {
|
|
52
|
-
_classCallCheck(this, MuiTextField);
|
|
53
|
-
|
|
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);
|
|
54
33
|
return _super.apply(this, arguments);
|
|
55
34
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
value: function renderMuiComponent() {
|
|
35
|
+
_createClass(TextValidator, [{
|
|
36
|
+
key: "renderValidatorComponent",
|
|
37
|
+
value: function renderValidatorComponent() {
|
|
60
38
|
var _this$props = this.props,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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);
|
|
71
48
|
var isValid = this.state.isValid;
|
|
72
49
|
return /*#__PURE__*/_react["default"].createElement(_TextField["default"], _extends({}, rest, {
|
|
73
50
|
error: !isValid || error,
|
|
@@ -75,8 +52,6 @@ var MuiTextField = /*#__PURE__*/function (_MuiComponent) {
|
|
|
75
52
|
}));
|
|
76
53
|
}
|
|
77
54
|
}]);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
exports["default"] = MuiTextField;
|
|
55
|
+
return TextValidator;
|
|
56
|
+
}(_ValidatorComponent2["default"]);
|
|
57
|
+
exports["default"] = TextValidator;
|
|
@@ -1,106 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
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
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _Checkbox = _interopRequireDefault(require("@mui/material/Checkbox"));
|
|
15
|
-
|
|
16
|
-
var _MuiComponent2 = _interopRequireDefault(require("../core/MuiComponent"));
|
|
17
|
-
|
|
18
|
-
var _excluded = ["errorStyle", "errorMessages", "validators", "requiredError", "value"];
|
|
19
|
-
|
|
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"];
|
|
20
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
-
|
|
22
|
-
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); }
|
|
23
|
-
|
|
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); }
|
|
24
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; }
|
|
25
|
-
|
|
26
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; }
|
|
27
|
-
|
|
28
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
29
|
-
|
|
30
|
-
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); } }
|
|
31
|
-
|
|
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); } }
|
|
32
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; }
|
|
33
|
-
|
|
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); }
|
|
34
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); }
|
|
35
|
-
|
|
36
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
37
|
-
|
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
38
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); }; }
|
|
39
|
-
|
|
40
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); }
|
|
41
|
-
|
|
42
25
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
-
|
|
44
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; } }
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
fontSize: "12px",
|
|
52
|
-
color: red300,
|
|
53
|
-
position: "absolute",
|
|
54
|
-
marginTop: "-25px"
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
var MuiCheckbox = /*#__PURE__*/function (_MuiComponent) {
|
|
58
|
-
_inherits(MuiCheckbox, _MuiComponent);
|
|
59
|
-
|
|
60
|
-
var _super = _createSuper(MuiCheckbox);
|
|
61
|
-
|
|
62
|
-
function MuiCheckbox() {
|
|
63
|
-
_classCallCheck(this, MuiCheckbox);
|
|
64
|
-
|
|
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);
|
|
65
33
|
return _super.apply(this, arguments);
|
|
66
34
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
value: function renderMuiComponent() {
|
|
71
|
-
var _this = this;
|
|
72
|
-
|
|
35
|
+
_createClass(SelectValidator, [{
|
|
36
|
+
key: "renderValidatorComponent",
|
|
37
|
+
value: function renderValidatorComponent() {
|
|
73
38
|
var _this$props = this.props,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
_this.input = r;
|
|
84
|
-
}
|
|
85
|
-
})), this.errorText());
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "errorText",
|
|
89
|
-
value: function errorText() {
|
|
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);
|
|
90
48
|
var isValid = this.state.isValid;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
97
|
-
style: errorStyle ? errorStyle : style
|
|
98
|
-
}, this.getErrorMessage());
|
|
49
|
+
return /*#__PURE__*/_react["default"].createElement(_TextField["default"], _extends({}, rest, {
|
|
50
|
+
select: true,
|
|
51
|
+
error: !isValid || error,
|
|
52
|
+
helperText: !isValid && this.getErrorMessage() || helperText
|
|
53
|
+
}));
|
|
99
54
|
}
|
|
100
55
|
}]);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var _default = MuiCheckbox;
|
|
106
|
-
exports["default"] = _default;
|
|
56
|
+
return SelectValidator;
|
|
57
|
+
}(_index.ValidatorComponent);
|
|
58
|
+
exports["default"] = SelectValidator;
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|
|
@@ -0,0 +1,80 @@
|
|
|
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;
|
|
@@ -0,0 +1,178 @@
|
|
|
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;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.FormContext = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _promisePolyfill = _interopRequireDefault(require("promise-polyfill"));
|
|
10
|
+
var _index = _interopRequireDefault(require("../context/index"));
|
|
11
|
+
var _ValidationRules = _interopRequireDefault(require("./ValidationRules"));
|
|
12
|
+
var _excluded = ["onSubmit", "instantValidate", "onError", "debounceTime", "children"];
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
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); }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
+
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); } }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
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
|
+
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; }
|
|
29
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
30
|
+
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-disable */ /* eslint-enable */
|
|
31
|
+
var FormContext = (0, _index["default"])("form");
|
|
32
|
+
exports.FormContext = FormContext;
|
|
33
|
+
var ValidatorForm = /*#__PURE__*/function (_React$Component) {
|
|
34
|
+
_inherits(ValidatorForm, _React$Component);
|
|
35
|
+
var _super = _createSuper(ValidatorForm);
|
|
36
|
+
function ValidatorForm() {
|
|
37
|
+
var _this;
|
|
38
|
+
_classCallCheck(this, ValidatorForm);
|
|
39
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
+
args[_key] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "getFormHelpers", function () {
|
|
44
|
+
return {
|
|
45
|
+
form: {
|
|
46
|
+
attachToForm: _this.attachToForm,
|
|
47
|
+
detachFromForm: _this.detachFromForm,
|
|
48
|
+
instantValidate: _this.instantValidate,
|
|
49
|
+
debounceTime: _this.debounceTime
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "instantValidate", _this.props.instantValidate !== undefined ? _this.props.instantValidate : true);
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "debounceTime", _this.props.debounceTime);
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "childs", []);
|
|
56
|
+
_defineProperty(_assertThisInitialized(_this), "errors", []);
|
|
57
|
+
_defineProperty(_assertThisInitialized(_this), "attachToForm", function (component) {
|
|
58
|
+
if (_this.childs.indexOf(component) === -1) {
|
|
59
|
+
_this.childs.push(component);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
_defineProperty(_assertThisInitialized(_this), "detachFromForm", function (component) {
|
|
63
|
+
var componentPos = _this.childs.indexOf(component);
|
|
64
|
+
if (componentPos !== -1) {
|
|
65
|
+
_this.childs = _this.childs.slice(0, componentPos).concat(_this.childs.slice(componentPos + 1));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(_assertThisInitialized(_this), "submit", function (event) {
|
|
69
|
+
if (event) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
event.persist();
|
|
72
|
+
}
|
|
73
|
+
_this.errors = [];
|
|
74
|
+
_this.walk(_this.childs).then(function (result) {
|
|
75
|
+
if (_this.errors.length) {
|
|
76
|
+
_this.props.onError(_this.errors);
|
|
77
|
+
}
|
|
78
|
+
if (result) {
|
|
79
|
+
_this.props.onSubmit(event);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
_defineProperty(_assertThisInitialized(_this), "walk", function (children, dryRun) {
|
|
85
|
+
var self = _assertThisInitialized(_this);
|
|
86
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
87
|
+
var result = true;
|
|
88
|
+
if (Array.isArray(children)) {
|
|
89
|
+
_promisePolyfill["default"].all(children.map(function (input) {
|
|
90
|
+
return self.checkInput(input, dryRun);
|
|
91
|
+
})).then(function (data) {
|
|
92
|
+
data.forEach(function (item) {
|
|
93
|
+
if (!item) {
|
|
94
|
+
result = false;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
resolve(result);
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
self.walk([children], dryRun).then(function (result) {
|
|
101
|
+
return resolve(result);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
_defineProperty(_assertThisInitialized(_this), "checkInput", function (input, dryRun) {
|
|
107
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
108
|
+
var result = true;
|
|
109
|
+
var validators = input.props.validators;
|
|
110
|
+
if (validators) {
|
|
111
|
+
_this.validate(input, true, dryRun).then(function (data) {
|
|
112
|
+
if (!data) {
|
|
113
|
+
result = false;
|
|
114
|
+
}
|
|
115
|
+
resolve(result);
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
resolve(result);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (input, includeRequired, dryRun) {
|
|
123
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
124
|
+
var value = input.props.value;
|
|
125
|
+
input.validate(value, includeRequired, dryRun).then(function (valid) {
|
|
126
|
+
if (!valid) {
|
|
127
|
+
_this.errors.push(input);
|
|
128
|
+
}
|
|
129
|
+
resolve(valid);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
_defineProperty(_assertThisInitialized(_this), "find", function (collection, fn) {
|
|
134
|
+
for (var i = 0, l = collection.length; i < l; i++) {
|
|
135
|
+
var item = collection[i];
|
|
136
|
+
if (fn(item)) {
|
|
137
|
+
return item;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
});
|
|
142
|
+
_defineProperty(_assertThisInitialized(_this), "resetValidations", function () {
|
|
143
|
+
_this.childs.forEach(function (child) {
|
|
144
|
+
child.validateDebounced.cancel();
|
|
145
|
+
child.setState({
|
|
146
|
+
isValid: true
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
_defineProperty(_assertThisInitialized(_this), "isFormValid", function () {
|
|
151
|
+
var dryRun = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
152
|
+
return _this.walk(_this.childs, dryRun);
|
|
153
|
+
});
|
|
154
|
+
return _this;
|
|
155
|
+
}
|
|
156
|
+
_createClass(ValidatorForm, [{
|
|
157
|
+
key: "render",
|
|
158
|
+
value: function render() {
|
|
159
|
+
// eslint-disable-next-line
|
|
160
|
+
var _this$props = this.props,
|
|
161
|
+
onSubmit = _this$props.onSubmit,
|
|
162
|
+
instantValidate = _this$props.instantValidate,
|
|
163
|
+
onError = _this$props.onError,
|
|
164
|
+
debounceTime = _this$props.debounceTime,
|
|
165
|
+
children = _this$props.children,
|
|
166
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
167
|
+
return /*#__PURE__*/_react["default"].createElement(FormContext.Provider, {
|
|
168
|
+
value: this.getFormHelpers()
|
|
169
|
+
}, /*#__PURE__*/_react["default"].createElement("form", _extends({}, rest, {
|
|
170
|
+
onSubmit: this.submit
|
|
171
|
+
}), children));
|
|
172
|
+
}
|
|
173
|
+
}]);
|
|
174
|
+
return ValidatorForm;
|
|
175
|
+
}(_react["default"].Component);
|
|
176
|
+
_defineProperty(ValidatorForm, "getValidator", function (validator, value, includeRequired) {
|
|
177
|
+
var result = true;
|
|
178
|
+
var name = validator;
|
|
179
|
+
if (name !== "required" || includeRequired) {
|
|
180
|
+
var extra;
|
|
181
|
+
var splitIdx = validator.indexOf(":");
|
|
182
|
+
if (splitIdx !== -1) {
|
|
183
|
+
name = validator.substring(0, splitIdx);
|
|
184
|
+
extra = validator.substring(splitIdx + 1);
|
|
185
|
+
}
|
|
186
|
+
result = _ValidationRules["default"][name](value, extra);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
});
|
|
190
|
+
ValidatorForm.addValidationRule = function (name, callback) {
|
|
191
|
+
_ValidationRules["default"][name] = callback;
|
|
192
|
+
};
|
|
193
|
+
ValidatorForm.getValidationRule = function (name) {
|
|
194
|
+
return _ValidationRules["default"][name];
|
|
195
|
+
};
|
|
196
|
+
ValidatorForm.hasValidationRule = function (name) {
|
|
197
|
+
return _ValidationRules["default"][name] && typeof _ValidationRules["default"][name] === "function";
|
|
198
|
+
};
|
|
199
|
+
ValidatorForm.removeValidationRule = function (name) {
|
|
200
|
+
delete _ValidationRules["default"][name];
|
|
201
|
+
};
|
|
202
|
+
ValidatorForm.propTypes = {
|
|
203
|
+
onSubmit: _propTypes["default"].func.isRequired,
|
|
204
|
+
instantValidate: _propTypes["default"].bool,
|
|
205
|
+
children: _propTypes["default"].node,
|
|
206
|
+
onError: _propTypes["default"].func,
|
|
207
|
+
debounceTime: _propTypes["default"].number
|
|
208
|
+
};
|
|
209
|
+
ValidatorForm.defaultProps = {
|
|
210
|
+
onError: function onError() {},
|
|
211
|
+
debounceTime: 0
|
|
212
|
+
};
|
|
213
|
+
var _default = ValidatorForm;
|
|
214
|
+
exports["default"] = _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _MuiComponent = _interopRequireDefault(require("./core/MuiComponent"));
|
|
4
|
+
var _MuiForm = _interopRequireDefault(require("./core/MuiForm"));
|
|
5
|
+
var _MuiTextField = _interopRequireDefault(require("./components/MuiTextField"));
|
|
6
|
+
var _MuiCheckbox = _interopRequireDefault(require("./components/MuiCheckbox"));
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
+
exports.MuiTextField = _MuiTextField["default"];
|
|
9
|
+
exports.MuiCheckbox = _MuiCheckbox["default"];
|
|
10
|
+
exports.MuiComponent = _MuiComponent["default"];
|
|
11
|
+
exports.MuiForm = _MuiForm["default"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-mui-form-validator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Validator for forms designed with material-ui components.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,29 +27,32 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/Blencm/react-mui-form-validator#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"promise-polyfill": "^8.
|
|
30
|
+
"@mui/material": "^5.13.6",
|
|
31
|
+
"core-js": "^3.31.0",
|
|
32
|
+
"promise-polyfill": "^8.3.0",
|
|
33
33
|
"prop-types": "^15.8.1",
|
|
34
|
-
"react-lifecycles-compat": "^3.0.4"
|
|
34
|
+
"react-lifecycles-compat": "^3.0.4",
|
|
35
|
+
"tiny-warning": "^1.0.3",
|
|
36
|
+
"typescript": "^5.1.6"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
|
-
"react": "^16.0.0 || ^17.0.0 || ^18.
|
|
38
|
-
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
|
|
39
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.2.0 || ^19.0.0 || ^20.0.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@babel/cli": "^7.
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/plugin-syntax-jsx": "^7.
|
|
44
|
-
"@babel/preset-env": "^7.
|
|
45
|
-
"@babel/preset-react": "^7.
|
|
42
|
+
"@babel/cli": "^7.22.5",
|
|
43
|
+
"@babel/core": "^7.22.5",
|
|
44
|
+
"@babel/plugin-syntax-jsx": "^7.22.5",
|
|
45
|
+
"@babel/preset-env": "^7.22.5",
|
|
46
|
+
"@babel/preset-react": "^7.22.5",
|
|
47
|
+
"@types/react": "18.2.14",
|
|
46
48
|
"babel-eslint": "^10.1.0",
|
|
47
|
-
"babel-loader": "^
|
|
48
|
-
"eslint": "^8.
|
|
49
|
+
"babel-loader": "^9.1.2",
|
|
50
|
+
"eslint": "^8.44.0",
|
|
49
51
|
"eslint-config-airbnb": "^19.0.4",
|
|
50
|
-
"eslint-plugin-import": "^2.
|
|
51
|
-
"eslint-plugin-jsx-a11y": "6.
|
|
52
|
-
"eslint-plugin-react": "^7.
|
|
53
|
-
"
|
|
52
|
+
"eslint-plugin-import": "^2.27.5",
|
|
53
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
54
|
+
"eslint-plugin-react": "^7.32.2",
|
|
55
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
56
|
+
"rimraf": "^5.0.1"
|
|
54
57
|
}
|
|
55
58
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": false,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"jsx": "react-jsx",
|
|
22
|
+
"baseUrl": "src"
|
|
23
|
+
},
|
|
24
|
+
"include": [
|
|
25
|
+
"src"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/.eslintrc
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "babel-eslint",
|
|
3
|
-
"plugins": ["import"],
|
|
4
|
-
"extends": ["airbnb"],
|
|
5
|
-
"rules": {
|
|
6
|
-
// Soft some rules.
|
|
7
|
-
"camelcase": "off",
|
|
8
|
-
"class-methods-use-this": "off",
|
|
9
|
-
"default-case": 0, // Required default case is nonsense.
|
|
10
|
-
"indent": [2, 4, { "SwitchCase": 1, "VariableDeclarator": 1 }],
|
|
11
|
-
"linebreak-style": "off",
|
|
12
|
-
"max-len": "off",
|
|
13
|
-
"new-cap": [2, { "capIsNew": false, "newIsCap": true }], // For Record() etc.
|
|
14
|
-
"newline-per-chained-call": 0,
|
|
15
|
-
"no-cond-assign": "off",
|
|
16
|
-
"no-floating-decimal": 0, // .5 is just fine.
|
|
17
|
-
"no-nested-ternary": 0, // It's nice for JSX.
|
|
18
|
-
"no-param-reassign": 0, // We love param reassignment. Naming is hard.
|
|
19
|
-
"no-plusplus": 0,
|
|
20
|
-
"no-prototype-builtins": 0,
|
|
21
|
-
"no-shadow": 0, // Shadowing is a nice language feature. Naming is hard.
|
|
22
|
-
"react/no-string-refs": 0,
|
|
23
|
-
"no-underscore-dangle": "off",
|
|
24
|
-
// eslint-plugin-import
|
|
25
|
-
"import/no-unresolved": [2, { "commonjs": true }],
|
|
26
|
-
"import/no-extraneous-dependencies": 0,
|
|
27
|
-
"import/named": 2,
|
|
28
|
-
"import/default": 2,
|
|
29
|
-
"import/namespace": 2,
|
|
30
|
-
"import/export": 2,
|
|
31
|
-
"func-names": ["error", "as-needed"],
|
|
32
|
-
// Overide Stateless
|
|
33
|
-
"react/prefer-stateless-function": 0,
|
|
34
|
-
"react/jsx-indent": [2, 4],
|
|
35
|
-
"react/jsx-indent-props": [2, 4],
|
|
36
|
-
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
|
|
37
|
-
"react/no-unused-prop-types": 0,
|
|
38
|
-
"react/no-array-index-key": 0,
|
|
39
|
-
"react/forbid-prop-types": 0,
|
|
40
|
-
"react/require-default-props": 0,
|
|
41
|
-
"jsx-a11y/anchor-has-content": 0
|
|
42
|
-
},
|
|
43
|
-
"globals": {
|
|
44
|
-
"after": false,
|
|
45
|
-
"afterEach": false,
|
|
46
|
-
"before": false,
|
|
47
|
-
"beforeEach": false,
|
|
48
|
-
"describe": false,
|
|
49
|
-
"it": false,
|
|
50
|
-
"require": false,
|
|
51
|
-
"window": true,
|
|
52
|
-
"localStorage": true,
|
|
53
|
-
"document": true,
|
|
54
|
-
"navigator": true,
|
|
55
|
-
"location": true,
|
|
56
|
-
"XMLHttpRequest": true,
|
|
57
|
-
"XDomainRequest": true,
|
|
58
|
-
"Blob": true
|
|
59
|
-
},
|
|
60
|
-
"settings": {
|
|
61
|
-
"import/ignore": ["node_modules", "\\.json$"],
|
|
62
|
-
"import/parser": "babel-eslint",
|
|
63
|
-
"import/resolve": {
|
|
64
|
-
"extensions": [".js", ".jsx", ".json"]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|