react-mui-form-validator 1.0.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/.babelrc +3 -0
- package/.eslintignore +3 -0
- package/.eslintrc +76 -0
- package/.gitattributes +2 -0
- package/.travis.yml +11 -0
- package/LICENSE +21 -0
- package/Readme.md +165 -0
- package/lib/components/MuiCheckbox.js +105 -0
- package/lib/components/MuiTextField.js +77 -0
- package/lib/components/MuiTextSelect.js +77 -0
- package/lib/core/MuiComponent.js +231 -0
- package/lib/core/MuiForm.js +279 -0
- package/lib/core/MuiRules.js +86 -0
- package/lib/index.js +19 -0
- package/lib/utils/utils.js +53 -0
- package/package.json +53 -0
package/.babelrc
ADDED
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser" : "babel-eslint",
|
|
3
|
+
"plugins": [
|
|
4
|
+
"import"
|
|
5
|
+
],
|
|
6
|
+
"extends" : ["airbnb"],
|
|
7
|
+
"rules": {
|
|
8
|
+
// Soft some rules.
|
|
9
|
+
"camelcase": "off",
|
|
10
|
+
"class-methods-use-this": "off",
|
|
11
|
+
"default-case": 0, // Required default case is nonsense.
|
|
12
|
+
"indent": [2, 4, { "SwitchCase": 1, "VariableDeclarator": 1 }],
|
|
13
|
+
"linebreak-style": "off",
|
|
14
|
+
"max-len": "off",
|
|
15
|
+
"new-cap": [2, {"capIsNew": false, "newIsCap": true}], // For Record() etc.
|
|
16
|
+
"newline-per-chained-call": 0,
|
|
17
|
+
"no-cond-assign": "off",
|
|
18
|
+
"no-floating-decimal": 0, // .5 is just fine.
|
|
19
|
+
"no-nested-ternary": 0, // It's nice for JSX.
|
|
20
|
+
"no-param-reassign": 0, // We love param reassignment. Naming is hard.
|
|
21
|
+
"no-plusplus": 0,
|
|
22
|
+
"no-prototype-builtins": 0,
|
|
23
|
+
"no-shadow": 0, // Shadowing is a nice language feature. Naming is hard.
|
|
24
|
+
"react/no-string-refs": 0,
|
|
25
|
+
"no-underscore-dangle": "off",
|
|
26
|
+
// eslint-plugin-import
|
|
27
|
+
"import/no-unresolved": [2, {"commonjs": true}],
|
|
28
|
+
"import/no-extraneous-dependencies": 0,
|
|
29
|
+
"import/named": 2,
|
|
30
|
+
"import/default": 2,
|
|
31
|
+
"import/namespace": 2,
|
|
32
|
+
"import/export": 2,
|
|
33
|
+
"func-names": ["error", "as-needed"],
|
|
34
|
+
// Overide Stateless
|
|
35
|
+
"react/prefer-stateless-function": 0,
|
|
36
|
+
"react/jsx-indent": [2, 4],
|
|
37
|
+
"react/jsx-indent-props": [2, 4],
|
|
38
|
+
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
|
|
39
|
+
"react/no-unused-prop-types": 0,
|
|
40
|
+
"react/no-array-index-key": 0,
|
|
41
|
+
"react/forbid-prop-types": 0,
|
|
42
|
+
"react/require-default-props": 0,
|
|
43
|
+
"jsx-a11y/anchor-has-content": 0,
|
|
44
|
+
},
|
|
45
|
+
"globals": {
|
|
46
|
+
"after": false,
|
|
47
|
+
"afterEach": false,
|
|
48
|
+
"before": false,
|
|
49
|
+
"beforeEach": false,
|
|
50
|
+
"describe": false,
|
|
51
|
+
"it": false,
|
|
52
|
+
"require": false,
|
|
53
|
+
"window": true,
|
|
54
|
+
"localStorage": true,
|
|
55
|
+
"document": true,
|
|
56
|
+
"navigator": true,
|
|
57
|
+
"location": true,
|
|
58
|
+
"XMLHttpRequest": true,
|
|
59
|
+
"XDomainRequest": true,
|
|
60
|
+
"Blob": true,
|
|
61
|
+
},
|
|
62
|
+
"settings": {
|
|
63
|
+
"import/ignore": [
|
|
64
|
+
"node_modules",
|
|
65
|
+
"\\.json$"
|
|
66
|
+
],
|
|
67
|
+
"import/parser": "babel-eslint",
|
|
68
|
+
"import/resolve": {
|
|
69
|
+
"extensions": [
|
|
70
|
+
".js",
|
|
71
|
+
".jsx",
|
|
72
|
+
".json"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/.gitattributes
ADDED
package/.travis.yml
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 blencm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
## Validation component for material-ui forms
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install react-mui-form-validator
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Info
|
|
13
|
+
|
|
14
|
+
Some rules can accept extra parameter, example:
|
|
15
|
+
|
|
16
|
+
TextField
|
|
17
|
+
```javascript
|
|
18
|
+
<MuiTextField
|
|
19
|
+
{...someProps}
|
|
20
|
+
validators={["minNumber:0", "maxNumber:255", "matchRegexp:^[0-9]$"]}
|
|
21
|
+
/>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Select
|
|
25
|
+
```javascript
|
|
26
|
+
<MuiTextSelect
|
|
27
|
+
{...someProps}
|
|
28
|
+
validators={["required"]}
|
|
29
|
+
errorMessages={["this select is required"]}
|
|
30
|
+
/>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Checkbox
|
|
34
|
+
```javascript
|
|
35
|
+
<MuiCheckbox
|
|
36
|
+
{...someProps}
|
|
37
|
+
validators={["required"]}
|
|
38
|
+
errorMessages={["this checkbox is required"]}
|
|
39
|
+
checked={value}
|
|
40
|
+
value={value}
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Usage Example
|
|
45
|
+
|
|
46
|
+
You can pass any props of field components, but note that `errorText` prop will be replaced when validation errors occurred.
|
|
47
|
+
Your component must [provide a theme](http://www.material-ui.com/#/get-started/usage).
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
import React from "react";
|
|
51
|
+
import Button from "@mui/material/Button";
|
|
52
|
+
import { MuiForm, MuiTextField } from "react-mui-form-validator";
|
|
53
|
+
|
|
54
|
+
class MyForm extends React.Component {
|
|
55
|
+
state = {
|
|
56
|
+
email: "",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
handleChange = (event) => {
|
|
60
|
+
const email = event.target.value;
|
|
61
|
+
this.setState({ email });
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
handleSubmit = () => {
|
|
65
|
+
// your submit logic
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
render() {
|
|
69
|
+
const { email } = this.state;
|
|
70
|
+
return (
|
|
71
|
+
<MuiForm
|
|
72
|
+
ref="form"
|
|
73
|
+
onSubmit={this.handleSubmit}
|
|
74
|
+
onError={(errors) => console.log(errors)}
|
|
75
|
+
>
|
|
76
|
+
<MuiTextField
|
|
77
|
+
label="Email"
|
|
78
|
+
onChange={this.handleChange}
|
|
79
|
+
name="email"
|
|
80
|
+
value={email}
|
|
81
|
+
validators={["required", "isEmail"]}
|
|
82
|
+
errorMessages={["this field is required", "email is not valid"]}
|
|
83
|
+
/>
|
|
84
|
+
<Button type="submit">Submit</Button>
|
|
85
|
+
</MuiForm>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You can add your custom rules:
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
|
|
95
|
+
import React from 'react';
|
|
96
|
+
import Button from '@mui/material/Button';
|
|
97
|
+
import { MuiForm, MuiTextField} from 'react-mui-form-validator';
|
|
98
|
+
|
|
99
|
+
class ResetPasswordForm extends React.Component {
|
|
100
|
+
|
|
101
|
+
state = {
|
|
102
|
+
user: {
|
|
103
|
+
password: '',
|
|
104
|
+
repeatPassword: '',
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
componentDidMount() {
|
|
109
|
+
// custom rule will have name 'isPasswordMatch'
|
|
110
|
+
MuiForm.addValidationRule('isPasswordMatch', (value) => {
|
|
111
|
+
if (value !== this.state.user.password) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
componentWillUnmount() {
|
|
119
|
+
// remove rule when it is not needed
|
|
120
|
+
MuiForm.removeValidationRule('isPasswordMatch');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
handleChange = (event) => {
|
|
124
|
+
const { user } = this.state;
|
|
125
|
+
user[event.target.name] = event.target.value;
|
|
126
|
+
this.setState({ user });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
handleSubmit = () => {
|
|
130
|
+
// your submit logic
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
render() {
|
|
134
|
+
const { user } = this.state;
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<MuiForm
|
|
138
|
+
onSubmit={this.handleSubmit}
|
|
139
|
+
>
|
|
140
|
+
<MuiTextField
|
|
141
|
+
label="Password"
|
|
142
|
+
onChange={this.handleChange}
|
|
143
|
+
name="password"
|
|
144
|
+
type="password"
|
|
145
|
+
validators={['required']}
|
|
146
|
+
errorMessages={['this field is required']}
|
|
147
|
+
value={user.password}
|
|
148
|
+
/>
|
|
149
|
+
<MuiTextField
|
|
150
|
+
label="Repeat password"
|
|
151
|
+
onChange={this.handleChange}
|
|
152
|
+
name="repeatPassword"
|
|
153
|
+
type="password"
|
|
154
|
+
validators={['isPasswordMatch', 'required']}
|
|
155
|
+
errorMessages={['password mismatch', 'this field is required']}
|
|
156
|
+
value={user.repeatPassword}
|
|
157
|
+
/>
|
|
158
|
+
<Button type="submit">Submit</Button>
|
|
159
|
+
</MuiForm>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
##### [Advanced usage](https://github.com/blencm/react-mui-form-validator/wiki)
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _red = _interopRequireDefault(require("@mui/material/colors/red"));
|
|
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
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
+
|
|
22
|
+
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
|
+
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
|
+
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
|
+
|
|
30
|
+
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
|
+
|
|
32
|
+
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
|
+
|
|
36
|
+
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
|
+
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
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
+
|
|
42
|
+
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
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
45
|
+
|
|
46
|
+
var red300 = _red["default"]["500"];
|
|
47
|
+
var style = {
|
|
48
|
+
right: 0,
|
|
49
|
+
fontSize: "12px",
|
|
50
|
+
color: red300,
|
|
51
|
+
position: "absolute",
|
|
52
|
+
marginTop: "-25px"
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var MuiCheckbox = /*#__PURE__*/function (_MuiComponent) {
|
|
56
|
+
_inherits(MuiCheckbox, _MuiComponent);
|
|
57
|
+
|
|
58
|
+
var _super = _createSuper(MuiCheckbox);
|
|
59
|
+
|
|
60
|
+
function MuiCheckbox() {
|
|
61
|
+
_classCallCheck(this, MuiCheckbox);
|
|
62
|
+
|
|
63
|
+
return _super.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_createClass(MuiCheckbox, [{
|
|
67
|
+
key: "renderMuiComponent",
|
|
68
|
+
value: function renderMuiComponent() {
|
|
69
|
+
var _this = this;
|
|
70
|
+
|
|
71
|
+
var _this$props = this.props,
|
|
72
|
+
errorStyle = _this$props.errorStyle,
|
|
73
|
+
errorMessages = _this$props.errorMessages,
|
|
74
|
+
validators = _this$props.validators,
|
|
75
|
+
requiredError = _this$props.requiredError,
|
|
76
|
+
value = _this$props.value,
|
|
77
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
78
|
+
|
|
79
|
+
return <div>
|
|
80
|
+
<_Checkbox.default {...rest} ref={function (r) {
|
|
81
|
+
_this.input = r;
|
|
82
|
+
}} />
|
|
83
|
+
{this.errorText()}
|
|
84
|
+
</div>;
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "errorText",
|
|
88
|
+
value: function errorText() {
|
|
89
|
+
var isValid = this.state.isValid;
|
|
90
|
+
|
|
91
|
+
if (isValid) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return <div style={errorStyle ? errorStyle : style}>
|
|
96
|
+
{this.getErrorMessage()}
|
|
97
|
+
</div>;
|
|
98
|
+
}
|
|
99
|
+
}]);
|
|
100
|
+
|
|
101
|
+
return MuiCheckbox;
|
|
102
|
+
}(_MuiComponent2["default"]);
|
|
103
|
+
|
|
104
|
+
var _default = MuiCheckbox;
|
|
105
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
|
|
13
|
+
|
|
14
|
+
var _MuiComponent2 = _interopRequireDefault(require("../core/MuiComponent"));
|
|
15
|
+
|
|
16
|
+
var _excluded = ["error", "errorMessages", "validators", "requiredError", "helperText", "validatorListener", "withRequiredValidator", "containerProps"];
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
+
|
|
26
|
+
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); } }
|
|
27
|
+
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
+
|
|
34
|
+
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); }; }
|
|
35
|
+
|
|
36
|
+
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); }
|
|
37
|
+
|
|
38
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
|
+
|
|
40
|
+
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; } }
|
|
41
|
+
|
|
42
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
|
+
|
|
44
|
+
var MuiTextField = /*#__PURE__*/function (_MuiComponent) {
|
|
45
|
+
_inherits(MuiTextField, _MuiComponent);
|
|
46
|
+
|
|
47
|
+
var _super = _createSuper(MuiTextField);
|
|
48
|
+
|
|
49
|
+
function MuiTextField() {
|
|
50
|
+
_classCallCheck(this, MuiTextField);
|
|
51
|
+
|
|
52
|
+
return _super.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_createClass(MuiTextField, [{
|
|
56
|
+
key: "renderMuiComponent",
|
|
57
|
+
value: function renderMuiComponent() {
|
|
58
|
+
var _this$props = this.props,
|
|
59
|
+
error = _this$props.error,
|
|
60
|
+
errorMessages = _this$props.errorMessages,
|
|
61
|
+
validators = _this$props.validators,
|
|
62
|
+
requiredError = _this$props.requiredError,
|
|
63
|
+
helperText = _this$props.helperText,
|
|
64
|
+
validatorListener = _this$props.validatorListener,
|
|
65
|
+
withRequiredValidator = _this$props.withRequiredValidator,
|
|
66
|
+
containerProps = _this$props.containerProps,
|
|
67
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
68
|
+
|
|
69
|
+
var isValid = this.state.isValid;
|
|
70
|
+
return <_TextField.default {...rest} error={!isValid || error} helperText={!isValid && this.getErrorMessage() || helperText} />;
|
|
71
|
+
}
|
|
72
|
+
}]);
|
|
73
|
+
|
|
74
|
+
return MuiTextField;
|
|
75
|
+
}(_MuiComponent2["default"]);
|
|
76
|
+
|
|
77
|
+
exports["default"] = MuiTextField;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
|
|
13
|
+
|
|
14
|
+
var _MuiComponent2 = _interopRequireDefault(require("../core/MuiComponent"));
|
|
15
|
+
|
|
16
|
+
var _excluded = ["error", "errorMessages", "validators", "requiredError", "helperText", "validatorListener", "withRequiredValidator", "containerProps"];
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
+
|
|
26
|
+
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); } }
|
|
27
|
+
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
+
|
|
34
|
+
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); }; }
|
|
35
|
+
|
|
36
|
+
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); }
|
|
37
|
+
|
|
38
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
|
+
|
|
40
|
+
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; } }
|
|
41
|
+
|
|
42
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
|
+
|
|
44
|
+
var MuiTextSelect = /*#__PURE__*/function (_MuiComponent) {
|
|
45
|
+
_inherits(MuiTextSelect, _MuiComponent);
|
|
46
|
+
|
|
47
|
+
var _super = _createSuper(MuiTextSelect);
|
|
48
|
+
|
|
49
|
+
function MuiTextSelect() {
|
|
50
|
+
_classCallCheck(this, MuiTextSelect);
|
|
51
|
+
|
|
52
|
+
return _super.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_createClass(MuiTextSelect, [{
|
|
56
|
+
key: "renderMuiComponent",
|
|
57
|
+
value: function renderMuiComponent() {
|
|
58
|
+
var _this$props = this.props,
|
|
59
|
+
error = _this$props.error,
|
|
60
|
+
errorMessages = _this$props.errorMessages,
|
|
61
|
+
validators = _this$props.validators,
|
|
62
|
+
requiredError = _this$props.requiredError,
|
|
63
|
+
helperText = _this$props.helperText,
|
|
64
|
+
validatorListener = _this$props.validatorListener,
|
|
65
|
+
withRequiredValidator = _this$props.withRequiredValidator,
|
|
66
|
+
containerProps = _this$props.containerProps,
|
|
67
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
68
|
+
|
|
69
|
+
var isValid = this.state.isValid;
|
|
70
|
+
return <_TextField.default {...rest} select error={!isValid || error} helperText={!isValid && this.getErrorMessage() || helperText} />;
|
|
71
|
+
}
|
|
72
|
+
}]);
|
|
73
|
+
|
|
74
|
+
return MuiTextSelect;
|
|
75
|
+
}(_MuiComponent2["default"]);
|
|
76
|
+
|
|
77
|
+
exports["default"] = MuiTextSelect;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _promisePolyfill = _interopRequireDefault(require("promise-polyfill"));
|
|
13
|
+
|
|
14
|
+
var _reactLifecyclesCompat = require("react-lifecycles-compat");
|
|
15
|
+
|
|
16
|
+
var _MuiForm = _interopRequireWildcard(require("./MuiForm"));
|
|
17
|
+
|
|
18
|
+
var _utils = require("../utils/utils");
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
+
|
|
26
|
+
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); }
|
|
27
|
+
|
|
28
|
+
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
|
+
|
|
32
|
+
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
|
+
|
|
34
|
+
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
|
+
|
|
38
|
+
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
|
+
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
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
+
|
|
44
|
+
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
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
|
+
|
|
48
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
49
|
+
|
|
50
|
+
var MuiComponent = /*#__PURE__*/function (_React$Component) {
|
|
51
|
+
_inherits(MuiComponent, _React$Component);
|
|
52
|
+
|
|
53
|
+
var _super = _createSuper(MuiComponent);
|
|
54
|
+
|
|
55
|
+
function MuiComponent() {
|
|
56
|
+
var _this;
|
|
57
|
+
|
|
58
|
+
_classCallCheck(this, MuiComponent);
|
|
59
|
+
|
|
60
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
61
|
+
args[_key] = arguments[_key];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
65
|
+
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
67
|
+
isValid: true,
|
|
68
|
+
value: _this.props.value,
|
|
69
|
+
errorMessages: _this.props.errorMessages,
|
|
70
|
+
validators: _this.props.validators
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
_defineProperty(_assertThisInitialized(_this), "getErrorMessage", function () {
|
|
74
|
+
var errorMessages = _this.state.errorMessages;
|
|
75
|
+
|
|
76
|
+
var type = _typeof(errorMessages);
|
|
77
|
+
|
|
78
|
+
if (type === 'string') {
|
|
79
|
+
return errorMessages;
|
|
80
|
+
} else if (type === 'object') {
|
|
81
|
+
if (_this.invalid.length > 0) {
|
|
82
|
+
return errorMessages[_this.invalid[0]];
|
|
83
|
+
}
|
|
84
|
+
} // eslint-disable-next-line
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
console.log('unknown errorMessages type', errorMessages);
|
|
88
|
+
return true;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
_defineProperty(_assertThisInitialized(_this), "instantValidate", true);
|
|
92
|
+
|
|
93
|
+
_defineProperty(_assertThisInitialized(_this), "invalid", []);
|
|
94
|
+
|
|
95
|
+
_defineProperty(_assertThisInitialized(_this), "configure", function () {
|
|
96
|
+
_this.form.attachToForm(_assertThisInitialized(_this));
|
|
97
|
+
|
|
98
|
+
_this.instantValidate = _this.form.instantValidate;
|
|
99
|
+
_this.debounceTime = _this.form.debounceTime;
|
|
100
|
+
_this.validateDebounced = (0, _utils.debounce)(_this.validate, _this.debounceTime);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (value) {
|
|
104
|
+
var includeRequired = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
105
|
+
var dryRun = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
106
|
+
|
|
107
|
+
var validations = _promisePolyfill["default"].all(_this.state.validators.map(function (validator) {
|
|
108
|
+
return _MuiForm["default"].getValidator(validator, value, includeRequired);
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
return validations.then(function (results) {
|
|
112
|
+
_this.invalid = [];
|
|
113
|
+
var valid = true;
|
|
114
|
+
results.forEach(function (result, key) {
|
|
115
|
+
if (!result) {
|
|
116
|
+
valid = false;
|
|
117
|
+
|
|
118
|
+
_this.invalid.push(key);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (!dryRun) {
|
|
123
|
+
_this.setState({
|
|
124
|
+
isValid: valid
|
|
125
|
+
}, function () {
|
|
126
|
+
_this.props.validatorListener(_this.state.isValid);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return valid;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
_defineProperty(_assertThisInitialized(_this), "isValid", function () {
|
|
135
|
+
return _this.state.isValid;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
_defineProperty(_assertThisInitialized(_this), "makeInvalid", function () {
|
|
139
|
+
_this.setState({
|
|
140
|
+
isValid: false
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
_defineProperty(_assertThisInitialized(_this), "makeValid", function () {
|
|
145
|
+
_this.setState({
|
|
146
|
+
isValid: true
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
_defineProperty(_assertThisInitialized(_this), "renderComponent", function (form) {
|
|
151
|
+
if (!_this.form) {
|
|
152
|
+
_this.form = form;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return _this.renderMuiComponent();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return _this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_createClass(MuiComponent, [{
|
|
162
|
+
key: "componentDidMount",
|
|
163
|
+
value: function componentDidMount() {
|
|
164
|
+
this.configure();
|
|
165
|
+
}
|
|
166
|
+
}, {
|
|
167
|
+
key: "shouldComponentUpdate",
|
|
168
|
+
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
169
|
+
return this.state !== nextState || this.props !== nextProps;
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
key: "componentDidUpdate",
|
|
173
|
+
value: function componentDidUpdate(prevProps, prevState) {
|
|
174
|
+
if (this.instantValidate && this.props.value !== prevState.value) {
|
|
175
|
+
this.validateDebounced(this.props.value, this.props.withRequiredValidator);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "componentWillUnmount",
|
|
180
|
+
value: function componentWillUnmount() {
|
|
181
|
+
this.form.detachFromForm(this);
|
|
182
|
+
this.validateDebounced.cancel();
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
key: "render",
|
|
186
|
+
value: function render() {
|
|
187
|
+
var _this2 = this;
|
|
188
|
+
|
|
189
|
+
return <_MuiForm.FormContext.Consumer>
|
|
190
|
+
{function (_ref) {
|
|
191
|
+
var form = _ref.form;
|
|
192
|
+
return <div {..._this2.props.containerProps}>{_this2.renderComponent(form)}</div>;
|
|
193
|
+
}}
|
|
194
|
+
</_MuiForm.FormContext.Consumer>;
|
|
195
|
+
}
|
|
196
|
+
}], [{
|
|
197
|
+
key: "getDerivedStateFromProps",
|
|
198
|
+
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
199
|
+
if (nextProps.validators && nextProps.errorMessages && (prevState.validators !== nextProps.validators || prevState.errorMessages !== nextProps.errorMessages)) {
|
|
200
|
+
return {
|
|
201
|
+
value: nextProps.value,
|
|
202
|
+
validators: nextProps.validators,
|
|
203
|
+
errorMessages: nextProps.errorMessages
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
value: nextProps.value
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}]);
|
|
212
|
+
|
|
213
|
+
return MuiComponent;
|
|
214
|
+
}(_react["default"].Component);
|
|
215
|
+
|
|
216
|
+
MuiComponent.propTypes = {
|
|
217
|
+
errorMessages: _propTypes["default"].oneOfType([_propTypes["default"].array, _propTypes["default"].string]),
|
|
218
|
+
validators: _propTypes["default"].array,
|
|
219
|
+
value: _propTypes["default"].any,
|
|
220
|
+
validatorListener: _propTypes["default"].func,
|
|
221
|
+
withRequiredValidator: _propTypes["default"].bool,
|
|
222
|
+
containerProps: _propTypes["default"].object
|
|
223
|
+
};
|
|
224
|
+
MuiComponent.defaultProps = {
|
|
225
|
+
errorMessages: 'error',
|
|
226
|
+
validators: [],
|
|
227
|
+
validatorListener: function validatorListener() {}
|
|
228
|
+
};
|
|
229
|
+
(0, _reactLifecyclesCompat.polyfill)(MuiComponent);
|
|
230
|
+
var _default = MuiComponent;
|
|
231
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,279 @@
|
|
|
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
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.FormContext = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _promisePolyfill = _interopRequireDefault(require("promise-polyfill"));
|
|
15
|
+
|
|
16
|
+
var _reactCreateThemeContext = _interopRequireDefault(require("react-create-theme-context"));
|
|
17
|
+
|
|
18
|
+
var _MuiRules = _interopRequireDefault(require("./MuiRules"));
|
|
19
|
+
|
|
20
|
+
var _excluded = ["onSubmit", "instantValidate", "onError", "debounceTime", "children"];
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
|
+
|
|
24
|
+
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
|
+
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
|
+
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
|
+
|
|
32
|
+
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
|
+
|
|
34
|
+
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
|
+
|
|
38
|
+
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
|
+
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
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
+
|
|
44
|
+
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
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
|
+
|
|
48
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
49
|
+
|
|
50
|
+
var FormContext = (0, _reactCreateThemeContext["default"])('form');
|
|
51
|
+
exports.FormContext = FormContext;
|
|
52
|
+
|
|
53
|
+
var MuiForm = /*#__PURE__*/function (_React$Component) {
|
|
54
|
+
_inherits(MuiForm, _React$Component);
|
|
55
|
+
|
|
56
|
+
var _super = _createSuper(MuiForm);
|
|
57
|
+
|
|
58
|
+
function MuiForm() {
|
|
59
|
+
var _this;
|
|
60
|
+
|
|
61
|
+
_classCallCheck(this, MuiForm);
|
|
62
|
+
|
|
63
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
64
|
+
args[_key] = arguments[_key];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
68
|
+
|
|
69
|
+
_defineProperty(_assertThisInitialized(_this), "getFormHelpers", function () {
|
|
70
|
+
return {
|
|
71
|
+
form: {
|
|
72
|
+
attachToForm: _this.attachToForm,
|
|
73
|
+
detachFromForm: _this.detachFromForm,
|
|
74
|
+
instantValidate: _this.instantValidate,
|
|
75
|
+
debounceTime: _this.debounceTime
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
_defineProperty(_assertThisInitialized(_this), "instantValidate", _this.props.instantValidate !== undefined ? _this.props.instantValidate : true);
|
|
81
|
+
|
|
82
|
+
_defineProperty(_assertThisInitialized(_this), "debounceTime", _this.props.debounceTime);
|
|
83
|
+
|
|
84
|
+
_defineProperty(_assertThisInitialized(_this), "childs", []);
|
|
85
|
+
|
|
86
|
+
_defineProperty(_assertThisInitialized(_this), "errors", []);
|
|
87
|
+
|
|
88
|
+
_defineProperty(_assertThisInitialized(_this), "attachToForm", function (component) {
|
|
89
|
+
if (_this.childs.indexOf(component) === -1) {
|
|
90
|
+
_this.childs.push(component);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
_defineProperty(_assertThisInitialized(_this), "detachFromForm", function (component) {
|
|
95
|
+
var componentPos = _this.childs.indexOf(component);
|
|
96
|
+
|
|
97
|
+
if (componentPos !== -1) {
|
|
98
|
+
_this.childs = _this.childs.slice(0, componentPos).concat(_this.childs.slice(componentPos + 1));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
_defineProperty(_assertThisInitialized(_this), "submit", function (event) {
|
|
103
|
+
if (event) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
event.persist();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_this.errors = [];
|
|
109
|
+
|
|
110
|
+
_this.walk(_this.childs).then(function (result) {
|
|
111
|
+
if (_this.errors.length) {
|
|
112
|
+
_this.props.onError(_this.errors);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (result) {
|
|
116
|
+
_this.props.onSubmit(event);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
_defineProperty(_assertThisInitialized(_this), "walk", function (children, dryRun) {
|
|
124
|
+
var self = _assertThisInitialized(_this);
|
|
125
|
+
|
|
126
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
127
|
+
var result = true;
|
|
128
|
+
|
|
129
|
+
if (Array.isArray(children)) {
|
|
130
|
+
_promisePolyfill["default"].all(children.map(function (input) {
|
|
131
|
+
return self.checkInput(input, dryRun);
|
|
132
|
+
})).then(function (data) {
|
|
133
|
+
data.forEach(function (item) {
|
|
134
|
+
if (!item) {
|
|
135
|
+
result = false;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
resolve(result);
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
self.walk([children], dryRun).then(function (result) {
|
|
142
|
+
return resolve(result);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
_defineProperty(_assertThisInitialized(_this), "checkInput", function (input, dryRun) {
|
|
149
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
150
|
+
var result = true;
|
|
151
|
+
var validators = input.props.validators;
|
|
152
|
+
|
|
153
|
+
if (validators) {
|
|
154
|
+
_this.validate(input, true, dryRun).then(function (data) {
|
|
155
|
+
if (!data) {
|
|
156
|
+
result = false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
resolve(result);
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
resolve(result);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (input, includeRequired, dryRun) {
|
|
168
|
+
return new _promisePolyfill["default"](function (resolve) {
|
|
169
|
+
var value = input.props.value;
|
|
170
|
+
input.validate(value, includeRequired, dryRun).then(function (valid) {
|
|
171
|
+
if (!valid) {
|
|
172
|
+
_this.errors.push(input);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
resolve(valid);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
_defineProperty(_assertThisInitialized(_this), "find", function (collection, fn) {
|
|
181
|
+
for (var i = 0, l = collection.length; i < l; i++) {
|
|
182
|
+
var item = collection[i];
|
|
183
|
+
|
|
184
|
+
if (fn(item)) {
|
|
185
|
+
return item;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return null;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
_defineProperty(_assertThisInitialized(_this), "resetValidations", function () {
|
|
193
|
+
_this.childs.forEach(function (child) {
|
|
194
|
+
child.validateDebounced.cancel();
|
|
195
|
+
child.setState({
|
|
196
|
+
isValid: true
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
_defineProperty(_assertThisInitialized(_this), "isFormValid", function () {
|
|
202
|
+
var dryRun = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
203
|
+
return _this.walk(_this.childs, dryRun);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return _this;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
_createClass(MuiForm, [{
|
|
210
|
+
key: "render",
|
|
211
|
+
value: function render() {
|
|
212
|
+
// eslint-disable-next-line
|
|
213
|
+
var _this$props = this.props,
|
|
214
|
+
onSubmit = _this$props.onSubmit,
|
|
215
|
+
instantValidate = _this$props.instantValidate,
|
|
216
|
+
onError = _this$props.onError,
|
|
217
|
+
debounceTime = _this$props.debounceTime,
|
|
218
|
+
children = _this$props.children,
|
|
219
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
220
|
+
|
|
221
|
+
return <FormContext.Provider value={this.getFormHelpers()}>
|
|
222
|
+
<form {...rest} onSubmit={this.submit}>
|
|
223
|
+
{children}
|
|
224
|
+
</form>
|
|
225
|
+
</FormContext.Provider>;
|
|
226
|
+
}
|
|
227
|
+
}]);
|
|
228
|
+
|
|
229
|
+
return MuiForm;
|
|
230
|
+
}(_react["default"].Component);
|
|
231
|
+
|
|
232
|
+
_defineProperty(MuiForm, "getValidator", function (validator, value, includeRequired) {
|
|
233
|
+
var result = true;
|
|
234
|
+
var name = validator;
|
|
235
|
+
|
|
236
|
+
if (name !== 'required' || includeRequired) {
|
|
237
|
+
var extra;
|
|
238
|
+
var splitIdx = validator.indexOf(':');
|
|
239
|
+
|
|
240
|
+
if (splitIdx !== -1) {
|
|
241
|
+
name = validator.substring(0, splitIdx);
|
|
242
|
+
extra = validator.substring(splitIdx + 1);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
result = _MuiRules["default"][name](value, extra);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return result;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
MuiForm.addValidationRule = function (name, callback) {
|
|
252
|
+
_MuiRules["default"][name] = callback;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
MuiForm.getValidationRule = function (name) {
|
|
256
|
+
return _MuiRules["default"][name];
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
MuiForm.hasValidationRule = function (name) {
|
|
260
|
+
return _MuiRules["default"][name] && typeof _MuiRules["default"][name] === 'function';
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
MuiForm.removeValidationRule = function (name) {
|
|
264
|
+
delete _MuiRules["default"][name];
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
MuiForm.propTypes = {
|
|
268
|
+
onSubmit: _propTypes["default"].func.isRequired,
|
|
269
|
+
instantValidate: _propTypes["default"].bool,
|
|
270
|
+
children: _propTypes["default"].node,
|
|
271
|
+
onError: _propTypes["default"].func,
|
|
272
|
+
debounceTime: _propTypes["default"].number
|
|
273
|
+
};
|
|
274
|
+
MuiForm.defaultProps = {
|
|
275
|
+
onError: function onError() {},
|
|
276
|
+
debounceTime: 0
|
|
277
|
+
};
|
|
278
|
+
var _default = MuiForm;
|
|
279
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isExisty = function isExisty(value) {
|
|
4
|
+
return value !== null && value !== undefined;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
var _isEmpty = function isEmpty(value) {
|
|
8
|
+
if (value instanceof Array) {
|
|
9
|
+
return value.length === 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return value === '' || !isExisty(value);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var isEmptyTrimed = function isEmptyTrimed(value) {
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
return value.trim() === '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var validations = {
|
|
24
|
+
matchRegexp: function matchRegexp(value, regexp) {
|
|
25
|
+
var validationRegexp = regexp instanceof RegExp ? regexp : new RegExp(regexp);
|
|
26
|
+
return _isEmpty(value) || validationRegexp.test(value);
|
|
27
|
+
},
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
isEmail: function isEmail(value) {
|
|
30
|
+
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);
|
|
31
|
+
},
|
|
32
|
+
isEmpty: function isEmpty(value) {
|
|
33
|
+
return _isEmpty(value);
|
|
34
|
+
},
|
|
35
|
+
required: function required(value) {
|
|
36
|
+
return !_isEmpty(value);
|
|
37
|
+
},
|
|
38
|
+
trim: function trim(value) {
|
|
39
|
+
return !isEmptyTrimed(value);
|
|
40
|
+
},
|
|
41
|
+
isNumber: function isNumber(value) {
|
|
42
|
+
return validations.matchRegexp(value, /^-?[0-9]\d*(\d+)?$/i);
|
|
43
|
+
},
|
|
44
|
+
isFloat: function isFloat(value) {
|
|
45
|
+
return validations.matchRegexp(value, /^(?:-?[1-9]\d*|-?0)?(?:\.\d+)?$/i);
|
|
46
|
+
},
|
|
47
|
+
isPositive: function isPositive(value) {
|
|
48
|
+
if (isExisty(value)) {
|
|
49
|
+
return (validations.isNumber(value) || validations.isFloat(value)) && value >= 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
maxNumber: function maxNumber(value, max) {
|
|
55
|
+
return _isEmpty(value) || parseInt(value, 10) <= parseInt(max, 10);
|
|
56
|
+
},
|
|
57
|
+
minNumber: function minNumber(value, min) {
|
|
58
|
+
return _isEmpty(value) || parseInt(value, 10) >= parseInt(min, 10);
|
|
59
|
+
},
|
|
60
|
+
maxFloat: function maxFloat(value, max) {
|
|
61
|
+
return _isEmpty(value) || parseFloat(value) <= parseFloat(max);
|
|
62
|
+
},
|
|
63
|
+
minFloat: function minFloat(value, min) {
|
|
64
|
+
return _isEmpty(value) || parseFloat(value) >= parseFloat(min);
|
|
65
|
+
},
|
|
66
|
+
isString: function isString(value) {
|
|
67
|
+
return _isEmpty(value) || typeof value === 'string' || value instanceof String;
|
|
68
|
+
},
|
|
69
|
+
minStringLength: function minStringLength(value, length) {
|
|
70
|
+
return validations.isString(value) && value.length >= length;
|
|
71
|
+
},
|
|
72
|
+
maxStringLength: function maxStringLength(value, length) {
|
|
73
|
+
return validations.isString(value) && value.length <= length;
|
|
74
|
+
},
|
|
75
|
+
// eslint-disable-next-line no-undef
|
|
76
|
+
isFile: function isFile(value) {
|
|
77
|
+
return _isEmpty(value) || value instanceof File;
|
|
78
|
+
},
|
|
79
|
+
maxFileSize: function maxFileSize(value, max) {
|
|
80
|
+
return _isEmpty(value) || validations.isFile(value) && value.size <= parseInt(max, 10);
|
|
81
|
+
},
|
|
82
|
+
allowedExtensions: function allowedExtensions(value, fileTypes) {
|
|
83
|
+
return _isEmpty(value) || validations.isFile(value) && fileTypes.split(',').indexOf(value.type) !== -1;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
module.exports = validations;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _MuiComponent = _interopRequireDefault(require("./core/MuiComponent"));
|
|
4
|
+
|
|
5
|
+
var _MuiForm = _interopRequireDefault(require("./core/MuiForm"));
|
|
6
|
+
|
|
7
|
+
var _MuiTextSelect = _interopRequireDefault(require("./components/MuiTextSelect"));
|
|
8
|
+
|
|
9
|
+
var _MuiTextField = _interopRequireDefault(require("./components/MuiTextField"));
|
|
10
|
+
|
|
11
|
+
var _MuiCheckbox = _interopRequireDefault(require("./components/MuiCheckbox"));
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
|
|
15
|
+
exports.MuiTextSelect = _MuiTextSelect["default"];
|
|
16
|
+
exports.MuiTextField = _MuiTextField["default"];
|
|
17
|
+
exports.MuiCheckbox = _MuiCheckbox["default"];
|
|
18
|
+
exports.MuiComponent = _MuiComponent["default"];
|
|
19
|
+
exports.MuiForm = _MuiForm["default"];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debounce = void 0;
|
|
7
|
+
|
|
8
|
+
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); } }
|
|
9
|
+
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
|
|
14
|
+
var debounce = function debounce(func, wait, immediate) {
|
|
15
|
+
var timeout;
|
|
16
|
+
|
|
17
|
+
function cancel() {
|
|
18
|
+
if (timeout !== undefined) {
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var debounced = /*#__PURE__*/_createClass(function debounced() {
|
|
24
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
25
|
+
args[_key] = arguments[_key];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_classCallCheck(this, debounced);
|
|
29
|
+
|
|
30
|
+
var context = this;
|
|
31
|
+
|
|
32
|
+
var later = function delayed() {
|
|
33
|
+
timeout = null;
|
|
34
|
+
|
|
35
|
+
if (!immediate) {
|
|
36
|
+
func.apply(context, args);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var callNow = immediate && !timeout;
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
timeout = setTimeout(later, wait);
|
|
43
|
+
|
|
44
|
+
if (callNow) {
|
|
45
|
+
func.apply(context, args);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
debounced.cancel = cancel;
|
|
50
|
+
return debounced;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.debounce = debounce;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-mui-form-validator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple validator for forms designed with material-ui v1/v3/v4/v5 components.",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rimraf lib && npm install --ignore-scripts && babel src --out-dir lib",
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"lint": "eslint src/**"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Blencm/react-mui-form-validator.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react",
|
|
17
|
+
"material-ui",
|
|
18
|
+
"mui",
|
|
19
|
+
"form",
|
|
20
|
+
"validator"
|
|
21
|
+
],
|
|
22
|
+
"author": "Blencm",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Blencm/react-mui-form-validator/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/Blencm/react-mui-form-validator#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"core-js": "^3.21.0",
|
|
30
|
+
"promise-polyfill": "^8.2.1",
|
|
31
|
+
"prop-types": "^15.8.1",
|
|
32
|
+
"react-create-theme-context": "^0.0.1",
|
|
33
|
+
"react-lifecycles-compat": "^3.0.4"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0",
|
|
37
|
+
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@babel/cli": "^7.17.0",
|
|
41
|
+
"@babel/core": "^7.17.2",
|
|
42
|
+
"@babel/plugin-syntax-jsx": "^7.16.7",
|
|
43
|
+
"@babel/preset-env": "^7.16.11",
|
|
44
|
+
"babel-eslint": "^10.1.0",
|
|
45
|
+
"babel-loader": "^8.2.3",
|
|
46
|
+
"eslint": "^8.9.0",
|
|
47
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
48
|
+
"eslint-plugin-import": "^2.25.4",
|
|
49
|
+
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
50
|
+
"eslint-plugin-react": "^7.28.0",
|
|
51
|
+
"rimraf": "^3.0.2"
|
|
52
|
+
}
|
|
53
|
+
}
|